This commit is contained in:
Trey t
2022-12-23 09:43:48 -06:00
parent 49e3812659
commit 488832b777
9 changed files with 195 additions and 167 deletions

View File

@@ -19,7 +19,7 @@ struct SettingsView: View {
@State private var importContent = ""
@State private var showOnboarding = false
@State private var showSpecialThanks = false
@State private var showWhyBGMode = false
@ObservedObject var syncMonitor = SyncMonitor.shared
@@ -29,7 +29,7 @@ struct SettingsView: View {
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor
@AppStorage(UserDefaultsStore.Keys.firstLaunchDate.rawValue, store: GroupUserDefaults.groupDefaults) private var firstLaunchDate = Date()
var body: some View {
ScrollView {
VStack {
@@ -37,24 +37,25 @@ struct SettingsView: View {
closeButtonView
.padding()
// cloudKitEnable
// cloudKitEnable
subscriptionInfoView
canDelete
showOnboardingButton
specialThanksCell
// specialThanksCell
}
#if DEBUG
Group {
Divider()
Text("Test builds only")
addTestDataCell
clearDB
// randomIcons
// randomIcons
if useCloudKit {
cloudKitStatus
}
// fixWeekday
// fixWeekday
exportData
importData
editFirstLaunchDatePast
@@ -62,7 +63,7 @@ struct SettingsView: View {
Divider()
}
Spacer()
#endif
Text("\(Bundle.main.appName) v \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))")
.font(.body)
}
@@ -126,7 +127,7 @@ struct SettingsView: View {
let localTime = dateFormatter.date(from: columns[3])!
moodEntry.weekDay = Int16(Calendar.current.component(.weekday, from: localTime))
// let _ = print("import info: ", columns[3], dateFormatter.date(from: columns[3]), localTime, Int16(Calendar.current.component(.weekday, from: localTime)))
// let _ = print("import info: ", columns[3], dateFormatter.date(from: columns[3]), localTime, Int16(Calendar.current.component(.weekday, from: localTime)))
try! PersistenceController.shared.viewContext.save()
}
PersistenceController.shared.saveAndRunDataListerners()
@@ -184,7 +185,7 @@ struct SettingsView: View {
Text(String(localized: "settings_view_special_thanks_to_title"))
.foregroundColor(textColor)
})
.padding()
.padding()
if showSpecialThanks {
Divider()
@@ -213,7 +214,7 @@ struct SettingsView: View {
Text("Add test data")
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
@@ -263,7 +264,7 @@ struct SettingsView: View {
Text("Clear DB")
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
@@ -278,7 +279,7 @@ struct SettingsView: View {
Text("Fix Weekday")
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
@@ -296,7 +297,7 @@ struct SettingsView: View {
Text(String(localized: "settings_view_why_bg_mode_title"))
.foregroundColor(textColor)
})
.padding()
.padding()
if showWhyBGMode {
Text(String(localized: "settings_view_why_bg_mode_body"))
.foregroundColor(textColor)
@@ -318,7 +319,7 @@ struct SettingsView: View {
Text(String(localized: "settings_view_show_onboarding"))
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
@@ -332,10 +333,10 @@ struct SettingsView: View {
Text(String(localized: "settings_use_cloudkit_title"))
.foregroundColor(textColor)
})
.onChange(of: useCloudKit) { newValue in
EventLogger.log(event: "toggle_use_cloudkit", withData: ["value": newValue])
}
.padding()
.onChange(of: useCloudKit) { newValue in
EventLogger.log(event: "toggle_use_cloudkit", withData: ["value": newValue])
}
.padding()
Text(String(localized: "settings_use_cloudkit_body"))
.foregroundColor(textColor)
}
@@ -366,11 +367,11 @@ struct SettingsView: View {
VStack {
Toggle(String(localized: "settings_use_delete_enable"),
isOn: $deleteEnabled)
.onChange(of: deleteEnabled) { newValue in
EventLogger.log(event: "toggle_can_delete", withData: ["value": newValue])
}
.foregroundColor(textColor)
.padding()
.onChange(of: deleteEnabled) { newValue in
EventLogger.log(event: "toggle_can_delete", withData: ["value": newValue])
}
.foregroundColor(textColor)
.padding()
}
}
.fixedSize(horizontal: false, vertical: true)
@@ -387,12 +388,12 @@ struct SettingsView: View {
Text("Export")
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var importData: some View {
ZStack {
theme.currentTheme.secondaryBGColor
@@ -403,7 +404,7 @@ struct SettingsView: View {
Text("Import")
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
@@ -414,17 +415,17 @@ struct SettingsView: View {
theme.currentTheme.secondaryBGColor
Button(action: {
var iconViews = [UIImage]()
// for _ in 0...300 {
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color.random(),
// bgOverlayColor: Color.random(),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color.random())
// ).asImage(size: CGSize(width: 1024, height: 1024)))
// }
// for _ in 0...300 {
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color.random(),
// bgOverlayColor: Color.random(),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color.random())
// ).asImage(size: CGSize(width: 1024, height: 1024)))
// }
iconViews.append(
IconView(iconViewModel: IconViewModel(
@@ -433,7 +434,7 @@ struct SettingsView: View {
bgOverlayColor: IconViewModel.great.bgOverlayColor,
centerImage: MoodImages.FontAwesome.icon(forMood: .great),
innerColor: IconViewModel.great.innerColor)
).asImage(size: CGSize(width: 1024, height: 1024))
).asImage(size: CGSize(width: 1024, height: 1024))
)
iconViews.append(
@@ -443,7 +444,7 @@ struct SettingsView: View {
bgOverlayColor: IconViewModel.good.bgOverlayColor,
centerImage: MoodImages.FontAwesome.icon(forMood: .great),
innerColor: IconViewModel.good.innerColor)
).asImage(size: CGSize(width: 1024, height: 1024))
).asImage(size: CGSize(width: 1024, height: 1024))
)
iconViews.append(
@@ -453,7 +454,7 @@ struct SettingsView: View {
bgOverlayColor: IconViewModel.average.bgOverlayColor,
centerImage: MoodImages.FontAwesome.icon(forMood: .great),
innerColor: IconViewModel.average.innerColor)
).asImage(size: CGSize(width: 1024, height: 1024))
).asImage(size: CGSize(width: 1024, height: 1024))
)
iconViews.append(
@@ -463,7 +464,7 @@ struct SettingsView: View {
bgOverlayColor: IconViewModel.bad.bgOverlayColor,
centerImage: MoodImages.FontAwesome.icon(forMood: .great),
innerColor: IconViewModel.bad.innerColor)
).asImage(size: CGSize(width: 1024, height: 1024))
).asImage(size: CGSize(width: 1024, height: 1024))
)
iconViews.append(
@@ -473,49 +474,49 @@ struct SettingsView: View {
bgOverlayColor: IconViewModel.horrible.bgOverlayColor,
centerImage: MoodImages.FontAwesome.icon(forMood: .great),
innerColor: IconViewModel.horrible.innerColor)
).asImage(size: CGSize(width: 1024, height: 1024))
).asImage(size: CGSize(width: 1024, height: 1024))
)
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "EF0CF3"),
// bgOverlayColor: Color(hex: "EF0CF3").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "EF0CF3"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "1AE5D6"),
// bgOverlayColor: Color(hex: "1AE5D6").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "1AE5D6"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "633EC1"),
// bgOverlayColor: Color(hex: "633EC1").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "633EC1"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "10F30C"),
// bgOverlayColor: Color(hex: "10F30C").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "10F30C"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "EF0CF3"),
// bgOverlayColor: Color(hex: "EF0CF3").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "EF0CF3"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "1AE5D6"),
// bgOverlayColor: Color(hex: "1AE5D6").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "1AE5D6"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "633EC1"),
// bgOverlayColor: Color(hex: "633EC1").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "633EC1"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
//
// iconViews.append(
// IconView(iconViewModel: IconViewModel(
// backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
// bgColor: Color(hex: "10F30C"),
// bgOverlayColor: Color(hex: "10F30C").darker(by: 40),
// centerImage: MoodImages.FontAwesome.icon(forMood: .great),
// innerColor: Color(hex: "10F30C"))
// ).asImage(size: CGSize(width: 1024, height: 1024))
// )
for (idx, image) in iconViews.enumerated() {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
@@ -534,7 +535,7 @@ struct SettingsView: View {
Text("Create random icons")
.foregroundColor(textColor)
})
.padding()
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
@@ -555,10 +556,10 @@ struct SettingsView: View {
struct TextFile: FileDocument {
// tell the system we support only plain text
static var readableContentTypes = [UTType.plainText]
// by default our document is empty
var text = ""
// a simple initializer that creates new, empty documents
init() {
let entries = PersistenceController.shared.getData(startDate: Date(timeIntervalSince1970: 0),
@@ -576,19 +577,19 @@ struct TextFile: FileDocument {
let weekDay = entry.weekDay
let dataString = "\(canDelete),\(canEdit),\(entryType),\(String(describing: forDate)),\(moodValue),\(String(describing:timestamp)),\(weekDay)\n"
// print("DATA: \(dataString)")
// print("DATA: \(dataString)")
csvString = csvString.appending(dataString)
}
text = csvString
}
// this initializer loads data that has been saved previously
init(configuration: ReadConfiguration) throws {
if let data = configuration.file.regularFileContents {
text = String(decoding: data, as: UTF8.self)
}
}
// this will be called when the system wants to write our data to disk
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
let data = Data(text.utf8)