252 lines
8.0 KiB
Swift
252 lines
8.0 KiB
Swift
//
|
|
// SettingsView.swift
|
|
// Feels
|
|
//
|
|
// Created by Trey Tartt on 1/8/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CloudKitSyncMonitor
|
|
|
|
struct SettingsView: View {
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
let editedDataClosure: (() -> Void)
|
|
let updateBoardingDataClosure: ((OnboardingData) -> Void)
|
|
|
|
@State private var showOnboarding = false
|
|
|
|
@State private var showSpecialThanks = false
|
|
@State private var showWhyBGMode = false
|
|
@ObservedObject var syncMonitor = SyncMonitor.shared
|
|
|
|
@AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue) private var useCloudKit = false
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Color(UIColor.secondarySystemBackground)
|
|
|
|
VStack {
|
|
closeButtonView
|
|
.padding()
|
|
cloudKitEnable
|
|
addTestDataCell
|
|
clearDB
|
|
changeIcon
|
|
showOnboardingButton
|
|
whyBackgroundMode
|
|
specialThanksCell
|
|
|
|
if useCloudKit {
|
|
cloudKitStatus
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.padding()
|
|
|
|
}.sheet(isPresented: $showOnboarding) {
|
|
OnboardingMain(onboardingData: UserDefaultsStore.getOnboarding(),
|
|
updateBoardingDataClosure: { onboardingData in
|
|
updateBoardingDataClosure(onboardingData)
|
|
showOnboarding = false
|
|
})
|
|
}
|
|
.ignoresSafeArea()
|
|
}
|
|
|
|
private var closeButtonView: some View {
|
|
HStack{
|
|
Spacer()
|
|
Button(action: {
|
|
dismiss()
|
|
}, label: {
|
|
Text(String(localized: "settings_view_exit"))
|
|
.font(.body)
|
|
.foregroundColor(Color(UIColor.systemBlue))
|
|
})
|
|
}
|
|
}
|
|
|
|
private var specialThanksCell: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
VStack {
|
|
Button(action: {
|
|
withAnimation{
|
|
showSpecialThanks.toggle()
|
|
}
|
|
}, label: {
|
|
Text(String(localized: "settings_view_special_thanks_to_title"))
|
|
})
|
|
.padding()
|
|
|
|
if showSpecialThanks {
|
|
Text(String(localized: "settings_view_special_thanks_to_body"))
|
|
.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()
|
|
editedDataClosure()
|
|
}, 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()
|
|
editedDataClosure()
|
|
}, 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)
|
|
VStack {
|
|
Button(action: {
|
|
withAnimation{
|
|
showWhyBGMode.toggle()
|
|
}
|
|
}, label: {
|
|
Text(String(localized: "settings_view_why_bg_mode_title"))
|
|
})
|
|
.padding()
|
|
if showWhyBGMode {
|
|
Text(String(localized: "settings_view_why_bg_mode_body"))
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
let iconSets: [(String,String)] = [
|
|
("PurpleFeelsAppIcon", "PurpleAppIcon"),
|
|
("RedFeelsAppIcon", "RedAppIcon")
|
|
]
|
|
|
|
private var changeIcon: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
VStack {
|
|
Text(String(localized: "settings_view_change_icon"))
|
|
HStack {
|
|
|
|
Button(action: {
|
|
UIApplication.shared.setAlternateIconName(nil)
|
|
}, label: {
|
|
Image("FeelsAppIcon", bundle: .main)
|
|
.resizable()
|
|
.frame(width: 50, height:50)
|
|
.cornerRadius(10)
|
|
})
|
|
.padding()
|
|
|
|
ForEach(iconSets, id: \.self.0){ iconSet in
|
|
Button(action: {
|
|
UIApplication.shared.setAlternateIconName(iconSet.1) { (error) in
|
|
// FIXME: Handle error
|
|
}
|
|
}, label: {
|
|
Image(iconSet.0, bundle: .main)
|
|
.resizable()
|
|
.frame(width: 50, height:50)
|
|
.cornerRadius(10)
|
|
})
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var showOnboardingButton: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
Button(action: {
|
|
showOnboarding.toggle()
|
|
}, label: {
|
|
Text(String(localized: "settings_view_show_onboarding"))
|
|
})
|
|
.padding()
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var cloudKitEnable: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
VStack {
|
|
Toggle(String(localized: "settings_use_cloudkit_title"),
|
|
isOn: $useCloudKit)
|
|
.onChange(of: useCloudKit) { value in
|
|
print(value)
|
|
PersistenceController.shared.switchContainer()
|
|
}
|
|
.padding()
|
|
Text(String(localized: "settings_use_cloudkit_body"))
|
|
}
|
|
.padding(.bottom)
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
|
|
private var cloudKitStatus: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
VStack {
|
|
Image(systemName: syncMonitor.syncStateSummary.symbolName)
|
|
.foregroundColor(syncMonitor.syncStateSummary.symbolColor)
|
|
Text( syncMonitor.syncStateSummary.isBroken ? "cloudkit is broken" : "cloudkit is good")
|
|
}
|
|
.padding()
|
|
}
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
}
|
|
}
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SettingsView(editedDataClosure: {
|
|
|
|
}, updateBoardingDataClosure: { _ in
|
|
|
|
})
|
|
|
|
SettingsView(editedDataClosure: {
|
|
|
|
}, updateBoardingDataClosure: { _ in
|
|
|
|
})
|
|
.preferredColorScheme(.dark)
|
|
}
|
|
}
|