mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Remove keyboard type setting, hook up map settings toggles
This commit is contained in:
parent
6dc63099e6
commit
8c01abacce
7 changed files with 110 additions and 71 deletions
|
|
@ -10,11 +10,11 @@ import Foundation
|
|||
extension UserDefaults {
|
||||
|
||||
enum Keys: String, CaseIterable {
|
||||
case hasBeenLaunched
|
||||
case meshtasticUsername
|
||||
case preferredPeripheralId
|
||||
case provideLocation
|
||||
case provideLocationInterval
|
||||
case keyboardType
|
||||
case meshMapType
|
||||
case meshMapCenteringMode
|
||||
case meshMapRecentering
|
||||
|
|
@ -37,6 +37,43 @@ extension UserDefaults {
|
|||
}
|
||||
}
|
||||
|
||||
static var meshtasticUsername: String {
|
||||
get {
|
||||
UserDefaults.standard.string(forKey: "meshtasticUsername") ?? ""
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: "meshtasticUsername")
|
||||
}
|
||||
}
|
||||
|
||||
static var preferredPeripheralId: String {
|
||||
get {
|
||||
UserDefaults.standard.string(forKey: "preferredPeripheralId") ?? ""
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: "preferredPeripheralId")
|
||||
}
|
||||
}
|
||||
|
||||
static var provideLocation: Bool {
|
||||
get {
|
||||
let result = UserDefaults.standard.bool(forKey: "provideLocation")
|
||||
UserDefaults.standard.set(true, forKey: "provideLocation")
|
||||
return result
|
||||
} set {
|
||||
UserDefaults.standard.set(newValue, forKey: "provideLocation")
|
||||
}
|
||||
}
|
||||
|
||||
static var provideLocationInterval: Int {
|
||||
get {
|
||||
UserDefaults.standard.integer(forKey: "provideLocationInterval")
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: "provideLocationInterval")
|
||||
}
|
||||
}
|
||||
|
||||
static var mapType: Int {
|
||||
get {
|
||||
UserDefaults.standard.integer(forKey: "meshMapType")
|
||||
|
|
|
|||
|
|
@ -31,12 +31,6 @@ class UserSettings: ObservableObject {
|
|||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
}
|
||||
@Published var keyboardType: Int {
|
||||
didSet {
|
||||
UserDefaults.standard.set(keyboardType, forKey: "keyboardType")
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
}
|
||||
@Published var meshMapType: String {
|
||||
didSet {
|
||||
UserDefaults.standard.set(meshMapType, forKey: "meshMapType")
|
||||
|
|
@ -86,7 +80,6 @@ class UserSettings: ObservableObject {
|
|||
self.preferredPeripheralId = UserDefaults.standard.object(forKey: "preferredPeripheralId") as? String ?? ""
|
||||
self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false
|
||||
self.provideLocationInterval = UserDefaults.standard.object(forKey: "provideLocationInterval") as? Int ?? 900
|
||||
self.keyboardType = UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0
|
||||
self.meshMapType = UserDefaults.standard.string(forKey: "meshMapType") ?? "standard"
|
||||
self.meshMapCenteringMode = UserDefaults.standard.object(forKey: "meshMapCenteringMode") as? Int ?? 0
|
||||
self.meshMapRecentering = UserDefaults.standard.object(forKey: "meshMapRecentering") as? Bool ?? false
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
let userTrackingMode: MKUserTrackingMode
|
||||
let showNodeHistory: Bool
|
||||
let showRouteLines: Bool
|
||||
@AppStorage("meshMapRecentering") private var recenter: Bool = false
|
||||
// User Defaults
|
||||
//@State var enableMapRecentering: Bool = UserDefaults.enableMapRecentering
|
||||
// Offline Map Tiles
|
||||
@AppStorage("lastUpdatedLocalMapFile") private var lastUpdatedLocalMapFile = 0
|
||||
@State private var loadedLastUpdatedLocalMapFile = 0
|
||||
|
|
@ -119,6 +120,7 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
|
||||
mapView.mapType = mapViewType
|
||||
|
||||
// Offline maps and tile server settings
|
||||
if UserDefaults.enableOfflineMaps {
|
||||
|
||||
if tileServerUrl.count > 0 {
|
||||
|
|
@ -166,60 +168,69 @@ struct MapViewSwiftUI: UIViewRepresentable {
|
|||
}
|
||||
}
|
||||
|
||||
let latest = positions
|
||||
.filter { $0.latest == true }
|
||||
.sorted { $0.nodePosition?.num ?? 0 > $1.nodePosition?.num ?? -1 }
|
||||
|
||||
DispatchQueue.main.async {
|
||||
let latest = positions
|
||||
.filter { $0.latest == true }
|
||||
.sorted { $0.nodePosition?.num ?? 0 > $1.nodePosition?.num ?? -1 }
|
||||
// Node Route Lines
|
||||
if showRouteLines {
|
||||
// Remove all existing PolyLine Overlays
|
||||
for overlay in mapView.overlays {
|
||||
if overlay is MKPolyline {
|
||||
mapView.removeOverlay(overlay)
|
||||
}
|
||||
}
|
||||
var lineIndex = 0
|
||||
for position in latest {
|
||||
|
||||
let nodePositions = positions.filter { $0.nodePosition?.num ?? 0 == position.nodePosition?.num ?? -1 }
|
||||
let lineCoords = nodePositions.map ({
|
||||
(position) -> CLLocationCoordinate2D in
|
||||
return position.nodeCoordinate!
|
||||
})
|
||||
let polyline = MKPolyline(coordinates: lineCoords, count: nodePositions.count)
|
||||
polyline.title = "\(String(position.nodePosition?.num ?? 0))"
|
||||
mapView.addOverlay(polyline, level: .aboveLabels)
|
||||
lineIndex += 1
|
||||
// There are 18 colors for lines, start over if we are at index 17
|
||||
if lineIndex > 17 {
|
||||
lineIndex = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//DispatchQueue.main.async {
|
||||
|
||||
|
||||
|
||||
|
||||
let annotationCount = waypoints.count + (showNodeHistory ? positions.count : latest.count)
|
||||
// if annotationCount != mapView.annotations.count {
|
||||
if annotationCount != mapView.annotations.count {
|
||||
print("Annotation Count: \(annotationCount) Map Annotations: \(mapView.annotations.count)")
|
||||
mapView.removeAnnotations(mapView.annotations)
|
||||
mapView.addAnnotations(waypoints)
|
||||
if showRouteLines {
|
||||
// Remove all existing PolyLine Overlays
|
||||
for overlay in mapView.overlays {
|
||||
if overlay is MKPolyline {
|
||||
mapView.removeOverlay(overlay)
|
||||
}
|
||||
}
|
||||
var lineIndex = 0
|
||||
for position in latest {
|
||||
|
||||
let nodePositions = positions.filter { $0.nodePosition?.num ?? 0 == position.nodePosition?.num ?? -1 }
|
||||
let lineCoords = nodePositions.map ({
|
||||
(position) -> CLLocationCoordinate2D in
|
||||
return position.nodeCoordinate!
|
||||
})
|
||||
let polyline = MKPolyline(coordinates: lineCoords, count: nodePositions.count)
|
||||
polyline.title = "\(String(position.nodePosition?.num ?? 0))"
|
||||
mapView.addOverlay(polyline, level: .aboveLabels)
|
||||
lineIndex += 1
|
||||
// There are 18 colors for lines, start over if we are at index 17
|
||||
if lineIndex > 17 {
|
||||
lineIndex = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.showsUserLocation = false
|
||||
|
||||
}
|
||||
if userTrackingMode == MKUserTrackingMode.none {
|
||||
mapView.showsUserLocation = false
|
||||
|
||||
if UserDefaults.enableMapRecentering {
|
||||
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
if recenter {
|
||||
if latest.count > 1 {
|
||||
mapView.fitAllAnnotations()
|
||||
} else {
|
||||
mapView.fit(annotations:showNodeHistory ? positions : latest, andShow: false)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Centering Done by tracking mode
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
mapView.showsUserLocation = true
|
||||
mapView.fitAllAnnotations()
|
||||
// if latest.count > 1 {
|
||||
// mapView.fitAllAnnotations()
|
||||
// } else {
|
||||
// mapView.fit(annotations:showNodeHistory ? positions : latest, andShow: false)
|
||||
// }
|
||||
}
|
||||
mapView.setUserTrackingMode(userTrackingMode, animated: true)
|
||||
//}
|
||||
}
|
||||
} else {
|
||||
// Centering Done by tracking mode
|
||||
mapView.addAnnotations(showNodeHistory ? positions : latest)
|
||||
mapView.showsUserLocation = true
|
||||
}
|
||||
mapView.setUserTrackingMode(userTrackingMode, animated: true)
|
||||
// }
|
||||
}
|
||||
|
||||
func makeCoordinator() -> MapCoordinator {
|
||||
|
|
|
|||
|
|
@ -275,7 +275,6 @@ struct ChannelMessageList: View {
|
|||
HStack(alignment: .top) {
|
||||
|
||||
ZStack {
|
||||
let kbType = UIKeyboardType(rawValue: UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0)
|
||||
TextField("message", text: $typingMessage, axis: .vertical)
|
||||
.onChange(of: typingMessage, perform: { value in
|
||||
totalBytes = value.utf8.count
|
||||
|
|
@ -290,7 +289,7 @@ struct ChannelMessageList: View {
|
|||
}
|
||||
}
|
||||
})
|
||||
.keyboardType(kbType!)
|
||||
.keyboardType(.default)
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .keyboard) {
|
||||
Button("dismiss.keyboard") {
|
||||
|
|
|
|||
|
|
@ -266,7 +266,6 @@ struct UserMessageList: View {
|
|||
|
||||
HStack(alignment: .top) {
|
||||
ZStack {
|
||||
let kbType = UIKeyboardType(rawValue: UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0)
|
||||
TextField("message", text: $typingMessage, axis: .vertical)
|
||||
.onChange(of: typingMessage, perform: { value in
|
||||
totalBytes = value.utf8.count
|
||||
|
|
@ -281,7 +280,7 @@ struct UserMessageList: View {
|
|||
}
|
||||
}
|
||||
})
|
||||
.keyboardType(kbType!)
|
||||
.keyboardType(.default)
|
||||
.toolbar {
|
||||
ToolbarItemGroup(placement: .keyboard) {
|
||||
Button("dismiss.keyboard") {
|
||||
|
|
|
|||
|
|
@ -103,19 +103,29 @@ struct NodeMap: View {
|
|||
Label("map.recentering", systemImage: "camera.metering.center.weighted")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
.onTapGesture {
|
||||
self.enableMapRecentering.toggle()
|
||||
UserDefaults.enableMapRecentering = self.enableMapRecentering
|
||||
}
|
||||
|
||||
Toggle(isOn: $enableMapNodeHistoryPins) {
|
||||
|
||||
Label("Show Node History", systemImage: "building.columns.fill")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
.onTapGesture {
|
||||
self.enableMapNodeHistoryPins.toggle()
|
||||
UserDefaults.enableMapNodeHistoryPins = self.enableMapNodeHistoryPins
|
||||
}
|
||||
|
||||
Toggle(isOn: $enableMapRouteLines) {
|
||||
|
||||
Label("Show Route Lines", systemImage: "road.lanes")
|
||||
}
|
||||
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
|
||||
.onChange(of: (enableMapRouteLines)) { newEnableMapRouteLines in
|
||||
UserDefaults.enableMapRouteLines = newEnableMapRouteLines
|
||||
.onTapGesture {
|
||||
self.enableMapRouteLines.toggle()
|
||||
UserDefaults.enableMapRouteLines = self.enableMapRouteLines
|
||||
}
|
||||
}
|
||||
Section(header: Text("Offline Maps")) {
|
||||
|
|
|
|||
|
|
@ -27,16 +27,6 @@ struct AppSettings: View {
|
|||
.disableAutocorrection(true)
|
||||
.listRowSeparator(.visible)
|
||||
}
|
||||
Section(header: Text("options")) {
|
||||
|
||||
Picker("keyboard.type", selection: $userSettings.keyboardType) {
|
||||
ForEach(KeyboardType.allCases) { kb in
|
||||
Text(kb.description)
|
||||
}
|
||||
}
|
||||
.pickerStyle(DefaultPickerStyle())
|
||||
|
||||
}
|
||||
|
||||
Section(header: Text("phone.gps")) {
|
||||
let accuracy = Measurement(value: locationHelper.locationManager.location?.horizontalAccuracy ?? 300, unit: UnitLength.meters)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue