Add Connected indicator to navigationBarItems and display the same indicator on the messages page

This commit is contained in:
Garth Vander Houwen 2021-09-19 01:10:49 -07:00
parent c1c2f3730a
commit 7bb4eb94ab
9 changed files with 57 additions and 45 deletions

View file

@ -39,7 +39,6 @@
DDC2E17A26CE248F0042C5E4 /* MeshtasticClientUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E17926CE248F0042C5E4 /* MeshtasticClientUITests.swift */; };
DDC2E18F26CE25FE0042C5E4 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E18E26CE25FE0042C5E4 /* ContentView.swift */; };
DDC2E19126CE26290042C5E4 /* Messages.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E19026CE26290042C5E4 /* Messages.swift */; };
DDC2E19B26CE27150042C5E4 /* CircleImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E19A26CE27150042C5E4 /* CircleImage.swift */; };
DDC2E19D26CE27580042C5E4 /* ModelData.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E19C26CE27580042C5E4 /* ModelData.swift */; };
DDC2E1A726CEB3400042C5E4 /* LocationHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E1A626CEB3400042C5E4 /* LocationHelper.swift */; };
DDC2E1AB26DD89EC0042C5E4 /* packets.json in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E1AA26DD89EC0042C5E4 /* packets.json */; };
@ -103,7 +102,6 @@
DDC2E17B26CE248F0042C5E4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DDC2E18E26CE25FE0042C5E4 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
DDC2E19026CE26290042C5E4 /* Messages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Messages.swift; sourceTree = "<group>"; };
DDC2E19A26CE27150042C5E4 /* CircleImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleImage.swift; sourceTree = "<group>"; };
DDC2E19C26CE27580042C5E4 /* ModelData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelData.swift; sourceTree = "<group>"; };
DDC2E1A626CEB3400042C5E4 /* LocationHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationHelper.swift; sourceTree = "<group>"; };
DDC2E1AA26DD89EC0042C5E4 /* packets.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = packets.json; sourceTree = "<group>"; };
@ -278,7 +276,6 @@
DDC2E18D26CE25CB0042C5E4 /* Helpers */ = {
isa = PBXGroup;
children = (
DDC2E19A26CE27150042C5E4 /* CircleImage.swift */,
DD47E3D526F17ED900029299 /* CircleText.swift */,
DD47E3D826F3093800029299 /* MessageBubble.swift */,
DD90860B26F684AF00DC5189 /* BatteryIcon.swift */,
@ -458,7 +455,6 @@
DDAF8C6326ED0A230058C060 /* admin.pb.swift in Sources */,
DDAF8C5826ED07FD0058C060 /* mesh.pb.swift in Sources */,
DD47E3D926F3093800029299 /* MessageBubble.swift in Sources */,
DDC2E19B26CE27150042C5E4 /* CircleImage.swift in Sources */,
DDAF8C6726ED0C8C0058C060 /* remote_hardware.pb.swift in Sources */,
DDAF8C6526ED0A490058C060 /* channel.pb.swift in Sources */,
DD47E3DD26F390A000029299 /* MessageDetail.swift in Sources */,

View file

@ -117,7 +117,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
}
let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, index: peripherals.count, name: peripheralName, rssi: RSSI.intValue)
print(newPeripheral)
//print(newPeripheral)
peripherals.append(newPeripheral)
}

View file

