Role Silders for user and node list filters

This commit is contained in:
Garth Vander Houwen 2024-06-29 19:13:48 -07:00
parent 457c87c128
commit 8059f4332a
4 changed files with 57 additions and 25 deletions

View file

@ -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." : {

View file

@ -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<Int> = []
@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)

View file

@ -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<Int>
@ -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)
}
}

View file

@ -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<Int> = []
@ -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