From a1f70edec2661641e055e9e249a72e84733e4567 Mon Sep 17 00:00:00 2001 From: Trey t Date: Fri, 4 Feb 2022 16:49:56 -0600 Subject: [PATCH] closed #62 closed #60 --- Feels.xcodeproj/project.pbxproj | 4 ++ Shared/Models/Mood.swift | 2 +- Shared/Models/UserDefaultsStore.swift | 1 + Shared/views/AddMoodHeaderView.swift | 6 ++- Shared/views/ContentView.swift | 15 +++--- Shared/views/FilterView.swift | 39 ++++++++------- Shared/views/SettingsView.swift | 37 ++++++++++++-- Shared/views/SwitchableView.swift | 3 +- Shared/views/Theme.swift | 71 +++++++++++++++++++++++++++ en.lproj/Localizable.strings | 1 + 10 files changed, 150 insertions(+), 29 deletions(-) create mode 100644 Shared/views/Theme.swift diff --git a/Feels.xcodeproj/project.pbxproj b/Feels.xcodeproj/project.pbxproj index c7d2f1f..96200ec 100644 --- a/Feels.xcodeproj/project.pbxproj +++ b/Feels.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 1C2618FE27960A4F00FDC148 /* FilterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C2618FD27960A4F00FDC148 /* FilterViewModel.swift */; }; 1C26190327960CE500FDC148 /* ChartDataBuildable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C26190227960CE500FDC148 /* ChartDataBuildable.swift */; }; 1C26190727960DC900FDC148 /* ChartViewItemBuildable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C26190627960DC900FDC148 /* ChartViewItemBuildable.swift */; }; + 1C358FAD27ADD0C3002C83A6 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FAC27ADD0C3002C83A6 /* Theme.swift */; }; 1C5F4976279C84090092F1B4 /* OnboardingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4975279C84090092F1B4 /* OnboardingData.swift */; }; 1C5F4978279C945E0092F1B4 /* UserDefaultsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */; }; 1C683FCA2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; }; @@ -120,6 +121,7 @@ 1C2618FD27960A4F00FDC148 /* FilterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterViewModel.swift; sourceTree = ""; }; 1C26190227960CE500FDC148 /* ChartDataBuildable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartDataBuildable.swift; sourceTree = ""; }; 1C26190627960DC900FDC148 /* ChartViewItemBuildable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartViewItemBuildable.swift; sourceTree = ""; }; + 1C358FAC27ADD0C3002C83A6 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; 1C5F4975279C84090092F1B4 /* OnboardingData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingData.swift; sourceTree = ""; }; 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsStore.swift; sourceTree = ""; }; 1C683FC92792281400745862 /* Stats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stats.swift; sourceTree = ""; }; @@ -262,6 +264,7 @@ 1CAD602C27A5C1C800C520BD /* SettingsView.swift */, 1CAD602B27A5C1C800C520BD /* SmallRollUpHeaderView.swift */, 1CAD603D27A6ECCD00C520BD /* SwitchableView.swift */, + 1C358FAC27ADD0C3002C83A6 /* Theme.swift */, ); path = Views; sourceTree = ""; @@ -609,6 +612,7 @@ 1C5F4978279C945E0092F1B4 /* UserDefaultsStore.swift in Sources */, 1CD90B18278C7DE0001C4FEA /* FeelsApp.swift in Sources */, 1CA03777279A295600D26164 /* OnboardingTitle.swift in Sources */, + 1C358FAD27ADD0C3002C83A6 /* Theme.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Shared/Models/Mood.swift b/Shared/Models/Mood.swift index 33e76e1..70098b9 100644 --- a/Shared/Models/Mood.swift +++ b/Shared/Models/Mood.swift @@ -46,7 +46,7 @@ enum Mood: Int { case .great: return .green case .missing: - return Color(uiColor: UIColor.tertiarySystemBackground) + return Color(uiColor: UIColor.systemGray2) } } diff --git a/Shared/Models/UserDefaultsStore.swift b/Shared/Models/UserDefaultsStore.swift index 3ea9767..58bf27c 100644 --- a/Shared/Models/UserDefaultsStore.swift +++ b/Shared/Models/UserDefaultsStore.swift @@ -14,6 +14,7 @@ class UserDefaultsStore { case useCloudKit case deleteEnable case mainViewTopHeaderIndex + case theme } static func getOnboarding() -> OnboardingData { diff --git a/Shared/views/AddMoodHeaderView.swift b/Shared/views/AddMoodHeaderView.swift index fa335f8..5d3d563 100644 --- a/Shared/views/AddMoodHeaderView.swift +++ b/Shared/views/AddMoodHeaderView.swift @@ -12,6 +12,7 @@ import CoreData struct AddMoodHeaderView: View { private let savedOnboardingData = UserDefaultsStore.getOnboarding() + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system let addItemHeaderClosure: ((Mood, Date) -> Void) @@ -19,7 +20,7 @@ struct AddMoodHeaderView: View { var body: some View { ZStack { - Color(UIColor.systemBackground) + Color(theme.secondaryBGColor) VStack { Text(self.getTitle()) @@ -45,6 +46,9 @@ struct AddMoodHeaderView: View { } .padding([.leading, .trailing, .bottom]) } + .background( + Color(theme.secondaryBGColor) + ) .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) .frame(minHeight: 88, maxHeight: 150) .frame(minWidth: 0, maxWidth: .infinity) diff --git a/Shared/views/ContentView.swift b/Shared/views/ContentView.swift index 65c6e62..b2d6798 100644 --- a/Shared/views/ContentView.swift +++ b/Shared/views/ContentView.swift @@ -19,6 +19,7 @@ struct ContentView: View { @AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true @AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true @AppStorage(UserDefaultsStore.Keys.mainViewTopHeaderIndex.rawValue, store: GroupUserDefaults.groupDefaults) private var mainViewTopHeaderIndex = 0 + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system @State private var showingSheet = false @State private var showTodayInput = true @@ -33,7 +34,8 @@ struct ContentView: View { @ObservedObject var viewModel = ContentModeViewModel() init(){ - UITabBar.appearance().backgroundColor = UIColor.systemBackground + UITabBar.appearance().backgroundColor = theme.secondaryBGColor + print(theme) } var body: some View { @@ -180,7 +182,7 @@ struct ContentView: View { ) } .background( - Color(UIColor.systemBackground) + Color(theme.secondaryBGColor) ) .coordinateSpace(name: "scroll") .onPreferenceChange(ViewOffsetKey.self) { value in @@ -200,7 +202,7 @@ struct ContentView: View { .frame(maxWidth: .infinity, alignment: .leading) .padding() .background( - Color(UIColor.systemBackground) + Color(theme.secondaryBGColor) ) } @@ -285,7 +287,7 @@ struct ContentView: View { private var emptyView: some View { ZStack { - Color(UIColor.systemBackground) + Color(theme.secondaryBGColor) VStack { Text(String(localized: "content_view_empty_title")) @@ -327,7 +329,7 @@ struct ContentView: View { VStack { SmallRollUpHeaderView(fakeData: false, backDays: 30) .background( - Color(UIColor.systemBackground) + Color(theme.secondaryBGColor) ) .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) .padding() @@ -342,7 +344,8 @@ struct ContentView: View { .padding([.leading, .trailing, .bottom]) } }.background( - BGView().equatable() + theme.bg + .edgesIgnoringSafeArea(.all) ) } } diff --git a/Shared/views/FilterView.swift b/Shared/views/FilterView.swift index 811f915..ed96242 100644 --- a/Shared/views/FilterView.swift +++ b/Shared/views/FilterView.swift @@ -13,7 +13,6 @@ struct FilterView: View { let months = [(0, "J"), (1, "F"), (2,"M"), (3,"A"), (4,"M"), (5, "J"), (6,"J"), (7,"A"), (8,"S"), (9,"O"), (10, "N"), (11,"D")] @State private var toggle = true - @State private var showFilter = false @FetchRequest( @@ -21,6 +20,8 @@ struct FilterView: View { animation: .spring()) private var items: FetchedResults + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + @StateObject private var viewModel = FilterViewModel() //[ // 2001: [0: [], 1: [], 2: []], @@ -63,6 +64,10 @@ struct FilterView: View { self.viewModel.filterEntries(startDate: Date(timeIntervalSince1970: 0), endDate: Date()) }) } + .background( + theme.bg + .edgesIgnoringSafeArea(.all) + ) } private var filterButon: some View { @@ -75,7 +80,7 @@ struct FilterView: View { .frame(maxWidth: .infinity) .frame(height: 44) .foregroundColor(Color(UIColor.label)) - .background(Color(UIColor.secondarySystemBackground)) + .background(Color(theme.secondaryBGColor)) .cornerRadius(25) }).frame(maxWidth: .infinity) } @@ -97,7 +102,7 @@ struct FilterView: View { private var statsView: some View { ZStack { - Color(UIColor.secondarySystemBackground) + Color(theme.secondaryBGColor) HStack { Spacer() @@ -115,7 +120,7 @@ struct FilterView: View { VStack { VStack { ZStack { - Color(UIColor.secondarySystemBackground) + Color(theme.secondaryBGColor) DatePicker( String(localized: "filter_view_begin_date"), selection: $viewModel.entryStartDate, @@ -130,7 +135,7 @@ struct FilterView: View { .padding([.leading, .trailing]) ZStack { - Color(UIColor.secondarySystemBackground) + Color(theme.secondaryBGColor) DatePicker( String(localized: "filter_view_end_date"), selection: $viewModel.entryEndDate, @@ -145,7 +150,7 @@ struct FilterView: View { .padding([.leading, .trailing]) ZStack { - Color(UIColor.secondarySystemBackground) + Color(theme.secondaryBGColor) HStack { Spacer() ForEach(weekdays.indices, id: \.self) { dayIdx in @@ -198,6 +203,10 @@ struct FilterView: View { Text(String(yearKey)) .font(.title) yearGridView(yearData: yearData, columns: columns) + .background( + Color(theme.secondaryBGColor) + ) + .cornerRadius(25) } } .simultaneousGesture(DragGesture().onChanged({ _ in @@ -215,20 +224,16 @@ struct FilterView: View { let columns: [GridItem] var body: some View { - ZStack { - Color(UIColor.secondarySystemBackground) - - VStack { - LazyVGrid(columns: columns, spacing: 0) { - ForEach(Array(yearData.keys.sorted(by: <)), id: \.self) { monthKey in - let monthData = yearData[monthKey]! - VStack { - monthGridView(monthData: monthData) - } + VStack { + LazyVGrid(columns: columns, spacing: 0) { + ForEach(Array(yearData.keys.sorted(by: <)), id: \.self) { monthKey in + let monthData = yearData[monthKey]! + VStack { + monthGridView(monthData: monthData) } } - .padding([.leading, .trailing, .top, .bottom]) } + .padding([.leading, .trailing, .top, .bottom]) } .cornerRadius(25) } diff --git a/Shared/views/SettingsView.swift b/Shared/views/SettingsView.swift index 4f76a16..b6b84c0 100644 --- a/Shared/views/SettingsView.swift +++ b/Shared/views/SettingsView.swift @@ -22,19 +22,22 @@ struct SettingsView: View { @AppStorage(UserDefaultsStore.Keys.useCloudKit.rawValue, store: GroupUserDefaults.groupDefaults) private var useCloudKit = false @AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system var body: some View { ZStack { - Color(UIColor.secondarySystemBackground) + Color(theme.secondaryBGColor) VStack { + closeButtonView + .padding() + Group { - closeButtonView - .padding() cloudKitEnable addTestDataCell clearDB changeIcon + themePicker showOnboardingButton whyBackgroundMode specialThanksCell @@ -247,6 +250,34 @@ struct SettingsView: View { .fixedSize(horizontal: false, vertical: true) .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) } + + private var themePicker: some View { + ZStack { + Color(UIColor.systemBackground) + VStack { + Text(String(localized: "settings_background_title")) + HStack { + Spacer() + ForEach(Theme.allCases, id:\.rawValue) { aTheme in + Button(action: { + theme = aTheme + print(theme) + }, label: { + VStack { + aTheme.preview + Text(aTheme.title) + } + }) + Spacer() + } + } + .padding(.top) + } + .padding() + } + .fixedSize(horizontal: false, vertical: true) + .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) + } } struct SettingsView_Previews: PreviewProvider { diff --git a/Shared/views/SwitchableView.swift b/Shared/views/SwitchableView.swift index d0ce359..d0ab5c6 100644 --- a/Shared/views/SwitchableView.swift +++ b/Shared/views/SwitchableView.swift @@ -10,6 +10,7 @@ import SwiftUI struct SwitchableView: View { @State var currentViewIdx = 0 + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system let daysBack: Int @@ -47,7 +48,7 @@ struct SwitchableView: View { .padding(.top, -12) } .background( - Color(UIColor.systemBackground) + Color(theme.secondaryBGColor) ) .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) .contentShape(Rectangle()) diff --git a/Shared/views/Theme.swift b/Shared/views/Theme.swift new file mode 100644 index 0000000..6dd8c15 --- /dev/null +++ b/Shared/views/Theme.swift @@ -0,0 +1,71 @@ +// +// Theme.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/4/22. +// + +import SwiftUI + +enum Theme: Int, CaseIterable { + static let iconSize: CGFloat = 50 + case system + case ifeelTheme + + var title: String { + switch self { + + case .system: + return "System" + case .ifeelTheme: + return "iFeel Theme" + } + } + + var secondaryBGColor: UIColor { + switch self{ + case .system: + return UIColor.secondarySystemBackground + case .ifeelTheme: + return UIColor.systemBackground + } + } + + var bg: some View { + switch self { + case .system: + return AnyView( + ZStack { + Rectangle() + .fill(Color(UIColor.systemBackground)) + } + ) + case .ifeelTheme: + return AnyView( + BGView().equatable() + ) + } + } + + var preview: some View { + switch self { + case .system: + return AnyView( + ZStack { + Rectangle() + .fill(Color(UIColor.secondarySystemBackground)) + .frame(width: Theme.iconSize, height: Theme.iconSize) + .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) + } + ) + case .ifeelTheme: + return AnyView( + ZStack { + BGView().equatable() + .frame(width: Theme.iconSize, height: Theme.iconSize) + .clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous)) + } + ) + } + } +} diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index 24075fe..542167d 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -56,6 +56,7 @@ "settings_use_cloudkit_title" = "Use CloudKit"; "settings_use_cloudkit_body" = "CloudKit fucking sucks"; "settings_use_delete_enable" = "Allow deletion of entry"; +"settings_background_title" = "What background would you like to use"; "mood_value_great" = "Great"; "mood_value_good" = "Good";