From 0c112e2a5571b52f7dbec124761c966c1ac641b3 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 26 Mar 2024 14:57:00 -0700 Subject: [PATCH] Online only filter --- Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift | 13 +++++++++++++ Meshtastic/Views/Nodes/NodeList.swift | 12 +++++++++++- .../Views/Settings/Config/Module/MQTTConfig.swift | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift b/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift index 03e04d84..a49fa9f2 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift @@ -13,6 +13,7 @@ struct NodeListFilter: View { /// Filters @Binding var viaLora: Bool @Binding var viaMqtt: Bool + @Binding var isOnline: Bool @Binding var distanceFilter: Bool @Binding var maximumDistance: Double @Binding var hopsAway: Int @@ -44,6 +45,18 @@ struct NodeListFilter: View { .toggleStyle(SwitchToggleStyle(tint: .accentColor)) .listRowSeparator(.visible) + Toggle(isOn: $isOnline) { + + Label { + Text("Online Only") + } icon: { + Image(systemName: "checkmark.circle.fill") + .foregroundColor(.green) + } + } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + .listRowSeparator(.visible) + // Toggle(isOn: $distanceFilter) { // // Label { diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index 2e8bda18..a750658b 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -19,6 +19,7 @@ struct NodeList: View { @State private var searchText = "" @State private var viaLora = true @State private var viaMqtt = true + @State private var isOnline = false @State private var distanceFilter = false @State private var maxDistance: Double = 800000 @State private var hopsAway: Int = -1 @@ -144,7 +145,7 @@ struct NodeList: View { } } .sheet(isPresented: $isEditingFilters) { - NodeListFilter(viaLora: $viaLora, viaMqtt: $viaMqtt, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole) + NodeListFilter(viaLora: $viaLora, viaMqtt: $viaMqtt, isOnline: $isOnline, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole) } .safeAreaInset(edge: .bottom, alignment: .trailing) { HStack { @@ -259,6 +260,9 @@ struct NodeList: View { .onChange(of: hopsAway) { _ in searchNodeList() } + .onChange(of: isOnline) { _ in + searchNodeList() + } .onAppear { if self.bleManager.context == nil { self.bleManager.context = context @@ -295,6 +299,12 @@ struct NodeList: View { let hopsAwayPredicate = NSPredicate(format: "hopsAway == %i", Int32(hopsAway)) predicates.append(hopsAwayPredicate) } + + /// Online + if isOnline { + let isOnlinePredicate = NSPredicate(format: "lastHeard >= %@", Calendar.current.date(byAdding: .minute, value: -15, to: Date())! as NSDate) + predicates.append(isOnlinePredicate) + } /// Distance if distanceFilter { let pointOfInterest = LocationHelper.currentLocation diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index 10563eb3..be067293 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -254,7 +254,7 @@ struct MQTTConfig: View { } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) } - Text("For all Mqtt functionality other than the map report you must also set uplink and downlink for each channel you want to brige over Mqtt.") + Text("For all Mqtt functionality other than the map report you must also set uplink and downlink for each channel you want to bridge over Mqtt.") .font(.callout) } .scrollDismissesKeyboard(.interactively)