WIP - a lot of uncommitted work

This commit is contained in:
Trey t
2022-01-15 12:03:31 -06:00
parent 80690e4a8c
commit 64dd1855ac
31 changed files with 1024 additions and 154 deletions

View File

@@ -10,47 +10,32 @@ import SwiftUI
struct SettingsView: View {
@Environment(\.dismiss) var dismiss
@State private var currentDate = Date() {
@AppStorage("notificationDate") private var notificationDate = Date() {
didSet {
if self.showReminder {
LocalNotification.scheduleReminder(atTime: self.currentDate)
LocalNotification.scheduleReminder(atTime: self.notificationDate)
}
}
}
@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()
}
}
}
@AppStorage("showReminder") private var showReminder: Bool = false
var body: some View { ZStack {
Color(UIColor.secondarySystemBackground)
VStack {
closeButtonView
.padding()
notificationCell
randomShitCell
addTestDataCell
clearDB
whyBackgroundMode
Spacer()
var body: some View {
ZStack {
Color(UIColor.secondarySystemBackground)
VStack {
closeButtonView
.padding()
notificationCell
randomShitCell
addTestDataCell
clearDB
whyBackgroundMode
Spacer()
}
.padding()
}
.padding()
}
}
private var closeButtonView: some View {
@@ -71,8 +56,14 @@ struct SettingsView: View {
Color(UIColor.systemBackground)
VStack {
Toggle("Would you like to be reminded?", isOn: $showReminder)
.onChange(of: showReminder, perform: { value in
self.maybeNotificaiotns(areEnabled: value)
})
.padding()
DatePicker("", selection: $currentDate, displayedComponents: .hourAndMinute)
DatePicker("", selection: $notificationDate, displayedComponents: .hourAndMinute)
.onChange(of: notificationDate, perform: { value in
self.updateNotificationTimes(toDate: value)
})
.disabled(showReminder == false)
.padding()
}
@@ -85,7 +76,11 @@ struct SettingsView: View {
ZStack {
Color(UIColor.systemBackground)
VStack {
Text("random shit")
Button(action: {
}, label: {
Text("Special thanks to")
})
.padding()
}
}
@@ -130,6 +125,29 @@ struct SettingsView: View {
.fixedSize(horizontal: false, vertical: true)
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
}
private func updateNotificationTimes(toDate date: Date) {
LocalNotification.removeNotificaiton()
LocalNotification.scheduleReminder(atTime: date)
}
private func maybeNotificaiotns(areEnabled: Bool) {
if areEnabled {
LocalNotification.testIfEnabled(completion: { result in
switch result{
case .success(_):
LocalNotification.scheduleReminder(atTime: self.notificationDate)
case .failure(let error):
print(error)
// show error
break
}
})
} else {
LocalNotification.removeNotificaiton()
}
}
}
struct SettingsView_Previews: PreviewProvider {