diff --git a/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 9ec14b92..7b19cc77 100644 --- a/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Meshtastic Client.xcodeproj/xcuserdata/garthvanderhouwen.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -42,8 +42,8 @@ filePath = "MeshtasticClient/Views/Settings/AppSettings.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "93" - endingLineNumber = "93" + startingLineNumber = "95" + endingLineNumber = "95" landmarkName = "body" landmarkType = "24"> diff --git a/MeshtasticClient/Views/Nodes/NodeList.swift b/MeshtasticClient/Views/Nodes/NodeList.swift index 8a441bf9..adb824cc 100644 --- a/MeshtasticClient/Views/Nodes/NodeList.swift +++ b/MeshtasticClient/Views/Nodes/NodeList.swift @@ -12,7 +12,6 @@ import SwiftUI struct NodeList: View { - // CoreData @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager @@ -25,11 +24,13 @@ struct NodeList: View { @State private var selection: String? var body: some View { + NavigationView { List { if nodes.count == 0 { + Text("Scan for Radios").font(.largeTitle) Text("No LoRa Mesh Nodes Found").font(.title2) Text("Go to the bluetooth section in the bottom right menu and click the Start Scanning button to scan for nearby radios and find your Meshtastic device. Make sure your device is powered on and near your phone or tablet.") @@ -37,78 +38,68 @@ struct NodeList: View { Text("Once the device shows under Available Devices touch the device you want to connect to and it will pull node information over BLE and populate the node list and mesh map in the Meshtastic app.") Text("Views with bluetooth functionality will show an indicator in the upper right hand corner show if bluetooth is on, and if a device is connected.") .listRowSeparator(.visible) + } else { ForEach( nodes ) { node in + let index = nodes.firstIndex(where: { $0.id == node.id }) + NavigationLink(destination: NodeDetail(node: node), tag: String(index!), selection: $selection) { let connected: Bool = (bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.name == node.bleName) - - if bleManager.connectedPeripheral != nil { - VStack(alignment: .leading) { - - HStack { + VStack(alignment: .leading) { + + HStack { - CircleText(text: node.user?.shortName ?? "???", color: Color.accentColor).offset(y: 1).padding(.trailing, 5) + CircleText(text: node.user?.shortName ?? "???", color: Color.accentColor).offset(y: 1).padding(.trailing, 5) + .offset(x: -15) + + if UIDevice.current.userInterfaceIdiom == .pad { Text(node.user?.longName ?? "Unknown").font(.headline) .offset(x: -15) - - if UIDevice.current.userInterfaceIdiom == .pad { Text(node.user?.longName ?? "Unknown").font(.headline) - .offset(x: -15) - } else { - Text(node.user?.longName ?? "Unknown").font(.title).offset(x: -15) - } - } - .padding(.bottom, 10) - - if connected { - HStack(alignment: .bottom) { - - Image(systemName: "repeat.circle.fill").font(.title3) - .foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) - Text("Currently Connected").font(.title3).foregroundColor(Color.accentColor) - } - Spacer() - } - - HStack(alignment: .bottom) { - - Image(systemName: "clock.badge.checkmark.fill").font(.title3).foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) - - if UIDevice.current.userInterfaceIdiom == .pad { - - if node.lastHeard != nil { - Text("Last Heard: \(node.lastHeard!, style: .relative) ago").font(.caption).foregroundColor(.gray) - .padding(.bottom) - } else { - Text("Last Heard: Unknown").font(.caption).foregroundColor(.gray) - } - - } else { - - if node.lastHeard != nil { - Text("Last Heard: \(node.lastHeard!, style: .relative) ago").font(.subheadline).foregroundColor(.gray) - } else { - Text("Last Heard: Unknown").font(.subheadline).foregroundColor(.gray) - } - } + } else { + Text(node.user?.longName ?? "Unknown").font(.title).offset(x: -15) + } + } + .padding(.bottom, 10) + + if connected { + HStack(alignment: .bottom) { + + Image(systemName: "repeat.circle.fill").font(.title3) + .foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) + Text("Currently Connected").font(.title3).foregroundColor(Color.accentColor) + } + Spacer() + } + + HStack(alignment: .bottom) { + + Image(systemName: "clock.badge.checkmark.fill").font(.title3).foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) + + if node.lastHeard != nil { + Text("Last Heard: \(node.lastHeard!, style: .relative) ago").font(.subheadline).foregroundColor(.gray) + } else { + Text("Last Heard: Unknown").font(.subheadline).foregroundColor(.gray) } } - .padding([.leading, .top, .bottom]) } + .padding([.leading, .top, .bottom]) } .swipeActions { + Button { context.delete(node) + do { try context.save() print("Successfully Deleted NodeInfoEntiy: \(node.num)") + } catch { print("Failed to save context after deleting NodeInfoEntity Num: \(node.num)") - } } label: { @@ -132,7 +123,7 @@ struct NodeList: View { } } } - //.ignoresSafeArea(.all, edges: [.leading, .trailing]) + .ignoresSafeArea(.all, edges: [.leading, .trailing]) .navigationViewStyle(DoubleColumnNavigationViewStyle()) } } diff --git a/MeshtasticClient/Views/Settings/AppSettings.swift b/MeshtasticClient/Views/Settings/AppSettings.swift index 32f12b05..cb19d55e 100644 --- a/MeshtasticClient/Views/Settings/AppSettings.swift +++ b/MeshtasticClient/Views/Settings/AppSettings.swift @@ -31,11 +31,11 @@ enum KeyboardType: Int, CaseIterable, Identifiable { } class UserSettings: ObservableObject { - // @Published var meshtasticUsername: String { - // didSet { - // UserDefaults.standard.set(meshtasticUsername, forKey: "meshtasticusername") - // } - // } +// @Published var meshtasticUsername: String { +// didSet { +// UserDefaults.standard.set(meshtasticUsername, forKey: "meshtasticusername") +// } +// } @Published var preferredPeripheralName: String { didSet { UserDefaults.standard.set(preferredPeripheralName, forKey: "preferredPeripheralName") @@ -46,11 +46,11 @@ class UserSettings: ObservableObject { UserDefaults.standard.set(preferredPeripheralId, forKey: "preferredPeripheralId") } } - @Published var provideLocation: Bool { - didSet { - UserDefaults.standard.set(provideLocation, forKey: "provideLocation") - } - } +// @Published var provideLocation: Bool { +// didSet { +// UserDefaults.standard.set(provideLocation, forKey: "provideLocation") +// } +// } @Published var keyboardType: Int { didSet { UserDefaults.standard.set(keyboardType, forKey: "keyboardType") @@ -63,17 +63,19 @@ class UserSettings: ObservableObject { } init() { - // self.meshtasticUsername = UserDefaults.standard.object(forKey: "meshtasticusername") as? String ?? "" + + //self.meshtasticUsername = UserDefaults.standard.object(forKey: "meshtasticusername") as? String ?? "" self.preferredPeripheralName = UserDefaults.standard.object(forKey: "preferredPeripheralName") as? String ?? "" self.preferredPeripheralId = UserDefaults.standard.object(forKey: "preferredPeripheralId") as? String ?? "" - self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false + //self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false self.keyboardType = UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0 - self.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false + self.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? true } } struct AppSettings: View { + @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager @EnvironmentObject var userSettings: UserSettings @@ -92,18 +94,18 @@ struct AppSettings: View { List { Section(header: Text("USER DETAILS")) { - // HStack { - // Label("Name", systemImage: "person.crop.rectangle.fill") - // TextField("Username", text: $userSettings.meshtasticUsername) - // .foregroundColor(.gray) - // } - // .listRowSeparator(.visible) - Toggle(isOn: $userSettings.provideLocation) { - - Label("Provide location to mesh", systemImage: "location.circle.fill") - } - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - .listRowSeparator(.visible) +// HStack { +// Label("Name", systemImage: "person.crop.rectangle.fill") +// TextField("Username", text: $userSettings.meshtasticUsername) +// .foregroundColor(.gray) +// } +// .listRowSeparator(.visible) +// Toggle(isOn: $userSettings.provideLocation) { +// +// Label("Provide location to mesh", systemImage: "location.circle.fill") +// } +// .toggleStyle(SwitchToggleStyle(tint: .accentColor)) +// .listRowSeparator(.visible) Label("Preferred Radio", systemImage: "flipphone") .listRowSeparator(.hidden) Text(userSettings.preferredPeripheralName) @@ -125,29 +127,32 @@ struct AppSettings: View { } .pickerStyle(DefaultPickerStyle()) } - Section(header: Text("MESH NETWORK OPTIONS")) { - Toggle(isOn: $userSettings.meshActivityLog) { - - Label("Log all Mesh activity", systemImage: "network") - } - .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - if userSettings.meshActivityLog { - NavigationLink(destination: MeshLog()) { - Text("View Mesh Log") - } - .listRowSeparator(.visible) - } - } +// Section(header: Text("MESH NETWORK OPTIONS")) { +// Toggle(isOn: $userSettings.meshActivityLog) { +// +// Label("Log all Mesh activity", systemImage: "network") +// } +// .toggleStyle(SwitchToggleStyle(tint: .accentColor)) +// if userSettings.meshActivityLog { +// NavigationLink(destination: MeshLog()) { +// Text("View Mesh Log") +// } +// .listRowSeparator(.visible) +// } +// } } } .navigationTitle("App Settings") .navigationBarItems(trailing: ZStack { - - //ConnectedDevice(bluetoothOn: self.bleManager.isSwitchedOn, deviceConnected: self.bleManager.connectedPeripheral != nil, name: (self.bleManager.connectedNode != nil) ? self.bleManager.connectedNode.user.shortName : ((self.bleManager.connectedPeripheral != nil) ? self.bleManager.connectedPeripheral.name : "Unknown") ) + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "???") }) + .onAppear{ + + self.bleManager.context = context + } } .navigationViewStyle(StackNavigationViewStyle()) }