2020-12-28 19:09:28 +00:00
|
|
|
//
|
|
|
|
// SettingsMain.swift
|
|
|
|
// DHBW-Service
|
|
|
|
//
|
|
|
|
// Created by Patrick Müller on 28.12.20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SettingsMain: View {
|
2020-12-28 22:12:09 +00:00
|
|
|
@EnvironmentObject var settings: LocalSettings
|
|
|
|
@State private var showLogoutConfirmationAlert = false
|
|
|
|
|
2020-12-28 19:09:28 +00:00
|
|
|
var body: some View {
|
2020-12-28 22:12:09 +00:00
|
|
|
NavigationView {
|
|
|
|
List {
|
|
|
|
Section(header: Text("other".localized(tableName: "General", plural: false))) {
|
|
|
|
NavigationLink(
|
|
|
|
destination: SettingsAcknowledgements(),
|
|
|
|
label: {
|
|
|
|
Text("Acknowledgements")
|
|
|
|
})
|
2021-04-07 11:26:37 +00:00
|
|
|
NavigationLink(
|
|
|
|
destination: SettingsPushNotifications(),
|
|
|
|
label: {
|
|
|
|
Text("Push Notifications")
|
|
|
|
})
|
2020-12-28 22:12:09 +00:00
|
|
|
Button(action: {
|
|
|
|
self.showLogoutConfirmationAlert = true
|
|
|
|
}, label: {
|
|
|
|
Text("logoutClearData".localized(tableName: "General", plural: false))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationTitle("settings".localized(tableName: "General", plural: false))
|
|
|
|
.listStyle(GroupedListStyle())
|
|
|
|
}
|
2021-02-07 14:17:29 +00:00
|
|
|
.navigationViewStyle(StackNavigationViewStyle())
|
2020-12-28 22:12:09 +00:00
|
|
|
.alert(isPresented: $showLogoutConfirmationAlert, content: {
|
|
|
|
Alert(
|
|
|
|
title: Text("logout".localized(tableName: "General", plural: false)),
|
|
|
|
message: Text("confirmLogoutMessage".localized(tableName: "General", plural: false)),
|
|
|
|
primaryButton: .cancel(),
|
|
|
|
secondaryButton: .destructive(Text("Ok")){
|
|
|
|
self.logoutAndClearData()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension SettingsMain {
|
|
|
|
private func logoutAndClearData() {
|
|
|
|
// TODO: Adjust before release!
|
|
|
|
UtilityFunctions.deleteAllData()
|
|
|
|
self.settings.isFirstOpening = true
|
2020-12-28 19:09:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SettingsMain_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
SettingsMain()
|
|
|
|
.preferredColorScheme(.dark)
|
2021-02-07 14:51:01 +00:00
|
|
|
.previewDevice("iPhone 12")
|
2020-12-28 19:09:28 +00:00
|
|
|
.environmentObject(getFirstOpening())
|
|
|
|
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func getFirstOpening() -> LocalSettings {
|
|
|
|
let settings = LocalSettings();
|
|
|
|
settings.isFirstOpening = false;
|
|
|
|
return settings
|
|
|
|
}
|
|
|
|
}
|