From 355e1126a2ac5e6518163a925bd9edc2291ef44d Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 2 Jul 2022 23:45:33 -0700 Subject: [PATCH] Clean up log buttons, select default tab on settings delete color array for deleted teams feature --- Meshtastic/Helpers/Extensions.swift | 38 -------------------- Meshtastic/Model/UserSettings.swift | 7 ---- Meshtastic/Views/Settings/MeshLog.swift | 44 +++++++++++------------- Meshtastic/Views/Settings/Settings.swift | 16 ++++++++- 4 files changed, 36 insertions(+), 69 deletions(-) diff --git a/Meshtastic/Helpers/Extensions.swift b/Meshtastic/Helpers/Extensions.swift index 8dab6f54..52bb1987 100644 --- a/Meshtastic/Helpers/Extensions.swift +++ b/Meshtastic/Helpers/Extensions.swift @@ -57,41 +57,3 @@ extension String { } } - -typealias NodeColor = Int - -extension NodeColor { - // a color to represent an individual meshtastic device - var color: Color { - switch self { - case 0: - return Color(.red) - case 1: - return Color(.blue) - case 2: - return Color(.yellow) - case 3: - return Color(.green) - case 4: - return Color(.purple) - case 5: - return Color(.systemPink) - case 6: - return Color(.systemTeal) - case 7: - return Color(.black) - case 8: - return Color(.gray) - case 9: - return Color(.brown) - case 10: - return Color(.magenta) - case 11: - return Color(.orange) - case 12: - return Color(.cyan) - default: - return Color(.blue) - } - } -} diff --git a/Meshtastic/Model/UserSettings.swift b/Meshtastic/Model/UserSettings.swift index 99d92220..c1ef080d 100644 --- a/Meshtastic/Model/UserSettings.swift +++ b/Meshtastic/Model/UserSettings.swift @@ -38,12 +38,6 @@ class UserSettings: ObservableObject { UserDefaults.standard.set(keyboardType, forKey: "keyboardType") } } - @Published var meshActivityLog: Bool { - didSet { - UserDefaults.standard.set(meshActivityLog, forKey: "meshActivityLog") - } - } - @Published var meshMapType: String { didSet { UserDefaults.standard.set(meshMapType, forKey: "meshMapType") @@ -63,7 +57,6 @@ class UserSettings: ObservableObject { 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.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? true self.meshMapType = UserDefaults.standard.string(forKey: "meshMapType") ?? "hybrid" self.meshMapCustomTileServer = UserDefaults.standard.string(forKey: "meshMapCustomTileServer") ?? "" } diff --git a/Meshtastic/Views/Settings/MeshLog.swift b/Meshtastic/Views/Settings/MeshLog.swift index b8eee16b..f1b9a5f7 100644 --- a/Meshtastic/Views/Settings/MeshLog.swift +++ b/Meshtastic/Views/Settings/MeshLog.swift @@ -46,7 +46,9 @@ struct MeshLog: View { HStack(alignment: .center) { Spacer() - Button(action: { + + Button(role: .destructive) { + let text = "" do { try text.write(to: logFile!, atomically: false, encoding: .utf8) @@ -54,35 +56,31 @@ struct MeshLog: View { } catch { print(error) } - - }) { - Image(systemName: "trash.circle.fill") - .symbolRenderingMode(.hierarchical) - .imageScale(.large).foregroundColor(.accentColor) - Text("Clear Log").font(.caption) - .font(.caption) - .foregroundColor(.accentColor) + + } label: { + + Label("Clear Log", systemImage: "trash.fill") } + .buttonStyle(.bordered) + .buttonBorderShape(.capsule) + .controlSize(.large) .padding() - .background(Color(.systemGray6)) - .clipShape(Capsule()) Spacer() - - Button(action: { + + Button { + isExporting = true - }) { - Image(systemName: "arrow.down.circle.fill") - .symbolRenderingMode(.hierarchical) - .imageScale(.large).foregroundColor(.accentColor) - Text("Download Log") - .font(.caption) - .foregroundColor(.accentColor) + + } label: { + + Label("Download Log", systemImage: "arrow.down.circle.fill") } + .buttonStyle(.bordered) + .buttonBorderShape(.capsule) + .controlSize(.large) .padding() - .background(Color(.systemGray6)) - .clipShape(Capsule()) - + Spacer() } diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index 43f4341b..76614ed6 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -19,13 +19,15 @@ struct Settings: View { private var nodes: FetchedResults + @State private var selection: String? = "" + var body: some View { NavigationView { List { let connectedNodeNum = bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral.num : 0 - NavigationLink { + NavigationLink(tag: String("0"), selection: $selection) { AppSettings() } label: { @@ -197,6 +199,18 @@ struct Settings: View { // WiFi Config - Would break connection to device // MQTT Config - Part of WiFi } + .onAppear { + + self.bleManager.context = context + self.bleManager.userSettings = userSettings + + if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { + + if nodes.count > 0 { + selection = "0" + } + } + } .listStyle(GroupedListStyle()) .navigationTitle("Settings") }