143 lines
3.9 KiB
Swift
143 lines
3.9 KiB
Swift
//
|
|
// SettingsView.swift
|
|
// Feels
|
|
//
|
|
// Created by Trey Tartt on 1/8/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct SettingsView: View {
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
@State private var currentDate = Date() {
|
|
didSet {
|
|
if self.showReminder {
|
|
LocalNotification.scheduleReminder(atTime: self.currentDate)
|
|
}
|
|
}
|
|
}
|
|
|
|
@State private var showReminder: Bool = false {
|
|
didSet {
|
|
if self.showReminder {
|
|
LocalNotification.testIfEnabled(completion: { result in
|
|
switch result{
|
|
case .success(_):
|
|
LocalNotification.scheduleReminder(atTime: self.currentDate)
|
|
case .failure(_):
|
|
// show error
|
|
break
|
|
}
|
|
})
|
|
} else {
|
|
LocalNotification.removeNotificaiton()
|
|
}
|
|
}
|
|
}
|
|
|
|
var body: some View { ZStack {
|
|
Color(UIColor.secondarySystemBackground)
|
|
|
|
VStack {
|
|
closeButtonView
|
|
.padding()
|
|
notificationCell
|
|
randomShitCell
|
|
addTestDataCell
|
|
clearDB
|
|
whyBackgroundMode
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
}
|
|
}
|
|
|
|
private var closeButtonView: some View {
|
|
HStack{
|
|
Spacer()
|
|
Button(action: {
|
|
dismiss()
|
|
}, label: {
|
|
Text("Exit")
|
|
.font(.body)
|
|
.foregroundColor(Color(UIColor.systemBlue))
|
|
})
|
|
}
|
|
}
|
|
|
|
private var notificationCell: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
VStack {
|
|
Toggle("Would you like to be reminded?", isOn: $showReminder)
|
|
.padding()
|
|
DatePicker("", selection: $currentDate, displayedComponents: .hourAndMinute)
|
|
.disabled(showReminder == false)
|
|
.padding()
|
|
}
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var randomShitCell: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
VStack {
|
|
Text("random shit")
|
|
.padding()
|
|
}
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var addTestDataCell: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
Button(action: {
|
|
PersistenceController.shared.populateTestData()
|
|
}, label: {
|
|
Text("Add test data")
|
|
})
|
|
.padding()
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var clearDB: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
Button(action: {
|
|
PersistenceController.shared.clearDB()
|
|
}, label: {
|
|
Text("Clear DB")
|
|
})
|
|
.padding()
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var whyBackgroundMode: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
Text("we do bg mode b/c we can")
|
|
.padding()
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
}
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SettingsView()
|
|
|
|
SettingsView()
|
|
.preferredColorScheme(.dark)
|
|
}
|
|
}
|