From b19109b7c7f34f995e830ecb7e058e1f6a20716b Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 29 Jun 2024 16:05:54 -0700 Subject: [PATCH] role filter mockup --- Localizable.xcstrings | 5 +++- Meshtastic/Views/Messages/UserList.swift | 4 ++- .../Views/Nodes/Helpers/NodeListFilter.swift | 27 +++++++++++++++++++ Meshtastic/Views/Nodes/NodeList.swift | 11 ++++---- .../Views/Settings/Logs/AppLogFilter.swift | 2 +- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index aa22cc67..2423c914 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -17386,6 +17386,9 @@ }, "Role: %@" : { + }, + "Roles" : { + }, "Root Topic" : { @@ -22405,4 +22408,4 @@ } }, "version" : "1.0" -} +} \ No newline at end of file diff --git a/Meshtastic/Views/Messages/UserList.swift b/Meshtastic/Views/Messages/UserList.swift index a7bab2a2..0f068c29 100644 --- a/Meshtastic/Views/Messages/UserList.swift +++ b/Meshtastic/Views/Messages/UserList.swift @@ -26,6 +26,8 @@ struct UserList: View { @State private var maxDistance: Double = 800000 @State private var hopsAway: Int = -1 @State private var deviceRole: Int = -1 + @State private var roleFilter = false + @State private var deviceRoles: Set = [] @State var isEditingFilters = false @FetchRequest( @@ -170,7 +172,7 @@ struct UserList: View { .listStyle(.plain) .navigationTitle(String.localizedStringWithFormat("contacts %@".localized, String(users.count == 0 ? 0 : users.count - 1))) .sheet(isPresented: $isEditingFilters) { - NodeListFilter(filterTitle: "Contact Filters", viaLora: $viaLora, viaMqtt: $viaMqtt, isOnline: $isOnline, isFavorite: $isFavorite, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole) + NodeListFilter(filterTitle: "Contact Filters", viaLora: $viaLora, viaMqtt: $viaMqtt, isOnline: $isOnline, isFavorite: $isFavorite, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole, roleFilter: $roleFilter, deviceRoles: $deviceRoles) } .onChange(of: searchText) { _ in searchUserList() diff --git a/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift b/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift index a5917f63..ba4b64e7 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeListFilter.swift @@ -10,6 +10,7 @@ import SwiftUI struct NodeListFilter: View { @Environment(\.dismiss) private var dismiss + @State var editMode = EditMode.active /// Filters var filterTitle = "Node Filters" @Binding var viaLora: Bool @@ -20,6 +21,7 @@ struct NodeListFilter: View { @Binding var maximumDistance: Double @Binding var hopsAway: Int @Binding var deviceRole: Int + @Binding var roleFilter: Bool @Binding var deviceRoles: Set var body: some View { @@ -127,6 +129,31 @@ struct NodeListFilter: View { } .pickerStyle(DefaultPickerStyle()) } + Toggle(isOn: $roleFilter) { + + Label { + Text("Roles") + } icon: { + Image(systemName: "apps.iphone") + } + } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + + .listRowSeparator(roleFilter ? .hidden : .visible) + if roleFilter { + VStack { + List(DeviceRoles.allCases, selection: $deviceRoles) { dr in + Label { + Text(" \(dr.name)") + } icon: { + Image(systemName: dr.systemName) + } + } + .listStyle(.plain) + .environment(\.editMode, $editMode) /// bind it here! + .frame(minHeight: 210, maxHeight: .infinity) + } + } } } #if targetEnvironment(macCatalyst) diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index b71d53b1..18ac320a 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -26,7 +26,8 @@ struct NodeList: View { @State private var distanceFilter = false @State private var maxDistance: Double = 800000 @State private var hopsAway: Int = -1 - @State private var deviceRole: Int = -1 + @State private var nodeRole: Int = -1 + @State private var roleFilter = false @State private var deviceRoles: Set = [] @State var isEditingFilters = false @@ -189,7 +190,7 @@ struct NodeList: View { } } .sheet(isPresented: $isEditingFilters) { - NodeListFilter(viaLora: $viaLora, viaMqtt: $viaMqtt, isOnline: $isOnline, isFavorite: $isFavorite, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole, deviceRoles: $deviceRoles) + NodeListFilter(viaLora: $viaLora, viaMqtt: $viaMqtt, isOnline: $isOnline, isFavorite: $isFavorite, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $nodeRole, roleFilter: $roleFilter, deviceRoles: $deviceRoles) } .safeAreaInset(edge: .bottom, alignment: .trailing) { HStack { @@ -298,7 +299,7 @@ struct NodeList: View { } searchNodeList() } - .onChange(of: deviceRole) { _ in + .onChange(of: nodeRole) { _ in searchNodeList() } .onChange(of: hopsAway) { _ in @@ -363,8 +364,8 @@ struct NodeList: View { } } /// Role - if deviceRole > -1 { - let rolePredicate = NSPredicate(format: "user.role == %i", Int32(deviceRole)) + if nodeRole > -1 { + let rolePredicate = NSPredicate(format: "user.role == %i", Int32(nodeRole)) predicates.append(rolePredicate) } /// Hops Away diff --git a/Meshtastic/Views/Settings/Logs/AppLogFilter.swift b/Meshtastic/Views/Settings/Logs/AppLogFilter.swift index 46d6f838..9943c2de 100644 --- a/Meshtastic/Views/Settings/Logs/AppLogFilter.swift +++ b/Meshtastic/Views/Settings/Logs/AppLogFilter.swift @@ -101,7 +101,7 @@ struct AppLogFilter: View { var filterTitle = "App Log Filters" @Binding var categories: Set @Binding var levels: Set - @State var editMode = EditMode.active /// the edit mode + @State var editMode = EditMode.active var body: some View {