AutoCat/AutoCat/Screens/SettingsScreen/SettingsScreen.swift

97 lines
3.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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
var body: some View {
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 {
viewModel.googleSignIn()
}
}
if viewModel.canSignOut {
Button("Sign Out", action: viewModel.signOut)
}
}
Section {
Picker("Server", selection: $viewModel.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.recognizeAlternativeOrder)
ToggleRowView(title: "Shortened numbers",
description: "If enabled, app will try to recognize shortened plate numbers (without region) and add default region",
toggle: $viewModel.recognizeShortenedNumbers)
if viewModel.recognizeShortenedNumbers {
LabeledContent("Default region") {
TextField("", text: $viewModel.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.recordBeep)
}
Section("Debug") {
ToggleRowView(title: "Show debug info",
description: nil,
toggle: $viewModel.showDebugInfo)
}
}
.navigationTitle("Settings")
.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.")
}
}
}
}
#if DEBUG
#Preview {
SettingsScreen(viewModel: .init(settingsService: MockSettingsServiceProtocol()))
}
#endif