From 0dcdd4f009054db36edf0206d3e7195bbc9d0b8c Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 13 May 2023 14:23:12 -0700 Subject: [PATCH] Button size cleanup --- Meshtastic.xcodeproj/project.pbxproj | 4 - Meshtastic/Enums/LoraConfigEnums.swift | 20 +++++ Meshtastic/Helpers/BLEManager.swift | 3 +- Meshtastic/Views/Map/Custom/TilesView.swift | 49 ---------- Meshtastic/Views/Map/WaypointFormView.swift | 6 +- Meshtastic/Views/Settings/AppSettings.swift | 99 +++++++++++++-------- en.lproj/Localizable.strings | 4 +- 7 files changed, 87 insertions(+), 98 deletions(-) delete mode 100644 Meshtastic/Views/Map/Custom/TilesView.swift diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index aec6aa6a..07b1d397 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -103,7 +103,6 @@ DDB75A142A0593E2006ED576 /* OfflineTileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB75A132A0593E2006ED576 /* OfflineTileManager.swift */; }; DDB75A162A0594AD006ED576 /* TileOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB75A152A0594AD006ED576 /* TileOverlay.swift */; }; DDB75A1A2A05EB67006ED576 /* alpha.png in Resources */ = {isa = PBXBuildFile; fileRef = DDB75A192A05EB67006ED576 /* alpha.png */; }; - DDB75A1C2A076DFA006ED576 /* TilesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB75A1B2A076DFA006ED576 /* TilesView.swift */; }; DDB75A1E2A0B0CD0006ED576 /* LoRaSignalStrengthIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB75A1D2A0B0CD0006ED576 /* LoRaSignalStrengthIndicator.swift */; }; DDC2E15826CE248E0042C5E4 /* MeshtasticApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E15726CE248E0042C5E4 /* MeshtasticApp.swift */; }; DDC2E15C26CE248F0042C5E4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */; }; @@ -293,7 +292,6 @@ DDB75A132A0593E2006ED576 /* OfflineTileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineTileManager.swift; sourceTree = ""; }; DDB75A152A0594AD006ED576 /* TileOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileOverlay.swift; sourceTree = ""; }; DDB75A192A05EB67006ED576 /* alpha.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = alpha.png; sourceTree = ""; }; - DDB75A1B2A076DFA006ED576 /* TilesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilesView.swift; sourceTree = ""; }; DDB75A1D2A0B0CD0006ED576 /* LoRaSignalStrengthIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoRaSignalStrengthIndicator.swift; sourceTree = ""; }; DDBA45EC299ED78100DEEDDC /* MeshtasticDataModelV8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV8.xcdatamodel; sourceTree = ""; }; DDC2E15426CE248E0042C5E4 /* Meshtastic.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Meshtastic.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -403,7 +401,6 @@ DD964FC32974767D007C176F /* MapViewFitExtension.swift */, DD2AD8A7296D2DF9001FF0E7 /* MapViewSwiftUI.swift */, DDDB443529F6287000EE2349 /* MapButtons.swift */, - DDB75A1B2A076DFA006ED576 /* TilesView.swift */, ); path = Custom; sourceTree = ""; @@ -1010,7 +1007,6 @@ DD2160AF28C5552500C17253 /* MQTTConfig.swift in Sources */, DDDB444229F8A88700EE2349 /* Double.swift in Sources */, DD5E520F298EE33B00D21B61 /* cannedmessages.pb.swift in Sources */, - DDB75A1C2A076DFA006ED576 /* TilesView.swift in Sources */, DDB75A162A0594AD006ED576 /* TileOverlay.swift in Sources */, DDF924CA26FBB953009FE055 /* ConnectedDevice.swift in Sources */, DD3CC6BE28E4CD9800FA9159 /* BatteryGauge.swift in Sources */, diff --git a/Meshtastic/Enums/LoraConfigEnums.swift b/Meshtastic/Enums/LoraConfigEnums.swift index b6738878..805a4288 100644 --- a/Meshtastic/Enums/LoraConfigEnums.swift +++ b/Meshtastic/Enums/LoraConfigEnums.swift @@ -135,6 +135,26 @@ enum ModemPresets: Int, CaseIterable, Identifiable { return "Short Range - Fast" } } + func snrLimit() -> Float { + switch self { + case .longFast: + return -17.5 + case .longSlow: + return -7.5 + case .longModerate: + return -17.5 + case .vLongSlow: + return -20 + case .medSlow: + return -15 + case .medFast: + return -12.5 + case .shortSlow: + return -10 + case .shortFast: + return -7.5 + } + } func protoEnumValue() -> Config.LoRaConfig.ModemPreset { switch self { case .longFast: diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 107e6f1b..43cbfd8e 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -787,9 +787,10 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject { if LocationHelper.currentSpeed >= 0 { positionPacket.groundSpeed = UInt32(LocationHelper.currentSpeed * 3.6) } - if LocationHelper.currentHeading >= 0 { + if (!LocationHelper.currentHeading.isNaN || !LocationHelper.currentHeading.isInfinite) { positionPacket.groundTrack = UInt32(LocationHelper.currentHeading) } + var meshPacket = MeshPacket() meshPacket.to = UInt32(destNum) meshPacket.from = UInt32(fromNodeNum) diff --git a/Meshtastic/Views/Map/Custom/TilesView.swift b/Meshtastic/Views/Map/Custom/TilesView.swift deleted file mode 100644 index b5927945..00000000 --- a/Meshtastic/Views/Map/Custom/TilesView.swift +++ /dev/null @@ -1,49 +0,0 @@ -// -// TilesView.swift -// Meshtastic -// -// Copyright(c) Garth Vander Houwen on 5/6/23. -// - -import SwiftUI -import MapKit - -struct TilesView: View { - - @ObservedObject var tileManager = OfflineTileManager.shared - @State var totalDownloadedTileSize = "" - - var body: some View { - - Button(action: { - tileManager.removeAll() - totalDownloadedTileSize = tileManager.getAllDownloadedSize() - print("delete all tiles") - }) { - - HStack { - Image(systemName: "trash") - .font(.callout) - .foregroundColor(.red) - Text("\("map.tiles.delete".localized) (\(totalDownloadedTileSize))") - .font(.callout) - .foregroundColor(.red) - Spacer() - } - } - .onAppear(perform: { - totalDownloadedTileSize = tileManager.getAllDownloadedSize() - }) - } -} - -// MARK: Previews -struct TilesView_Previews: PreviewProvider { - - static var previews: some View { - - TilesView() - .previewLayout(.fixed(width: 300, height: 80)) - .environment(\.colorScheme, .light) - } -} diff --git a/Meshtastic/Views/Map/WaypointFormView.swift b/Meshtastic/Views/Map/WaypointFormView.swift index 4f1171b6..1b375f4d 100644 --- a/Meshtastic/Views/Map/WaypointFormView.swift +++ b/Meshtastic/Views/Map/WaypointFormView.swift @@ -167,7 +167,7 @@ struct WaypointFormView: View { } .buttonStyle(.bordered) .buttonBorderShape(.capsule) - .controlSize(.large) + .controlSize(.regular) .disabled(bleManager.connectedPeripheral == nil) .padding(.bottom) @@ -178,7 +178,7 @@ struct WaypointFormView: View { } .buttonStyle(.bordered) .buttonBorderShape(.capsule) - .controlSize(.large) + .controlSize(.regular) .padding(.bottom) if coordinate.waypointId > 0 { @@ -230,7 +230,7 @@ struct WaypointFormView: View { } .buttonStyle(.bordered) .buttonBorderShape(.capsule) - .controlSize(.large) + .controlSize(.regular) .padding(.bottom) } } diff --git a/Meshtastic/Views/Settings/AppSettings.swift b/Meshtastic/Views/Settings/AppSettings.swift index 3da32607..febb27e3 100644 --- a/Meshtastic/Views/Settings/AppSettings.swift +++ b/Meshtastic/Views/Settings/AppSettings.swift @@ -8,11 +8,14 @@ struct AppSettings: View { @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager + @ObservedObject var tileManager = OfflineTileManager.shared + @State var totalDownloadedTileSize = "" @StateObject var locationHelper = LocationHelper() @State var meshtasticUsername: String = UserDefaults.meshtasticUsername @State var provideLocation: Bool = UserDefaults.provideLocation @State var provideLocationInterval: Int = UserDefaults.provideLocationInterval @State private var isPresentingCoreDataResetConfirm = false + @State private var isPresentingDeleteMapTilesConfirm = false var body: some View { VStack { @@ -40,8 +43,8 @@ struct AppSettings: View { .font(.footnote) } Label("Coordinate \(String(format: "%.5f", locationHelper.locationManager.location?.coordinate.latitude ?? 0)), \(String(format: "%.5f", locationHelper.locationManager.location?.coordinate.longitude ?? 0))", systemImage: "mappin") - .font(.footnote) - .textSelection(.enabled) + .font(.footnote) + .textSelection(.enabled) if locationHelper.locationManager.location?.verticalAccuracy ?? 0 > 0 { Label("Altitude \(altitiude.formatted())", systemImage: "mountain.2") .font(.footnote) @@ -55,56 +58,74 @@ struct AppSettings: View { .font(.footnote) } + } + Section(header: Text("Location Settings")) { + Toggle(isOn: $provideLocation) { - Label("provide.location", systemImage: "location.circle.fill") - .font(.footnote) } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) if UserDefaults.provideLocation { - - Picker("update.interval", selection: $provideLocationInterval) { - ForEach(LocationUpdateInterval.allCases) { lu in - Text(lu.description) + VStack { + Picker("update.interval", selection: $provideLocationInterval) { + ForEach(LocationUpdateInterval.allCases) { lu in + Text(lu.description) + } } + .pickerStyle(DefaultPickerStyle()) + .onChange(of: (provideLocationInterval)) { newProvideLocationInterval in + UserDefaults.provideLocationInterval = newProvideLocationInterval + } + Text("phone.gps.interval.description") + .font(.caption2) + .foregroundColor(.gray) } - .pickerStyle(DefaultPickerStyle()) - .onChange(of: (provideLocationInterval)) { newProvideLocationInterval in - UserDefaults.provideLocationInterval = newProvideLocationInterval - } - - Text("phone.gps.interval.description") - .font(.caption2) - .foregroundColor(.gray) } + } - TilesView() - } - HStack { - Button { - isPresentingCoreDataResetConfirm = true - } label: { - Label("clear.app.data", systemImage: "trash") - .foregroundColor(.red) - } - .buttonStyle(.bordered) - .buttonBorderShape(.capsule) - .controlSize(.large) - .padding() - .confirmationDialog( - "are.you.sure", - isPresented: $isPresentingCoreDataResetConfirm, - titleVisibility: .visible - ) { - Button("Erase all app data?", role: .destructive) { - bleManager.disconnectPeripheral() - clearCoreDataDatabase(context: context) - UserDefaults.standard.reset() - UserDefaults.standard.synchronize() + Section(header: Text("App Data")) { + Button { + isPresentingDeleteMapTilesConfirm = true + } label: { + Label("\("map.tiles.delete".localized) (\(totalDownloadedTileSize))", systemImage: "trash") + .foregroundColor(.red) + } + .confirmationDialog( + "are.you.sure", + isPresented: $isPresentingDeleteMapTilesConfirm, + titleVisibility: .visible + ) { + Button("Delete all map tiles?", role: .destructive) { + tileManager.removeAll() + totalDownloadedTileSize = tileManager.getAllDownloadedSize() + print("delete all tiles") + } + } + + Button { + isPresentingCoreDataResetConfirm = true + } label: { + Label("clear.app.data", systemImage: "trash") + .foregroundColor(.red) + } + .confirmationDialog( + "are.you.sure", + isPresented: $isPresentingCoreDataResetConfirm, + titleVisibility: .visible + ) { + Button("Erase all app data?", role: .destructive) { + bleManager.disconnectPeripheral() + clearCoreDataDatabase(context: context) + UserDefaults.standard.reset() + UserDefaults.standard.synchronize() + } } } } + .onAppear(perform: { + totalDownloadedTileSize = tileManager.getAllDownloadedSize() + }) } .navigationTitle("app.settings") .navigationBarItems(trailing: diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index 8f22be14..80820174 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -139,7 +139,7 @@ "map"="Mesh Map"; "map.type"="Default Type"; "map.centering"="Centering Mode"; -"map.tiles.delete"="Delete Cached Map Tiles"; +"map.tiles.delete"="Delete Map Tiles"; "map.recentering"="Automatic Re-centering"; "map.usertrackingmode"="User tracking mode"; "map.usertrackingmode.follow"="Follow"; @@ -207,7 +207,7 @@ "position"="Position"; "position.config"="Position Config"; "preferred.radio"="Preferred Radio"; -"provide.location"="Provide location to mesh"; +"provide.location"="Share location"; "radio.configuration"="Radio Configuration"; "range.test"="Range Test"; "range.test.config"="Range Test Config";