@ -5,10 +5,15 @@ Storage for model data.
import Foundation
import Combine
import CoreBluetooth
import CoreData
final class ModelData: ObservableObject {
@Published var nodes: [NodeInfoModel] = load("packets.json")
// @ObservedObject var connectedPeripheral: CBPeripheral!
//@Published var connectedPeripheral: CBPeripheral!
}
func load<T: Decodable>(_ filename: String) -> T {

View file

@ -7,7 +7,7 @@
import Foundation
struct MyInfoModel: Hashable, Codable, Identifiable {
struct MyInfoModel: Identifiable, Codable {
let id = UUID()
var myNodeNum: UInt32

View file

@ -8,14 +8,15 @@
import Foundation
import SwiftUI
import CoreLocation
import CoreData
struct NodeInfoModel: Hashable, Codable, Identifiable {
struct NodeInfoModel: Identifiable, Codable {
let id = UUID()
var num: UInt32
var user: User
struct User: Hashable, Codable, Identifiable {
struct User: Identifiable, Codable {
var id: String
var longName: String
var shortName: String
@ -24,13 +25,13 @@ struct NodeInfoModel: Hashable, Codable, Identifiable {
}
var position: Position
struct Position: Hashable, Codable {
struct Position: Codable {
var latitudeI: Int32?
var latitude: Double? {
if let unwrappedLat = latitudeI {
let d = Double(unwrappedLat)
return d / 10000000
return d / 1e7
}
else {
return nil
@ -41,7 +42,7 @@ struct NodeInfoModel: Hashable, Codable, Identifiable {
if let unwrappedLong = longitudeI {
let d = Double(unwrappedLong)
return d / 10000000
return d / 1e7
}
else {
return nil

View file

@ -28,7 +28,7 @@ struct Connect: View {
Section(header: Text("Connected Device").font(.largeTitle)) {
if(bleManager.connectedPeripheral != nil){
HStack{
Image(systemName: "dot.radiowaves.left.and.right").imageScale(.large).foregroundColor(.green)
Image(systemName: "antenna.radiowaves.left.and.right").imageScale(.large).foregroundColor(.green)
Text((bleManager.connectedPeripheral.name != nil) ? bleManager.connectedPeripheral.name! : "Unknown").font(.title)
}
}
@ -94,11 +94,23 @@ struct Connect: View {
.navigationTitle("Bluetooth Radios")
.navigationBarItems(trailing:
HStack {
Button(action: {
self.bleManager.startScanning()
}) {
Image(systemName: "arrow.clockwise.circle").imageScale(.large)
}}
VStack {
if bleManager.isSwitchedOn && bleManager.connectedPeripheral != nil {
Image(systemName: "antenna.radiowaves.left.and.right")
.imageScale(.large)
.foregroundColor(.green)
Text("CONNECTED").font(.caption2).foregroundColor(.gray)
}
else {
Image(systemName: "antenna.radiowaves.left.and.right")
.imageScale(.large)
.foregroundColor(.red)
Text("DISCONNECTED").font(.caption).foregroundColor(.gray)
}
}
}.offset(x: 10, y: -10)
)
}.navigationViewStyle(StackNavigationViewStyle())
}

View file

@ -15,8 +15,9 @@ struct ContentView: View {
}
var body: some View {
TabView(selection: $selection) {
Messages()
MessageList()
.tabItem {
Label("Messages", systemImage: "message")
}

View file

@ -1,27 +0,0 @@
/*
See LICENSE folder for this samples licensing information.
Abstract:
A view that clips an image to a circle and adds a stroke and shadow.
*/
import SwiftUI
struct CircleImage: View {
var image: Image
var body: some View {
image
//.resizable()
.clipShape(/*@START_MENU_TOKEN@*/Circle()/*@END_MENU_TOKEN@*/)
.overlay(Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 7)
}
}
struct CircleImage_Previews: PreviewProvider {
static var previews: some View {
CircleImage(image: Image("tbeam"))
}
}

View file

@ -5,6 +5,10 @@ struct MessageList: View {
@State var typingMessage: String = ""
@ObservedObject var bleManager = BLEManager()
@EnvironmentObject var modelData: ModelData
var body: some View {
NavigationView {
@ -17,6 +21,26 @@ struct MessageList: View {
}
.navigationTitle("Channels")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing:
HStack {
VStack {
if bleManager.isSwitchedOn {
Image(systemName: "antenna.radiowaves.left.and.right")
.imageScale(.large)
.foregroundColor(.green)
Text("CONNECTED").font(.caption2).foregroundColor(.gray)
}
else {
Image(systemName: "antenna.radiowaves.left.and.right")
.imageScale(.large)
.foregroundColor(.red)
Text("DISCONNECTED").font(.caption).foregroundColor(.gray)
}
}
}.offset(x: 10, y: -10)
)
}
}
}