Meshtastic-Apple/MeshtasticClient/Views/Settings/AppSettings.swift

210 lines
5.2 KiB
Swift
Raw Normal View History

import Foundation
import Combine
import SwiftUI
import SwiftProtobuf
import MapKit
enum KeyboardType: Int, CaseIterable, Identifiable {
2021-11-29 15:59:06 -08:00
case defaultKeyboard = 0
case asciiCapable = 1
case twitter = 9
case emailAddress = 7
case numbersAndPunctuation = 2
2021-11-29 15:59:06 -08:00
var id: Int { self.rawValue }
var description: String {
get {
switch self {
2021-11-29 16:51:59 -08:00
case .defaultKeyboard:
return "Default"
case .asciiCapable:
return "ASCII Capable"
case .twitter:
return "Twitter"
case .emailAddress:
return "Email Address"
case .numbersAndPunctuation:
return "Numbers and Punctuation"
}
}
}
}
enum MeshMapType: String, CaseIterable, Identifiable {
2021-12-25 23:48:12 -08:00
case satellite = "satellite"
case hybrid = "hybrid"
case standard = "standard"
2021-12-25 23:48:12 -08:00
var id: String { self.rawValue }
2021-12-25 23:48:12 -08:00
var description: String {
get {
switch self {
case .satellite:
return "Satellite"
case .standard:
return "Standard"
case .hybrid:
return "Hybrid"
}
}
}
}
2022-03-04 03:54:25 -08:00
enum LocationUpdateInterval: Int, CaseIterable, Identifiable {
case oneMinute = 60
case fiveMinutes = 300
case tenMinutes = 600
case fifteenMinutes = 900
var id: Int { self.rawValue }
var description: String {
get {
switch self {
case .oneMinute:
return "One Minute"
case .fiveMinutes:
return "Five Minutes"
case .tenMinutes:
return "Ten Minutes"
case .fifteenMinutes:
return "Fifteen Minutes"
}
}
}
}
struct AppSettings: View {
2021-11-29 15:59:06 -08:00
@Environment(\.managedObjectContext) var context
2021-10-17 15:08:12 -07:00
@EnvironmentObject var bleManager: BLEManager
@EnvironmentObject var userSettings: UserSettings
2021-11-29 15:59:06 -08:00
@State private var preferredDeviceConnected = false
2021-11-29 15:59:06 -08:00
var perferredPeripheral: String {
UserDefaults.standard.object(forKey: "preferredPeripheralName") as? String ?? ""
}
2021-11-29 15:59:06 -08:00
var body: some View {
2021-10-17 15:08:12 -07:00
NavigationView {
2021-11-29 15:59:06 -08:00
GeometryReader { _ in
Form {
Section(header: Text("USER DETAILS")) {
2021-11-29 15:59:06 -08:00
2022-02-23 23:05:47 -10:00
HStack {
Label("Name", systemImage: "person.crop.rectangle.fill")
TextField("Username", text: $userSettings.meshtasticUsername)
.foregroundColor(.gray)
}
.keyboardType(.asciiCapable)
.disableAutocorrection(true)
.listRowSeparator(.visible)
2022-03-04 03:54:25 -08:00
HStack {
Label("Radio", systemImage: "flipphone")
Text(userSettings.preferredPeripheralName)
2021-10-17 15:08:12 -07:00
.foregroundColor(.gray)
2022-03-04 03:54:25 -08:00
}
Text("This option is set via the preferred radio toggle for the connected device on the bluetooth tab.")
.font(.caption)
.listRowSeparator(.hidden)
2022-03-04 03:54:25 -08:00
Text("The preferred radio will automatically reconnect if it becomes disconnected and is still within range.")
.font(.caption2)
.foregroundColor(.gray)
2021-11-29 15:59:06 -08:00
}
2022-03-04 03:54:25 -08:00
Section(header: Text("LOCATION OPTIONS")) {
Toggle(isOn: $userSettings.provideLocation) {
Label("Provide location to mesh", systemImage: "location.circle.fill")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
if userSettings.provideLocation {
Picker(" Update Interval", selection: $userSettings.provideLocationInterval) {
ForEach(LocationUpdateInterval.allCases) { lu in
Text(lu.description)
}
}
.pickerStyle(DefaultPickerStyle())
Text("How frequently your phone will send your location to the device, location updates to the mesh are managed by the device.")
.font(.caption)
.listRowSeparator(.visible)
}
}
2022-04-11 15:58:11 -07:00
Section(header: Text("MESH OPTIONS")) {
NavigationLink(destination: ShareChannel()) {
Text("Share Your Channel vis QR Code")
}
}
Section(header: Text("MESSAGING OPTIONS")) {
Picker("Keyboard Type", selection: $userSettings.keyboardType) {
ForEach(KeyboardType.allCases) { kb in
Text(kb.description)
}
}
.pickerStyle(DefaultPickerStyle())
}
2022-01-02 23:28:51 -08:00
Section(header: Text("MAP OPTIONS")) {
Picker("Map Type", selection: $userSettings.meshMapType) {
ForEach(MeshMapType.allCases) { map in
Text(map.description)
}
}
.pickerStyle(DefaultPickerStyle())
// TextField("Custom Tile Server", text: $userSettings.meshMapCustomTileServer)
2022-01-02 23:28:51 -08:00
}
2022-02-23 23:05:47 -10:00
Section(header: Text("DEBUG OPTIONS")) {
Toggle(isOn: $userSettings.meshActivityLog) {
Label("Log all Mesh activity", systemImage: "network")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
2022-03-04 03:54:25 -08:00
if userSettings.meshActivityLog {
NavigationLink(destination: MeshLog()) {
Text("View Mesh Log")
}
.listRowSeparator(.visible)
}
}
}
}
.navigationTitle("App Settings")
.navigationBarItems(trailing:
2021-11-29 15:59:06 -08:00
ZStack {
2021-12-25 23:48:12 -08:00
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.lastFourCode : "????")
})
2021-12-25 23:48:12 -08:00
.onAppear {
self.bleManager.context = context
}
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
struct AppSettings_Previews: PreviewProvider {
2021-12-25 23:48:12 -08:00
static var previews: some View {
Group {
AppSettings()
}
}
}