Skip to content

Commit

Permalink
Clean up precision ranges for locations on the map report and public key
Browse files Browse the repository at this point in the history
  • Loading branch information
garthvh committed Sep 7, 2024
1 parent 10751e3 commit 4f813c1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
46 changes: 33 additions & 13 deletions Meshtastic/Views/Messages/UserList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct UserList: View {
var boolFilters: [Bool] {[
isFavorite,
isOnline,
isPkiEncrypted,
isEnvironment,
distanceFilter,
roleFilter
Expand All @@ -45,11 +44,12 @@ struct UserList: View {
sortDescriptors: [NSSortDescriptor(key: "lastMessage", ascending: false),
NSSortDescriptor(key: "userNode.favorite", ascending: false),
NSSortDescriptor(key: "pkiEncrypted", ascending: false),
NSSortDescriptor(key: "userNode.lastHeard", ascending: false),
NSSortDescriptor(key: "longName", ascending: true)],
predicate: NSPredicate(format: "hwModelId != nil"),
predicate: NSPredicate(format: "longName != ''"),
animation: .default
)
private var users: FetchedResults<UserEntity>
var users: FetchedResults<UserEntity>

@Binding var node: NodeInfoEntity?
@Binding var userSelection: UserEntity?
Expand Down Expand Up @@ -202,34 +202,55 @@ struct UserList: View {
DirectMessagesHelp()
}
.onChange(of: searchText) { _ in
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: viaLora) { _ in
if !viaLora && !viaMqtt {
viaMqtt = true
}
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: viaMqtt) { _ in
if !viaLora && !viaMqtt {
viaLora = true
}
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: [deviceRoles]) { _ in
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: hopsAway) { _ in
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: [boolFilters]) { _ in
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: maxDistance) { _ in
searchUserList()
Task {
await searchUserList()
}
}
.onChange(of: isPkiEncrypted) { _ in
Task {
await searchUserList()
}
}
.onAppear {
searchUserList()
Task {
await searchUserList()
}
}
.safeAreaInset(edge: .bottom, alignment: .leading) {
HStack {
Expand Down Expand Up @@ -267,8 +288,7 @@ struct UserList: View {
.scrollDismissesKeyboard(.immediately)
}
}

private func searchUserList() {
private func searchUserList() async {

/// Case Insensitive Search Text Predicates
let searchPredicates = ["userId", "numString", "hwModel", "hwDisplayName", "longName", "shortName"].map { property in
Expand Down
6 changes: 3 additions & 3 deletions Meshtastic/Views/Settings/Channels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct Channels: View {
preciseLocation = true
positionsEnabled = true
if channelKey == "AQ==" {
positionPrecision = 13
positionPrecision = 14
preciseLocation = false
}
} else if !supportedVersion && channelRole == 2 {
Expand All @@ -103,8 +103,8 @@ struct Channels: View {
} else {
if channelKey == "AQ==" {
preciseLocation = false
if (positionPrecision > 0 && positionPrecision < 10) || positionPrecision > 16 {
positionPrecision = 13
if (positionPrecision > 0 && positionPrecision < 11) || positionPrecision > 14 {
positionPrecision = 14
}
} else if positionPrecision == 32 {
preciseLocation = true
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Views/Settings/Channels/ChannelForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct ChannelForm: View {
VStack(alignment: .leading) {
Label("Approximate Location", systemImage: "location.slash.circle.fill")

Slider(value: $positionPrecision, in: 10...16, step: 1) {
Slider(value: $positionPrecision, in: 11...14, step: 1) {
} minimumValueLabel: {
Image(systemName: "minus")
} maximumValueLabel: {
Expand Down
48 changes: 15 additions & 33 deletions Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct MQTTConfig: View {
@State var nearbyTopics = [String]()
@State var mapReportingEnabled = false
@State var mapPublishIntervalSecs = 3600
@State var preciseLocation: Bool = false
@State var mapPositionPrecision: Double = 13.0

let locale = Locale.current
Expand Down Expand Up @@ -105,35 +104,17 @@ struct MQTTConfig: View {
}
}
.pickerStyle(DefaultPickerStyle())

VStack(alignment: .leading) {
Toggle(isOn: $preciseLocation) {
Label("Precise Location", systemImage: "scope")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.listRowSeparator(.visible)
.onChange(of: preciseLocation) { pl in
if pl == false {
mapPositionPrecision = 12
} else {
mapPositionPrecision = 32
}
}
}

if !preciseLocation {
VStack(alignment: .leading) {
Label("Approximate Location", systemImage: "location.slash.circle.fill")
Slider(value: $mapPositionPrecision, in: 11...16, step: 1) {
} minimumValueLabel: {
Image(systemName: "minus")
} maximumValueLabel: {
Image(systemName: "plus")
}
Text(PositionPrecision(rawValue: Int(mapPositionPrecision))?.description ?? "")
.foregroundColor(.gray)
.font(.callout)
Label("Approximate Location", systemImage: "location.slash.circle.fill")
Slider(value: $mapPositionPrecision, in: 11...14, step: 1) {
} minimumValueLabel: {
Image(systemName: "minus")
} maximumValueLabel: {
Image(systemName: "plus")
}
Text(PositionPrecision(rawValue: Int(mapPositionPrecision))?.description ?? "")
.foregroundColor(.gray)
.font(.callout)
}
}
}
Expand Down Expand Up @@ -429,11 +410,12 @@ struct MQTTConfig: View {
self.mqttConnected = bleManager.mqttProxyConnected
self.mapReportingEnabled = node?.mqttConfig?.mapReportingEnabled ?? false
self.mapPublishIntervalSecs = Int(node?.mqttConfig?.mapPublishIntervalSecs ?? 3600)
self.mapPositionPrecision = Double(node?.mqttConfig?.mapPositionPrecision ?? 12)
if mapPositionPrecision == 0.0 {
self.mapPositionPrecision = 12
self.mapPositionPrecision = Double(node?.mqttConfig?.mapPositionPrecision ?? 14)
if mapPositionPrecision < 11 || mapPositionPrecision > 14 {
self.mapPositionPrecision = 14
self.hasChanges = true
} else {
self.hasChanges = false
}
self.preciseLocation = mapPositionPrecision == 32
self.hasChanges = false
}
}

0 comments on commit 4f813c1

Please sign in to comment.