From 8059f4332a239205484c4ce03226572c669e49c1 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 29 Jun 2024 19:13:48 -0700 Subject: [PATCH] Role Silders for user and node list filters --- Localizable.xcstrings | 21 ++++++++++-- Meshtastic/Views/Messages/UserList.swift | 14 +++++--- .../Views/Nodes/Helpers/NodeListFilter.swift | 34 ++++++++++++------- Meshtastic/Views/Nodes/NodeList.swift | 13 ++++--- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index d382e186..2fd86fed 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -139,9 +139,15 @@ }, "%d%%" : { + }, + "%lf" : { + }, "%lld" : { + }, + "%lld or less hops away" : { + }, "%lld Readings Total" : { @@ -166,6 +172,15 @@ }, "1 byte" : { + }, + "1 hop away" : { + + }, + "7" : { + + }, + "8" : { + }, "25" : { @@ -665,6 +680,9 @@ }, "Alert when receiving a message" : { + }, + "All" : { + }, "All device and app data will be deleted. You will also need to forget your devices under Settings > Bluetooth." : { @@ -870,9 +888,6 @@ }, "An open source, off-grid, decentralized, mesh network that runs on affordable, low-power radios." : { - }, - "Any" : { - }, "Any missed messages will be delivered again." : { diff --git a/Meshtastic/Views/Messages/UserList.swift b/Meshtastic/Views/Messages/UserList.swift index 393458df..21be016a 100644 --- a/Meshtastic/Views/Messages/UserList.swift +++ b/Meshtastic/Views/Messages/UserList.swift @@ -24,7 +24,7 @@ struct UserList: View { @State private var isFavorite = false @State private var distanceFilter = false @State private var maxDistance: Double = 800000 - @State private var hopsAway: Int = -1 + @State private var hopsAway: Double = -1.0 @State private var roleFilter = false @State private var deviceRoles: Set = [] @State var isEditingFilters = false @@ -271,11 +271,15 @@ struct UserList: View { predicates.append(compoundPredicate) } /// Hops Away - if hopsAway > 0 { - let hopsAwayPredicate = NSPredicate(format: "userNode.hopsAway == %i", Int32(hopsAway)) - predicates.append(hopsAwayPredicate) + if hopsAway > -1.0 { + if hopsAway == 0.0 { + let hopsAwayPredicate = NSPredicate(format: "userNode.hopsAway == %i", Int32(hopsAway)) + predicates.append(hopsAwayPredicate) + } else { + let hopsAwayPredicate = NSPredicate(format: "userNode.hopsAway > 0 AND userNode.hopsAway <= %i", Int32(hopsAway)) + predicates.append(hopsAwayPredicate) + } } - /// Online if isOnline { let isOnlinePredicate = NSPredicate(format: "userNode.lastHeard >= %@", Calendar.current.date(byAdding: .minute, value: -15, to: Date())! as NSDate) diff --git a/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift b/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift index 5559037b..15f8f712 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift @@ -19,7 +19,7 @@ struct NodeListFilter: View { @Binding var isFavorite: Bool @Binding var distanceFilter: Bool @Binding var maximumDistance: Double - @Binding var hopsAway: Int + @Binding var hopsAway: Double @Binding var roleFilter: Bool @Binding var deviceRoles: Set @@ -99,19 +99,27 @@ struct NodeListFilter: View { .pickerStyle(DefaultPickerStyle()) } } - HStack { + VStack(alignment: .leading) { Label("Hops Away", systemImage: "hare") - Picker("", selection: $hopsAway) { - Text("Any") - .tag(-1) - Text("Direct") - .tag(0) - ForEach(1..<8) { - Text("\($0)") - .tag($0) - } + Slider( + value: $hopsAway, + in: -1...7, + step: 1 + ) { + Text("Speed") + } minimumValueLabel: { + Text("All") + } maximumValueLabel: { + Text("7") + } + if hopsAway >= 0 { + if hopsAway == 0 { + Text("Direct") + } else if hopsAway == 1 { + Text("1 hop away") + } else { + Text("\(Int(hopsAway)) or less hops away") } } - .pickerStyle(DefaultPickerStyle()) } Toggle(isOn: $roleFilter) { @@ -153,7 +161,7 @@ struct NodeListFilter: View { .padding(.bottom) #endif } - .presentationDetents([.fraction(roleFilter ? 1.0 : 0.55)]) + .presentationDetents([.fraction(roleFilter ? 1.0 : 0.65)]) .presentationDragIndicator(.visible) } } diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index 0f8c8683..81c034cc 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -25,7 +25,7 @@ struct NodeList: View { @State private var isFavorite = false @State private var distanceFilter = false @State private var maxDistance: Double = 800000 - @State private var hopsAway: Int = -1 + @State private var hopsAway: Double = -1.0 @State private var roleFilter = false @State private var deviceRoles: Set = [] @@ -373,9 +373,14 @@ struct NodeList: View { predicates.append(compoundPredicate) } /// Hops Away - if hopsAway > 0 { - let hopsAwayPredicate = NSPredicate(format: "hopsAway == %i", Int32(hopsAway)) - predicates.append(hopsAwayPredicate) + if hopsAway > -1.0 { + if hopsAway == 0.0 { + let hopsAwayPredicate = NSPredicate(format: "hopsAway == %i", Int32(hopsAway)) + predicates.append(hopsAwayPredicate) + } else { + let hopsAwayPredicate = NSPredicate(format: "hopsAway > 0 AND hopsAway <= %i", Int32(hopsAway)) + predicates.append(hopsAwayPredicate) + } } /// Online