102 lines
4.2 KiB
Swift
102 lines
4.2 KiB
Swift
//
|
||
// SettingsScreen.swift
|
||
// AutoCat
|
||
//
|
||
// Created by Selim Mustafaev on 17.08.2024.
|
||
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
||
//
|
||
|
||
import SwiftUI
|
||
import AutoCatCore
|
||
|
||
struct SettingsScreen: View {
|
||
|
||
@State var viewModel: SettingsViewModel
|
||
@State var googleSheetOpened = false
|
||
@State var googleLoginSheetOpened = false
|
||
|
||
init() {
|
||
self.viewModel = SettingsViewModel(
|
||
settingsService: ServiceContainer.shared.resolve(SettingsServiceProtocol.self)
|
||
)
|
||
}
|
||
|
||
var body: some View {
|
||
NavigationStack {
|
||
Form {
|
||
Section {
|
||
TextRowView(title: "Version", value: Bundle.main.fullVersion)
|
||
}
|
||
|
||
Section("Profile") {
|
||
SimpleTextRowView(title: "AutoCat Account", value: viewModel.autocatEmail)
|
||
SimpleTextRowView(title: "Google",
|
||
value: viewModel.googleEmail ?? "Log In",
|
||
showArrow: true)
|
||
.onTapGesture {
|
||
if viewModel.googleAuthorized {
|
||
googleSheetOpened = true
|
||
} else {
|
||
googleLoginSheetOpened = true
|
||
}
|
||
}
|
||
|
||
if viewModel.canSignOut {
|
||
Button("Sign Out", action: viewModel.signOut)
|
||
}
|
||
}
|
||
|
||
Section {
|
||
Picker("Server", selection: $viewModel.settingService.backend) {
|
||
ForEach(Constants.Backend.allCases, id: \.self) { backend in
|
||
Text(backend.name)
|
||
}
|
||
}
|
||
}
|
||
|
||
Section("Plate number recognition") {
|
||
ToggleRowView(title: "Alternative order",
|
||
description: "Recognize plate numbers in alternative form. For example 'ЕВА 123 777' instead of 'Е123ВА 777'",
|
||
toggle: $viewModel.settingService.recognizeAlternativeOrder)
|
||
ToggleRowView(title: "Shortened numbers",
|
||
description: "If enabled, app will try to recognize shortened plate numbers (without region) and add default region",
|
||
toggle: $viewModel.settingService.recognizeShortenedNumbers)
|
||
if viewModel.settingService.recognizeShortenedNumbers {
|
||
LabeledContent("Default region") {
|
||
TextField("", text: $viewModel.settingService.defaultRegion)
|
||
.frame(width: 50)
|
||
.multilineTextAlignment(.trailing)
|
||
}
|
||
}
|
||
ToggleRowView(title: "Beep before record",
|
||
description: "When enabled, you will hear short sound before starting audio recording. This will only work when audio record is started via Siri",
|
||
toggle: $viewModel.settingService.recordBeep)
|
||
}
|
||
|
||
Section("Debug") {
|
||
ToggleRowView(title: "Show debug info",
|
||
description: nil,
|
||
toggle: $viewModel.settingService.showDebugInfo)
|
||
}
|
||
}
|
||
.formStyle(.grouped)
|
||
.navigationTitle("Settings")
|
||
.titleModeInline()
|
||
.confirmationDialog(viewModel.googleUsername ?? "",
|
||
isPresented: $googleSheetOpened,
|
||
titleVisibility: .visible) {
|
||
Button("Sign Out", role: .destructive) {
|
||
viewModel.googleSignout()
|
||
}
|
||
} message: {
|
||
if let email = viewModel.googleEmail {
|
||
Text("You are currently signed in with email \(email). It will help to gather more data about vehicles.")
|
||
}
|
||
}
|
||
.sheet(isPresented: $googleLoginSheetOpened) {
|
||
GoogleAuthScreen()
|
||
}
|
||
}
|
||
}
|
||
}
|