From 7f1e2a2f5eec503e98e5779c88d6e9c1565d848f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Fri, 20 Oct 2023 16:49:42 -0700 Subject: [PATCH] Add unknown age to node list timestamp --- Meshtastic/Views/Helpers/LastHeardText.swift | 2 +- .../Views/Nodes/Helpers/NodeListItem.swift | 2 +- .../Views/Nodes/Helpers/NodeMapSwiftUI.swift | 6 +- Meshtastic/Views/Settings/Settings.swift | 70 +++++++++---------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Meshtastic/Views/Helpers/LastHeardText.swift b/Meshtastic/Views/Helpers/LastHeardText.swift index 97acce81..02c23f9f 100644 --- a/Meshtastic/Views/Helpers/LastHeardText.swift +++ b/Meshtastic/Views/Helpers/LastHeardText.swift @@ -17,7 +17,7 @@ struct LastHeardText: View { var body: some View { if lastHeard != nil && lastHeard! >= sixMonthsAgo! { - Text("heard")+Text(" \(LastHeardText.formatter.localizedString(for: lastHeard!, relativeTo: Date.now))") + Text(lastHeard?.formatted() ?? "unknown.age".localized) } else { Text("unknown.age") } diff --git a/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift b/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift index ea49426e..a4b9f1e9 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeListItem.swift @@ -54,7 +54,7 @@ struct NodeListItem: View { .font(.callout) .symbolRenderingMode(.hierarchical) .foregroundColor(node.isOnline ? .green : .orange) - Text(node.lastHeard?.formatted() ?? "unknown".localized) + LastHeardText(lastHeard: node.lastHeard) .font(.callout) } if node.positions?.count ?? 0 > 0 && connectedNode != node.num { diff --git a/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift b/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift index 3546f7ec..066125e5 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift @@ -293,9 +293,9 @@ struct NodeMapSwiftUI: View { .padding() #endif } - .presentationDetents([.fraction(0.60)]) - //.presentationDetents([.medium, .large]) - .presentationDragIndicator(.automatic) + //.presentationDetents([.fraction(0.60)]) + .presentationDetents([.medium, .large]) + .presentationDragIndicator(.visible) } .onChange(of: node) { let mostRecent = node.positions?.lastObject as? PositionEntity diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index 59b75425..a4972a90 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -14,7 +14,6 @@ struct Settings: View { private var nodes: FetchedResults @State private var selectedNode: Int = 0 @State private var connectedNodeNum: Int = 0 - @State private var initialLoad: Bool = true @State private var selection: SettingsSidebar = .about enum SettingsSidebar { case appSettings @@ -60,41 +59,43 @@ struct Settings: View { .tag(SettingsSidebar.appSettings) let node = nodes.first(where: { $0.num == connectedNodeNum }) let hasAdmin = node?.myInfo?.adminIndex ?? 0 > 0 ? true : false - - if !(node?.deviceConfig?.isManaged ?? false) { Section("Configure") { - Picker("Configuring Node", selection: $selectedNode) { - if selectedNode == 0 { - Text("Connect to a Node").tag(0) - } - ForEach(nodes) { node in - if node.num == bleManager.connectedPeripheral?.num ?? 0 { - Text("BLE Config: \(node.user?.longName ?? "unknown".localized)") - .tag(Int(node.num)) - } else if node.metadata != nil { - Text("Remote Config: \(node.user?.longName ?? "unknown".localized)") - .tag(Int(node.num)) - } else if hasAdmin { - Text("Request Admin: \(node.user?.longName ?? "unknown".localized)") - .tag(Int(node.num)) + if hasAdmin { + Picker("Configuring Node", selection: $selectedNode) { + if selectedNode == 0 { + Text("Connect to a Node").tag(0) } - } - } - .pickerStyle(.automatic) - .labelsHidden() - .onChange(of: selectedNode) { newValue in - if selectedNode > 0 { - let node = nodes.first(where: { $0.num == newValue }) - let connectedNode = nodes.first(where: { $0.num == connectedNodeNum }) - connectedNodeNum = Int(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral?.num ?? 0 : 0) - if connectedNode != nil && connectedNode?.user != nil && connectedNode?.myInfo != nil && node?.user != nil && node?.metadata == nil { - let adminMessageId = bleManager.requestDeviceMetadata(fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode!.myInfo!.adminIndex, context: context) - if adminMessageId > 0 { - print("Sent node metadata request from node details") + ForEach(nodes) { node in + if node.num == bleManager.connectedPeripheral?.num ?? 0 { + Text("BLE Config: \(node.user?.longName ?? "unknown".localized)") + .tag(Int(node.num)) + } else if node.metadata != nil { + Text("Remote Config: \(node.user?.longName ?? "unknown".localized)") + .tag(Int(node.num)) + } else if hasAdmin { + Text("Request Admin: \(node.user?.longName ?? "unknown".localized)") + .tag(Int(node.num)) } } } + .pickerStyle(.automatic) + .labelsHidden() + .onChange(of: selectedNode) { newValue in + if selectedNode > 0 { + let node = nodes.first(where: { $0.num == newValue }) + let connectedNode = nodes.first(where: { $0.num == connectedNodeNum }) + connectedNodeNum = Int(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral?.num ?? 0 : 0) + if connectedNode != nil && connectedNode?.user != nil && connectedNode?.myInfo != nil && node?.user != nil && node?.metadata == nil { + let adminMessageId = bleManager.requestDeviceMetadata(fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode!.myInfo!.adminIndex, context: context) + if adminMessageId > 0 { + print("Sent node metadata request from node details") + } + } + } + } + } else { + Text("Configuring Node \(node?.user?.longName ?? "unknown".localized)") } } Section("radio.configuration") { @@ -279,12 +280,11 @@ struct Settings: View { } } .onAppear { - self.bleManager.context = context - self.connectedNodeNum = Int(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral?.num ?? 0 : 0) - if initialLoad { - selectedNode = Int(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral?.num ?? 0 : 0) - initialLoad = false + if self.bleManager.context == nil { + self.bleManager.context = context } + self.connectedNodeNum = Int(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral?.num ?? 0 : 0) + selectedNode = Int(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral?.num ?? 0 : 0) } .listStyle(GroupedListStyle()) .navigationTitle("settings")