diff --git a/Feels.xcodeproj/project.pbxproj b/Feels.xcodeproj/project.pbxproj index 168dd6d..7113156 100644 --- a/Feels.xcodeproj/project.pbxproj +++ b/Feels.xcodeproj/project.pbxproj @@ -22,6 +22,15 @@ 1C10E24E27A1AB110047948B /* UserDefaultsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */; }; 1C10E25027A1AB220047948B /* OnboardingDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03774279A294800D26164 /* OnboardingDay.swift */; }; 1C10E25127A1AB320047948B /* OnboardingTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03776279A295600D26164 /* OnboardingTitle.swift */; }; + 1C1AFF3027F894970067F9DC /* ThemePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF2F27F894970067F9DC /* ThemePickerView.swift */; }; + 1C1AFF3227F894A40067F9DC /* IconPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF3127F894A40067F9DC /* IconPickerView.swift */; }; + 1C1AFF3427F894BA0067F9DC /* TintPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF3327F894BA0067F9DC /* TintPickerView.swift */; }; + 1C1AFF3827F8951F0067F9DC /* CustomWigetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF3727F8951F0067F9DC /* CustomWigetView.swift */; }; + 1C1AFF3A27F895490067F9DC /* ImagePackPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF3927F895490067F9DC /* ImagePackPickerView.swift */; }; + 1C1AFF3C27F895800067F9DC /* TextColorPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF3B27F895800067F9DC /* TextColorPickerView.swift */; }; + 1C1AFF3E27F895A40067F9DC /* PersonalityPackPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF3D27F895A40067F9DC /* PersonalityPackPickerView.swift */; }; + 1C1AFF4127F895C00067F9DC /* ShapePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF4027F895C00067F9DC /* ShapePickerView.swift */; }; + 1C1AFF4327F895D90067F9DC /* DayFilterPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C1AFF4227F895D90067F9DC /* DayFilterPickerView.swift */; }; 1C2162EB27C14EFA004353D1 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C2162EA27C14EFA004353D1 /* Date+Extensions.swift */; }; 1C2162EC27C14FC5004353D1 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C2162EA27C14EFA004353D1 /* Date+Extensions.swift */; }; 1C2162EE27C15191004353D1 /* MoodEntryFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C2162ED27C15191004353D1 /* MoodEntryFunctions.swift */; }; @@ -191,6 +200,15 @@ 1C04489827C3F24000D22444 /* Color+Codable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Codable.swift"; sourceTree = ""; }; 1C0DAB46279DB0FB003B1F21 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 1C0DAB48279DB116003B1F21 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; + 1C1AFF2F27F894970067F9DC /* ThemePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemePickerView.swift; sourceTree = ""; }; + 1C1AFF3127F894A40067F9DC /* IconPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconPickerView.swift; sourceTree = ""; }; + 1C1AFF3327F894BA0067F9DC /* TintPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TintPickerView.swift; sourceTree = ""; }; + 1C1AFF3727F8951F0067F9DC /* CustomWigetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomWigetView.swift; sourceTree = ""; }; + 1C1AFF3927F895490067F9DC /* ImagePackPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePackPickerView.swift; sourceTree = ""; }; + 1C1AFF3B27F895800067F9DC /* TextColorPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextColorPickerView.swift; sourceTree = ""; }; + 1C1AFF3D27F895A40067F9DC /* PersonalityPackPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonalityPackPickerView.swift; sourceTree = ""; }; + 1C1AFF4027F895C00067F9DC /* ShapePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapePickerView.swift; sourceTree = ""; }; + 1C1AFF4227F895D90067F9DC /* DayFilterPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayFilterPickerView.swift; sourceTree = ""; }; 1C2162EA27C14EFA004353D1 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = ""; }; 1C2162ED27C15191004353D1 /* MoodEntryFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoodEntryFunctions.swift; sourceTree = ""; }; 1C2162F127C156E6004353D1 /* CustomizeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomizeView.swift; sourceTree = ""; }; @@ -365,6 +383,7 @@ isa = PBXGroup; children = ( 1C2162F127C156E6004353D1 /* CustomizeView.swift */, + 1C1AFF4427F898E40067F9DC /* SubViews */, ); path = CustomizeView; sourceTree = ""; @@ -394,6 +413,22 @@ path = Sharing; sourceTree = ""; }; + 1C1AFF4427F898E40067F9DC /* SubViews */ = { + isa = PBXGroup; + children = ( + 1C1AFF3727F8951F0067F9DC /* CustomWigetView.swift */, + 1C1AFF4227F895D90067F9DC /* DayFilterPickerView.swift */, + 1C1AFF3127F894A40067F9DC /* IconPickerView.swift */, + 1C1AFF3927F895490067F9DC /* ImagePackPickerView.swift */, + 1C1AFF3D27F895A40067F9DC /* PersonalityPackPickerView.swift */, + 1C1AFF4027F895C00067F9DC /* ShapePickerView.swift */, + 1C1AFF3B27F895800067F9DC /* TextColorPickerView.swift */, + 1C1AFF2F27F894970067F9DC /* ThemePickerView.swift */, + 1C1AFF3327F894BA0067F9DC /* TintPickerView.swift */, + ); + path = SubViews; + sourceTree = ""; + }; 1C26190127960CDA00FDC148 /* Protocols */ = { isa = PBXGroup; children = ( @@ -827,9 +862,11 @@ 1CA0377C279B605000D26164 /* OnboardingWrapup.swift in Sources */, 1C4FF3C327BEE07200BE8F34 /* PersistenceDELETE.swift in Sources */, 1CA03775279A294800D26164 /* OnboardingDay.swift in Sources */, + 1C1AFF3C27F895800067F9DC /* TextColorPickerView.swift in Sources */, 1CAD603727A5C1C800C520BD /* YearView.swift in Sources */, 1C04488D27C2ADDB00D22444 /* IconViewModel.swift in Sources */, 1C2162F227C156E6004353D1 /* CustomizeView.swift in Sources */, + 1C1AFF3E27F895A40067F9DC /* PersonalityPackPickerView.swift in Sources */, 1C683FCA2792281400745862 /* Stats.swift in Sources */, 1C76E86E27C882A400ADEE1F /* SharingImageModels.swift in Sources */, 1C718C7327F611E300A8F9FE /* StupidAssCustomWidgetObservableObject.swift in Sources */, @@ -837,6 +874,8 @@ 1CD90B76278C8119001C4FEA /* LocalNotification.swift in Sources */, 1C358FB627B0AE15002C83A6 /* AllMoodsTotalTemplate.swift in Sources */, 1CD90B16278C7DE0001C4FEA /* Feels.xcdatamodeld in Sources */, + 1C1AFF3027F894970067F9DC /* ThemePickerView.swift in Sources */, + 1C1AFF4327F895D90067F9DC /* DayFilterPickerView.swift in Sources */, 1C04488727C1C81D00D22444 /* PersonalityPackable.swift in Sources */, 1C4FF3BE27BEDF9100BE8F34 /* PersistenceHelper.swift in Sources */, 1CC469AA278F30A0003E0C6E /* BGTask.swift in Sources */, @@ -853,6 +892,7 @@ 1C358FBE27B4D1F2002C83A6 /* CurrentStreakTemplate.swift in Sources */, 1C4FF3C727BEE09E00BE8F34 /* PersistenceADD.swift in Sources */, 1C414C0F27D51FB500BC1720 /* EntryListView.swift in Sources */, + 1C1AFF3827F8951F0067F9DC /* CustomWigetView.swift in Sources */, 1C4FF3BB27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift in Sources */, 1CAD603527A5C1C800C520BD /* SettingsView.swift in Sources */, 1CD90B53278C7E7A001C4FEA /* FeelsWidget.intentdefinition in Sources */, @@ -869,6 +909,7 @@ 1C7352B927DD02760024B5D2 /* ImagePickerGridView.swift in Sources */, 1C358FB327B0ADA4002C83A6 /* SharingTemplate.swift in Sources */, 1C358FB827B0AEE3002C83A6 /* LongestStreakTemplate.swift in Sources */, + 1C1AFF4127F895C00067F9DC /* ShapePickerView.swift in Sources */, 1C358FB127B0AD87002C83A6 /* SharingListView.swift in Sources */, 1CD90B1C278C7DE0001C4FEA /* Persistence.swift in Sources */, 1CEC966F27B9C29300CC8688 /* CustomWidgetView.swift in Sources */, @@ -879,6 +920,7 @@ 1CD90B18278C7DE0001C4FEA /* FeelsApp.swift in Sources */, 1C358FC027B4D20C002C83A6 /* MonthTotalTemplate.swift in Sources */, 1CA03777279A295600D26164 /* OnboardingTitle.swift in Sources */, + 1C1AFF3A27F895490067F9DC /* ImagePackPickerView.swift in Sources */, 1C4FF3C027BEE06900BE8F34 /* PersistenceGET.swift in Sources */, 1C04488A27C2ABD500D22444 /* IconView.swift in Sources */, 1C361F0C27C0356B00E832FC /* MainTabView.swift in Sources */, @@ -891,7 +933,9 @@ 1C95ABCC27E6FA7200509BD3 /* DiamondView.swift in Sources */, 1C2162EB27C14EFA004353D1 /* Date+Extensions.swift in Sources */, 1C02589C27B9677A00EB91AC /* CreateWidgetView.swift in Sources */, + 1C1AFF3227F894A40067F9DC /* IconPickerView.swift in Sources */, 1C04489927C3F24000D22444 /* Color+Codable.swift in Sources */, + 1C1AFF3427F894BA0067F9DC /* TintPickerView.swift in Sources */, 1C358FC227B4D227002C83A6 /* WeekTotalTemplate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Shared/FeelsApp.swift b/Shared/FeelsApp.swift index e9cd673..040a93f 100644 --- a/Shared/FeelsApp.swift +++ b/Shared/FeelsApp.swift @@ -14,8 +14,6 @@ struct FeelsApp: App { @Environment(\.scenePhase) private var scenePhase @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate - @StateObject var daysFilter = DaysFilterClass() - let persistenceController = PersistenceController.shared init() { @@ -28,12 +26,16 @@ struct FeelsApp: App { var body: some Scene { WindowGroup { - MainTabView() - .environment(\.managedObjectContext, persistenceController.viewContext) - .environmentObject(daysFilter) + // build these here so when tints and other things get updated the views / their data dont + // have to get redrawn + MainTabView(dayView: DayView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: false)), + monthView: MonthView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: true)), + yearView: YearView(viewModel: YearViewModel()), + customizeView: CustomizeView()) + .environment(\.managedObjectContext, persistenceController.viewContext) }.onChange(of: scenePhase) { phase in if phase == .background { -// BGTask.scheduleBackgroundProcessing() + //BGTask.scheduleBackgroundProcessing() WidgetCenter.shared.reloadAllTimelines() } diff --git a/Shared/Models/DaysFilterClass.swift b/Shared/Models/DaysFilterClass.swift index 9652e54..f7c94c8 100644 --- a/Shared/Models/DaysFilterClass.swift +++ b/Shared/Models/DaysFilterClass.swift @@ -8,6 +8,8 @@ import SwiftUI class DaysFilterClass: ObservableObject { + static let shared = DaysFilterClass() + @Published public var currentFilters = [Int]() init() { diff --git a/Shared/Random.swift b/Shared/Random.swift index 968aa9f..08a9d15 100644 --- a/Shared/Random.swift +++ b/Shared/Random.swift @@ -11,6 +11,8 @@ import SwiftUI struct Constants { static let groupShareId = "group.com.88oakapps.ifeel" static let groupShareIdDebug = "group.com.88oakapps.ifeelDebug" + + static let viewsCornerRaidus: CGFloat = 10 } struct GroupUserDefaults { diff --git a/Shared/views/AddMoodHeaderView.swift b/Shared/views/AddMoodHeaderView.swift index 6e37b30..bf89566 100644 --- a/Shared/views/AddMoodHeaderView.swift +++ b/Shared/views/AddMoodHeaderView.swift @@ -54,7 +54,7 @@ struct AddMoodHeaderView: View { .background( theme.currentTheme.secondaryBGColor ) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .frame(minHeight: 88, maxHeight: 150) .frame(minWidth: 0, maxWidth: .infinity) } diff --git a/Shared/views/CustomizeView/CustomizeView.swift b/Shared/views/CustomizeView/CustomizeView.swift index 153e3a7..1321fb5 100644 --- a/Shared/views/CustomizeView/CustomizeView.swift +++ b/Shared/views/CustomizeView/CustomizeView.swift @@ -8,365 +8,43 @@ import SwiftUI struct CustomizeView: View { - @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system - - @AppStorage(UserDefaultsStore.Keys.moodImages.rawValue, store: GroupUserDefaults.groupDefaults) private var imagePack: MoodImages = .FontAwesome - - @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default - - @AppStorage(UserDefaultsStore.Keys.shape.rawValue, store: GroupUserDefaults.groupDefaults) private var shape: BGShape = .circle - - @AppStorage(UserDefaultsStore.Keys.personalityPack.rawValue, store: GroupUserDefaults.groupDefaults) private var personalityPack: PersonalityPack = .Default - - @AppStorage(UserDefaultsStore.Keys.customMoodTintUpdateNumber.rawValue, store: GroupUserDefaults.groupDefaults) private var customMoodTintUpdateNumber: Int = 0 - - @AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor - - @AppStorage(UserDefaultsStore.Keys.showNSFW.rawValue, store: GroupUserDefaults.groupDefaults) private var showNSFW: Bool = false - @State private var sampleListEntry = PersistenceController.shared.randomEntries(count: 1).first! - @State private var showOver18Alert = false - - @StateObject private var customMoodTint = UserDefaultsStore.getCustomMoodTint() - - @State var shapeRefreshToggleThing: Bool = false - - @StateObject private var selectedWidget = StupidAssCustomWidgetObservableObject() - - @EnvironmentObject var daysFilter: DaysFilterClass - - let weekdays = [("Sun", 1), - ("mon", 2), - ("tue", 3), - ("wed", 4), - ("thur", 5), - ("fri", 6), - ("sat", 7)] - - let iconSets: [(String,String)] = [ - ("AppIconGoodImage", "AppIconGood"), - ("AppIconAverageImage", "AppIconAverage"), - ("AppIconBadImage", "AppIconBad"), - ("AppIconBlueGreenImage", "AppIconBlueGreen"), - ("AppIconNeonGreenImage", "AppIconNeonGreen"), - ("AppIconPinkImage", "AppIconPink"), - ("AppIconPurpleImage", "AppIconPurple") - ] + @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 var body: some View { ScrollView { VStack { Group { - createCustomWidget - changeIcon - themePicker + CustomWigetView() + IconPickerView() + ThemePickerView() Divider() sampleEntryView - pickMoodImagePack + ImagePackPickerView() } Group { - pickMoodTintPack - pickTextColor + TintPickerView() + TextColorPickerView() } Divider() - dayFilterView + DayFilterPickerView() Divider() - shapePicker + ShapePickerView() Divider() - pickPeronsalityPack + PersonalityPackPickerView() } } .onAppear(perform: { EventLogger.log(event: "show_customize_view") }) .padding() - .sheet(isPresented: $selectedWidget.showFuckingSheet) { - if let fuckingWrapped = selectedWidget.fuckingWrapped { - CreateWidgetView(customWidget: fuckingWrapped) - } - } .background( theme.currentTheme.bg .edgesIgnoringSafeArea(.all) ) } - private var changeIcon: some View { - ZStack { - theme.currentTheme.secondaryBGColor - VStack { - ScrollView(.horizontal) { - HStack { - Button(action: { - UIApplication.shared.setAlternateIconName(nil) - EventLogger.log(event: "change_icon_title", withData: ["title": "default"]) - }, label: { - Image("AppIconImage", bundle: .main) - .resizable() - .frame(width: 50, height:50) - .cornerRadius(10) - }) - - - ForEach(iconSets, id: \.self.0){ iconSet in - Button(action: { - UIApplication.shared.setAlternateIconName(iconSet.1) { (error) in - // FIXME: Handle error - } - EventLogger.log(event: "change_icon_title", withData: ["title": iconSet.1]) - }, label: { - Image(iconSet.0, bundle: .main) - .resizable() - .frame(width: 50, height:50) - .cornerRadius(10) - }) - } - } - .padding() - } - .background(RoundedRectangle(cornerRadius: 10).fill().foregroundColor(theme.currentTheme.bgColor)) - .padding() - .cornerRadius(10) - } - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var themePicker: some View { - ZStack { - theme.currentTheme.secondaryBGColor - VStack { - HStack { - Spacer() - ForEach(Theme.allCases, id:\.rawValue) { aTheme in - Button(action: { - theme = aTheme - EventLogger.log(event: "change_theme_id", withData: ["id": aTheme.rawValue]) - }, label: { - VStack { - aTheme.currentTheme.preview - .overlay( - Circle() - .stroke(Color(UIColor.systemGray), style: StrokeStyle(lineWidth: 2)) - ) - Text(aTheme.title) - .foregroundColor(textColor) - .font(.body) - } - }) - .contentShape(Rectangle()) - .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .fill(theme == aTheme ? theme.currentTheme.bgColor : .clear) - .padding(-5) - - ) - Spacer() - } - } - .padding(.top) - } - .padding() - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var createCustomWidget: some View { - ZStack { - theme.currentTheme.secondaryBGColor - VStack { - ScrollView(.horizontal) { - HStack { - ForEach(UserDefaultsStore.getCustomWidgets(), id: \.uuid) { widget in - CustomWidgetView(customWidgetModel: widget) - .frame(width: 50, height: 50) - .cornerRadius(10) - .onTapGesture { - EventLogger.log(event: "show_widget") - selectedWidget.fuckingWrapped = widget.copy() as? CustomWidgetModel - selectedWidget.showFuckingSheet = true - } - } - RoundedRectangle(cornerRadius: 10).fill().foregroundColor(theme.currentTheme.secondaryBGColor) - .frame(width: 50, height: 50) - .overlay( - Image(systemName: "plus") - ) - .onTapGesture { - EventLogger.log(event: "tap_create_new_widget") - selectedWidget.fuckingWrapped = CustomWidgetModel.randomWidget - selectedWidget.showFuckingSheet = true - } - } - .padding() - } - .background(RoundedRectangle(cornerRadius: 10).fill().foregroundColor(theme.currentTheme.bgColor)) - .padding() - .cornerRadius(10) - - Text("[How to add widget](https://support.apple.com/guide/iphone/add-widgets-iphb8f1bf206/ios)") - .accentColor(textColor) - .padding(.bottom) - } - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var pickMoodImagePack: some View { - ZStack { - theme.currentTheme.secondaryBGColor - VStack { - ForEach(MoodImages.allCases, id: \.rawValue) { images in - ZStack { - VStack { - HStack { - ForEach(Mood.allValues, id: \.self) { mood in - images.icon(forMood: mood) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 35, height: 35) - .foregroundColor( - moodTint.color(forMood: mood) - ) - } - .frame(minWidth: 0, maxWidth: .infinity) - } - .contentShape(Rectangle()) - .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .fill(imagePack == images ? theme.currentTheme.bgColor : .clear) - .padding([.top, .bottom], -3) - ) - .onTapGesture { - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - imagePack = images - EventLogger.log(event: "change_image_pack_id", withData: ["id": images.rawValue]) - } - if images.rawValue != (MoodImages.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 { - Divider() - } - } - } - } - } - .padding() - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var pickMoodTintPack: some View { - ZStack { - theme.currentTheme.secondaryBGColor - VStack { - ForEach(MoodTints.defaultOptions, id: \.rawValue) { tint in - HStack { - ForEach(Mood.allValues, id: \.self) { mood in - Circle() - .frame(width: 35, height: 35) - .foregroundColor( - tint.color(forMood: mood) - ) - } - .frame(minWidth: 0, maxWidth: .infinity) - } - .contentShape(Rectangle()) - .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .fill(moodTint == tint ? theme.currentTheme.bgColor : .clear) - .padding([.top, .bottom], -3) - - ) - .onTapGesture { - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - moodTint = tint - EventLogger.log(event: "change_mood_tint_id", withData: ["id": tint.rawValue]) - } - Divider() - } - - ZStack { - Color.clear - - Rectangle() - .frame(height: 35) - .frame(minWidth: 0, maxWidth: .infinity) - .foregroundColor(.clear) - .contentShape(Rectangle()) - .onTapGesture { - moodTint = .Custom - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - } - - HStack { - ColorPicker("", selection: $customMoodTint.colorOne) - .onChange(of: customMoodTint.colorOne, perform: { _ in - saveCustomMoodTint() - }) - .labelsHidden() - .frame(minWidth: 0, maxWidth: .infinity) - - ColorPicker("", selection: $customMoodTint.colorTwo) - .labelsHidden() - .frame(minWidth: 0, maxWidth: .infinity) - .onChange(of: customMoodTint.colorTwo, perform: { _ in - saveCustomMoodTint() - }) - - ColorPicker("", selection: $customMoodTint.colorThree) - .labelsHidden() - .frame(minWidth: 0, maxWidth: .infinity) - .onChange(of: customMoodTint.colorThree, perform: { _ in - saveCustomMoodTint() - }) - - ColorPicker("", selection: $customMoodTint.colorFour) - .labelsHidden() - .frame(minWidth: 0, maxWidth: .infinity) - .onChange(of: customMoodTint.colorFour, perform: { _ in - saveCustomMoodTint() - }) - - ColorPicker("", selection: $customMoodTint.colorFive) - .labelsHidden() - .frame(minWidth: 0, maxWidth: .infinity) - .onChange(of: customMoodTint.colorFive, perform: { _ in - saveCustomMoodTint() - }) - } - .background( - Color.clear - ) - } - .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .fill(moodTint == .Custom ? theme.currentTheme.bgColor : .clear) - .padding([.top, .bottom], -3) - ) - } - .padding() - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var pickTextColor: some View { - ZStack { - theme.currentTheme.secondaryBGColor - ColorPicker(String(localized: "customize_view_view_text_color"), selection: $textColor) - .padding() - .foregroundColor(textColor) - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - private var sampleEntryView: some View { ZStack { theme.currentTheme.secondaryBGColor @@ -395,156 +73,10 @@ struct CustomizeView: View { } } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } - private func saveCustomMoodTint() { - UserDefaultsStore.saveCustomMoodTint(customTint: customMoodTint) - moodTint = .Custom - EventLogger.log(event: "change_mood_tint_id", withData: ["id": MoodTints.Custom.rawValue]) - customMoodTintUpdateNumber += 1 - } - private var pickPeronsalityPack: some View { - ZStack { - theme.currentTheme.secondaryBGColor - VStack { - ForEach(PersonalityPack.allCases, id: \.self) { aPack in - VStack(spacing: 10) { - Text(String(aPack.title())) - .font(.body) - .foregroundColor(textColor) - - Text(aPack.randomPushNotificationStrings().title) - .font(.body) - .foregroundColor(Color(UIColor.systemGray)) - Text(aPack.randomPushNotificationStrings().body) - .font(.body) - .foregroundColor(Color(UIColor.systemGray)) - } - .frame(minWidth: 0, maxWidth: .infinity) - .padding() - .contentShape(Rectangle()) - .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .fill(personalityPack == aPack ? theme.currentTheme.bgColor : .clear) - .padding(5) - ) - .onTapGesture { - if aPack.rawValue == PersonalityPack.Rude.rawValue && !showNSFW { - showOver18Alert = true - EventLogger.log(event: "show_over_18_alert") - } else { - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - personalityPack = aPack - EventLogger.log(event: "change_personality_pack", withData: ["pack_title": aPack.title()]) - LocalNotification.rescheduleNotifiations() - } - } - .blur(radius: aPack.rawValue == PersonalityPack.Rude.rawValue && !showNSFW ? 5 : 0) - .alert(isPresented: $showOver18Alert) { - let primaryButton = Alert.Button.default(Text(String(localized: "customize_view_over18alert_ok"))) { - showNSFW = true - } - let secondaryButton = Alert.Button.cancel(Text(String(localized: "customize_view_over18alert_no"))) { - showNSFW = false - } - return Alert(title: Text(String(localized: "customize_view_over18alert_title")), - message: Text(String(localized: "customize_view_over18alert_body")), - primaryButton: primaryButton, - secondaryButton: secondaryButton) - } - if aPack.rawValue != (PersonalityPack.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 { - Divider() - } - } - - } - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var shapePicker: some View { - ZStack { - theme.currentTheme.secondaryBGColor - - VStack { - HStack { - Spacer() - Text(shapeRefreshToggleThing.description.localizedLowercase) - .hidden() - Image(systemName: "arrow.triangle.2.circlepath.circle") - .resizable() - .frame(width: 20, height: 20, alignment: .trailing) - .foregroundColor(Color(UIColor.systemGray)) - .onTapGesture { - shapeRefreshToggleThing.toggle() - } - } - Spacer() - } - .padding() - - VStack(alignment:.leading) { - Text(String(localized: "customize_view_view_pick_shape")) - .padding([.leading]) - .foregroundColor(textColor) - - Divider() - - HStack { - ForEach(BGShape.allCases, id: \.rawValue) { ashape in - ashape.view(withText: Text("20"), - bgColor: moodTint.color(forMood: Mood.allValues.randomElement()!), textColor: textColor) - .frame(height: 50) - .frame(minWidth: 0, maxWidth: .infinity) - .onTapGesture { - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - shape = ashape - EventLogger.log(event: "change_mood_shape_id", withData: ["id": shape.rawValue]) - } - .contentShape(Rectangle()) - .background( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .fill(shape == ashape ? theme.currentTheme.bgColor : .clear) - .padding(-5) - ) - } - } - } - .padding() - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } - - private var dayFilterView: some View { - ZStack { - theme.currentTheme.secondaryBGColor - HStack { - ForEach(weekdays.indices, id: \.self) { dayIdx in - let day = String(weekdays[dayIdx].0) - let value = weekdays[dayIdx].1 - - Button(day.capitalized, action: { - if daysFilter.currentFilters.contains(value) { - daysFilter.removeFilter(filter: value) - } else { - daysFilter.addFilter(newFilter: value) - } - }) - .frame(maxWidth: .infinity) - .foregroundColor(daysFilter.currentFilters.contains(value) ? .green : .red) - } - } - .padding() - } - .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) - } } struct CustomizeView_Previews: PreviewProvider { diff --git a/Shared/views/CustomizeView/SubViews/CustomWigetView.swift b/Shared/views/CustomizeView/SubViews/CustomWigetView.swift new file mode 100644 index 0000000..fcc64d2 --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/CustomWigetView.swift @@ -0,0 +1,67 @@ +// +// CustomWigetView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct CustomWigetView: 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 + @StateObject private var selectedWidget = StupidAssCustomWidgetObservableObject() + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + VStack { + ScrollView(.horizontal) { + HStack { + ForEach(UserDefaultsStore.getCustomWidgets(), id: \.uuid) { widget in + CustomWidgetView(customWidgetModel: widget) + .frame(width: 50, height: 50) + .cornerRadius(10) + .onTapGesture { + EventLogger.log(event: "show_widget") + selectedWidget.fuckingWrapped = widget.copy() as? CustomWidgetModel + selectedWidget.showFuckingSheet = true + } + } + RoundedRectangle(cornerRadius: 10).fill().foregroundColor(theme.currentTheme.secondaryBGColor) + .frame(width: 50, height: 50) + .overlay( + Image(systemName: "plus") + ) + .onTapGesture { + EventLogger.log(event: "tap_create_new_widget") + selectedWidget.fuckingWrapped = CustomWidgetModel.randomWidget + selectedWidget.showFuckingSheet = true + } + } + .padding() + } + .background(RoundedRectangle(cornerRadius: 10).fill().foregroundColor(theme.currentTheme.bgColor)) + .padding() + .cornerRadius(10) + + Text("[How to add widget](https://support.apple.com/guide/iphone/add-widgets-iphb8f1bf206/ios)") + .accentColor(textColor) + .padding(.bottom) + } + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .sheet(isPresented: $selectedWidget.showFuckingSheet) { + if let fuckingWrapped = selectedWidget.fuckingWrapped { + CreateWidgetView(customWidget: fuckingWrapped) + } + } + } +} + +struct CustomWigetView_Previews: PreviewProvider { + static var previews: some View { + CustomWigetView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/DayFilterPickerView.swift b/Shared/views/CustomizeView/SubViews/DayFilterPickerView.swift new file mode 100644 index 0000000..16802ea --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/DayFilterPickerView.swift @@ -0,0 +1,52 @@ +// +// DayFilterPickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct DayFilterPickerView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + @StateObject private var filteredDays = DaysFilterClass.shared + + let weekdays = [("Sun", 1), + ("mon", 2), + ("tue", 3), + ("wed", 4), + ("thur", 5), + ("fri", 6), + ("sat", 7)] + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + + HStack { + ForEach(weekdays.indices, id: \.self) { dayIdx in + let day = String(weekdays[dayIdx].0) + let value = weekdays[dayIdx].1 + Button(day.capitalized, action: { + if filteredDays.currentFilters.contains(value) { + filteredDays.removeFilter(filter: value) + } else { + filteredDays.addFilter(newFilter: value) + } + }) + .frame(maxWidth: .infinity) + .foregroundColor(filteredDays.currentFilters.contains(value) ? .green : .red) + } + } + .padding() + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct DayFilterPickerView_Previews: PreviewProvider { + static var previews: some View { + DayFilterPickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/IconPickerView.swift b/Shared/views/CustomizeView/SubViews/IconPickerView.swift new file mode 100644 index 0000000..77b08be --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/IconPickerView.swift @@ -0,0 +1,70 @@ +// +// IconPickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct IconPickerView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + + let iconSets: [(String,String)] = [ + ("AppIconGoodImage", "AppIconGood"), + ("AppIconAverageImage", "AppIconAverage"), + ("AppIconBadImage", "AppIconBad"), + ("AppIconBlueGreenImage", "AppIconBlueGreen"), + ("AppIconNeonGreenImage", "AppIconNeonGreen"), + ("AppIconPinkImage", "AppIconPink"), + ("AppIconPurpleImage", "AppIconPurple") + ] + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + VStack { + ScrollView(.horizontal) { + HStack { + Button(action: { + UIApplication.shared.setAlternateIconName(nil) + EventLogger.log(event: "change_icon_title", withData: ["title": "default"]) + }, label: { + Image("AppIconImage", bundle: .main) + .resizable() + .frame(width: 50, height:50) + .cornerRadius(10) + }) + + + ForEach(iconSets, id: \.self.0){ iconSet in + Button(action: { + UIApplication.shared.setAlternateIconName(iconSet.1) { (error) in + // FIXME: Handle error + } + EventLogger.log(event: "change_icon_title", withData: ["title": iconSet.1]) + }, label: { + Image(iconSet.0, bundle: .main) + .resizable() + .frame(width: 50, height:50) + .cornerRadius(10) + }) + } + } + .padding() + } + .background(RoundedRectangle(cornerRadius: 10).fill().foregroundColor(theme.currentTheme.bgColor)) + .padding() + .cornerRadius(10) + } + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct IconPickerView_Previews: PreviewProvider { + static var previews: some View { + IconPickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/ImagePackPickerView.swift b/Shared/views/CustomizeView/SubViews/ImagePackPickerView.swift new file mode 100644 index 0000000..c6a5a7c --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/ImagePackPickerView.swift @@ -0,0 +1,64 @@ +// +// ImagePackPickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct ImagePackPickerView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default + @AppStorage(UserDefaultsStore.Keys.moodImages.rawValue, store: GroupUserDefaults.groupDefaults) private var imagePack: MoodImages = .FontAwesome + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + VStack { + ForEach(MoodImages.allCases, id: \.rawValue) { images in + ZStack { + VStack { + HStack { + ForEach(Mood.allValues, id: \.self) { mood in + images.icon(forMood: mood) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 35, height: 35) + .foregroundColor( + moodTint.color(forMood: mood) + ) + } + .frame(minWidth: 0, maxWidth: .infinity) + } + .contentShape(Rectangle()) + .background( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .fill(imagePack == images ? theme.currentTheme.bgColor : .clear) + .padding([.top, .bottom], -3) + ) + .onTapGesture { + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + imagePack = images + EventLogger.log(event: "change_image_pack_id", withData: ["id": images.rawValue]) + } + if images.rawValue != (MoodImages.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 { + Divider() + } + } + } + } + } + .padding() + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct ImagePackPickerView_Previews: PreviewProvider { + static var previews: some View { + ImagePackPickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/PersonalityPackPickerView.swift b/Shared/views/CustomizeView/SubViews/PersonalityPackPickerView.swift new file mode 100644 index 0000000..652704c --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/PersonalityPackPickerView.swift @@ -0,0 +1,83 @@ +// +// PersonalityPackPickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct PersonalityPackPickerView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + @AppStorage(UserDefaultsStore.Keys.personalityPack.rawValue, store: GroupUserDefaults.groupDefaults) private var personalityPack: PersonalityPack = .Default + @State private var showOver18Alert = false + @AppStorage(UserDefaultsStore.Keys.showNSFW.rawValue, store: GroupUserDefaults.groupDefaults) private var showNSFW: Bool = false + @AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + VStack { + ForEach(PersonalityPack.allCases, id: \.self) { aPack in + VStack(spacing: 10) { + Text(String(aPack.title())) + .font(.body) + .foregroundColor(textColor) + + Text(aPack.randomPushNotificationStrings().title) + .font(.body) + .foregroundColor(Color(UIColor.systemGray)) + Text(aPack.randomPushNotificationStrings().body) + .font(.body) + .foregroundColor(Color(UIColor.systemGray)) + } + .frame(minWidth: 0, maxWidth: .infinity) + .padding() + .contentShape(Rectangle()) + .background( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .fill(personalityPack == aPack ? theme.currentTheme.bgColor : .clear) + .padding(5) + ) + .onTapGesture { + if aPack.rawValue == PersonalityPack.Rude.rawValue && !showNSFW { + showOver18Alert = true + EventLogger.log(event: "show_over_18_alert") + } else { + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + personalityPack = aPack + EventLogger.log(event: "change_personality_pack", withData: ["pack_title": aPack.title()]) + LocalNotification.rescheduleNotifiations() + } + } + .blur(radius: aPack.rawValue == PersonalityPack.Rude.rawValue && !showNSFW ? 5 : 0) + .alert(isPresented: $showOver18Alert) { + let primaryButton = Alert.Button.default(Text(String(localized: "customize_view_over18alert_ok"))) { + showNSFW = true + } + let secondaryButton = Alert.Button.cancel(Text(String(localized: "customize_view_over18alert_no"))) { + showNSFW = false + } + return Alert(title: Text(String(localized: "customize_view_over18alert_title")), + message: Text(String(localized: "customize_view_over18alert_body")), + primaryButton: primaryButton, + secondaryButton: secondaryButton) + } + if aPack.rawValue != (PersonalityPack.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 { + Divider() + } + } + + } + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct PersonalityPackPickerView_Previews: PreviewProvider { + static var previews: some View { + PersonalityPackPickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/ShapePickerView.swift b/Shared/views/CustomizeView/SubViews/ShapePickerView.swift new file mode 100644 index 0000000..b0890c7 --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/ShapePickerView.swift @@ -0,0 +1,77 @@ +// +// ShapePickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct ShapePickerView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + @State var shapeRefreshToggleThing: Bool = false + @AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor + @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default + @AppStorage(UserDefaultsStore.Keys.shape.rawValue, store: GroupUserDefaults.groupDefaults) private var shape: BGShape = .circle + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + + VStack { + HStack { + Spacer() + Text(shapeRefreshToggleThing.description.localizedLowercase) + .hidden() + Image(systemName: "arrow.triangle.2.circlepath.circle") + .resizable() + .frame(width: 20, height: 20, alignment: .trailing) + .foregroundColor(Color(UIColor.systemGray)) + .onTapGesture { + shapeRefreshToggleThing.toggle() + } + } + Spacer() + } + .padding() + + VStack(alignment:.leading) { + Text(String(localized: "customize_view_view_pick_shape")) + .padding([.leading]) + .foregroundColor(textColor) + + Divider() + + HStack { + ForEach(BGShape.allCases, id: \.rawValue) { ashape in + ashape.view(withText: Text("20"), + bgColor: moodTint.color(forMood: Mood.allValues.randomElement()!), textColor: textColor) + .frame(height: 50) + .frame(minWidth: 0, maxWidth: .infinity) + .onTapGesture { + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + shape = ashape + EventLogger.log(event: "change_mood_shape_id", withData: ["id": shape.rawValue]) + } + .contentShape(Rectangle()) + .background( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .fill(shape == ashape ? theme.currentTheme.bgColor : .clear) + .padding(-5) + ) + } + } + } + .padding() + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct ShapePickerView_Previews: PreviewProvider { + static var previews: some View { + ShapePickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/TextColorPickerView.swift b/Shared/views/CustomizeView/SubViews/TextColorPickerView.swift new file mode 100644 index 0000000..9fad18e --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/TextColorPickerView.swift @@ -0,0 +1,30 @@ +// +// TextColorPickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct TextColorPickerView: 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 + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + ColorPicker(String(localized: "customize_view_view_text_color"), selection: $textColor) + .padding() + .foregroundColor(textColor) + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct TextColorPickerView_Previews: PreviewProvider { + static var previews: some View { + TextColorPickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/ThemePickerView.swift b/Shared/views/CustomizeView/SubViews/ThemePickerView.swift new file mode 100644 index 0000000..710a0ea --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/ThemePickerView.swift @@ -0,0 +1,59 @@ +// +// ThemePicker.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct ThemePickerView: 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 + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + VStack { + HStack { + Spacer() + ForEach(Theme.allCases, id:\.rawValue) { aTheme in + Button(action: { + theme = aTheme + EventLogger.log(event: "change_theme_id", withData: ["id": aTheme.rawValue]) + }, label: { + VStack { + aTheme.currentTheme.preview + .overlay( + Circle() + .stroke(Color(UIColor.systemGray), style: StrokeStyle(lineWidth: 2)) + ) + Text(aTheme.title) + .foregroundColor(textColor) + .font(.body) + } + }) + .contentShape(Rectangle()) + .background( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .fill(theme == aTheme ? theme.currentTheme.bgColor : .clear) + .padding(-5) + + ) + Spacer() + } + } + .padding(.top) + } + .padding() + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } +} + +struct ThemePickerView_Previews: PreviewProvider { + static var previews: some View { + ThemePickerView() + } +} diff --git a/Shared/views/CustomizeView/SubViews/TintPickerView.swift b/Shared/views/CustomizeView/SubViews/TintPickerView.swift new file mode 100644 index 0000000..41185e1 --- /dev/null +++ b/Shared/views/CustomizeView/SubViews/TintPickerView.swift @@ -0,0 +1,125 @@ +// +// TintPickerView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 4/2/22. +// + +import SwiftUI + +struct TintPickerView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + @AppStorage(UserDefaultsStore.Keys.customMoodTintUpdateNumber.rawValue, store: GroupUserDefaults.groupDefaults) private var customMoodTintUpdateNumber: Int = 0 + @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default + @StateObject private var customMoodTint = UserDefaultsStore.getCustomMoodTint() + + var body: some View { + ZStack { + theme.currentTheme.secondaryBGColor + VStack { + ForEach(MoodTints.defaultOptions, id: \.rawValue) { tint in + HStack { + ForEach(Mood.allValues, id: \.self) { mood in + Circle() + .frame(width: 35, height: 35) + .foregroundColor( + tint.color(forMood: mood) + ) + } + .frame(minWidth: 0, maxWidth: .infinity) + } + .contentShape(Rectangle()) + .background( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .fill(moodTint == tint ? theme.currentTheme.bgColor : .clear) + .padding([.top, .bottom], -3) + + ) + .onTapGesture { + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + moodTint = tint + EventLogger.log(event: "change_mood_tint_id", withData: ["id": tint.rawValue]) + } + Divider() + } + + ZStack { + Color.clear + + Rectangle() + .frame(height: 35) + .frame(minWidth: 0, maxWidth: .infinity) + .foregroundColor(.clear) + .contentShape(Rectangle()) + .onTapGesture { + moodTint = .Custom + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + } + + HStack { + ColorPicker("", selection: $customMoodTint.colorOne) + .onChange(of: customMoodTint.colorOne, perform: { _ in + saveCustomMoodTint() + }) + .labelsHidden() + .frame(minWidth: 0, maxWidth: .infinity) + + ColorPicker("", selection: $customMoodTint.colorTwo) + .labelsHidden() + .frame(minWidth: 0, maxWidth: .infinity) + .onChange(of: customMoodTint.colorTwo, perform: { _ in + saveCustomMoodTint() + }) + + ColorPicker("", selection: $customMoodTint.colorThree) + .labelsHidden() + .frame(minWidth: 0, maxWidth: .infinity) + .onChange(of: customMoodTint.colorThree, perform: { _ in + saveCustomMoodTint() + }) + + ColorPicker("", selection: $customMoodTint.colorFour) + .labelsHidden() + .frame(minWidth: 0, maxWidth: .infinity) + .onChange(of: customMoodTint.colorFour, perform: { _ in + saveCustomMoodTint() + }) + + ColorPicker("", selection: $customMoodTint.colorFive) + .labelsHidden() + .frame(minWidth: 0, maxWidth: .infinity) + .onChange(of: customMoodTint.colorFive, perform: { _ in + saveCustomMoodTint() + }) + } + .background( + Color.clear + ) + } + .background( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .fill(moodTint == .Custom ? theme.currentTheme.bgColor : .clear) + .padding([.top, .bottom], -3) + ) + } + .padding() + } + .fixedSize(horizontal: false, vertical: true) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + } + + private func saveCustomMoodTint() { + UserDefaultsStore.saveCustomMoodTint(customTint: customMoodTint) + moodTint = .Custom + EventLogger.log(event: "change_mood_tint_id", withData: ["id": MoodTints.Custom.rawValue]) + customMoodTintUpdateNumber += 1 + } +} + +struct TintPickerView_Previews: PreviewProvider { + static var previews: some View { + TintPickerView() + } +} diff --git a/Shared/views/DayView/DayView.swift b/Shared/views/DayView/DayView.swift index 6f379c6..1444339 100644 --- a/Shared/views/DayView/DayView.swift +++ b/Shared/views/DayView/DayView.swift @@ -15,8 +15,6 @@ struct DayViewConstants { } struct DayView: View { - @EnvironmentObject var daysFilter: DaysFilterClass - @Environment(\.managedObjectContext) private var viewContext @AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true @@ -47,6 +45,7 @@ struct DayView: View { @State private var showTodayInput = true @State private var showUpdateEntryAlert = false @StateObject private var onboardingData = OnboardingDataDataManager.shared + @StateObject private var filteredDays = DaysFilterClass.shared // MARK: header properties @State private var headerHeight: CGFloat = DayViewConstants.maxHeaderHeight @@ -54,10 +53,10 @@ struct DayView: View { @State private var headerOpacity: Double = 1.0 // - @ObservedObject var viewModel: DayViewViewModel = DayViewViewModel(addMonthStartWeekdayPadding: false) + @ObservedObject var viewModel: DayViewViewModel var body: some View { - mainView + mainView .onAppear(perform: { EventLogger.log(event: "show_home_view") }) @@ -149,7 +148,7 @@ struct DayView: View { .background( theme.currentTheme.secondaryBGColor ) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) Spacer() } @@ -270,7 +269,7 @@ struct DayView: View { yOffset: value) } } - .cornerRadius(10, corners: [.topLeft, .topRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight]) } func getBackEntries() -> [MoodEntry] { @@ -300,7 +299,7 @@ extension DayView { ForEach(entries.sorted(by: { return $0.forDate! > $1.forDate! }), id: \.self) { entry in - if daysFilter.currentFilters.contains(Int(entry.weekDay)) { + if filteredDays.currentFilters.contains(Int(entry.weekDay)) { EntryListView(entry: entry) .contentShape(Rectangle()) .onTapGesture(perform: { diff --git a/Shared/views/EmptyView.swift b/Shared/views/EmptyView.swift index 9a077b2..3291de4 100644 --- a/Shared/views/EmptyView.swift +++ b/Shared/views/EmptyView.swift @@ -26,7 +26,7 @@ struct EmptyHomeView: View { } } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } } diff --git a/Shared/views/GraphView.swift b/Shared/views/GraphView.swift index bf82c6b..e62c58d 100644 --- a/Shared/views/GraphView.swift +++ b/Shared/views/GraphView.swift @@ -27,7 +27,7 @@ struct GraphView: View { BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10))) ]) } - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .padding() ZStack { @@ -40,7 +40,7 @@ struct GraphView: View { BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10))) ]) } - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .padding() } @@ -54,7 +54,7 @@ struct GraphView: View { BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10))) ]) } - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .padding() ZStack { @@ -67,7 +67,7 @@ struct GraphView: View { BarChartDataEntry(x: 5, y: Double(Int.random(in: 0...10))) ]) } - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .padding() } } diff --git a/Shared/views/MainTabView.swift b/Shared/views/MainTabView.swift index 838a182..7b89ba2 100644 --- a/Shared/views/MainTabView.swift +++ b/Shared/views/MainTabView.swift @@ -8,61 +8,61 @@ import SwiftUI struct MainTabView: View { - @EnvironmentObject var daysFilter: DaysFilterClass - @AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true - @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system - @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default let onboardingData = OnboardingDataDataManager.shared.savedOnboardingData + let dayView: DayView + let monthView: MonthView + let yearView: YearView + let customizeView: CustomizeView + var body: some View { - TabView { - DayView() + Self._printChanges() + return TabView { + dayView .tabItem { Label(String(localized: "content_view_tab_main"), systemImage: "list.dash") } - MonthView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: true)) + monthView .tabItem { Label(String(localized: "content_view_tab_month"), systemImage: "calendar") } - - YearView() + + yearView .tabItem { Label(String(localized: "content_view_tab_filter"), systemImage: "line.3.horizontal.decrease.circle") } - CustomizeView() + customizeView .tabItem { Label(String(localized: "content_view_tab_customize"), systemImage: "pencil") } } .accentColor(moodTint.color(forMood: .average)) - .sheet(isPresented: $needsOnboarding, onDismiss: { - - }, content: { + .sheet(isPresented: $needsOnboarding, onDismiss: { }, content: { OnboardingMain(onboardingData: onboardingData, updateBoardingDataClosure: { onboardingData in needsOnboarding = false OnboardingDataDataManager.shared.updateOnboardingData(onboardingData: onboardingData) }) }) - .onAppear(perform: { - switch theme { - case .system: - UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .unspecified - case .iFeel: - UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .unspecified - case .dark: - UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .dark - case .light: - UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .light - } + .onAppear(perform: { + switch theme { + case .system: + UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .unspecified + case .iFeel: + UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .unspecified + case .dark: + UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .dark + case .light: + UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .light + } }) - .onChange(of: theme, perform: { value in + .onChange(of: theme, perform: { value in switch theme { case .system: UIApplication.shared.windows.first?.overrideUserInterfaceStyle = .unspecified @@ -79,6 +79,9 @@ struct MainTabView: View { struct MainTabView_Previews: PreviewProvider { static var previews: some View { - MainTabView() + MainTabView(dayView: DayView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: false)), + monthView: MonthView(viewModel: DayViewViewModel(addMonthStartWeekdayPadding: true)), + yearView: YearView(viewModel: YearViewModel()), + customizeView: CustomizeView()) } } diff --git a/Shared/views/MonthView/MonthView.swift b/Shared/views/MonthView/MonthView.swift index 0056b87..8f38362 100644 --- a/Shared/views/MonthView/MonthView.swift +++ b/Shared/views/MonthView/MonthView.swift @@ -8,8 +8,6 @@ import SwiftUI struct MonthView: View { - @EnvironmentObject var daysFilter: DaysFilterClass - @AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system @@ -28,7 +26,8 @@ struct MonthView: View { @StateObject private var selectedDetail = StupidAssDetailViewObservableObject() @State private var showingSheet = false @StateObject private var onboardingData = OnboardingDataDataManager.shared - + @StateObject private var filteredDays = DaysFilterClass.shared + class StupidAssDetailViewObservableObject: ObservableObject { @Published var fuckingWrapped: MonthDetailView? = nil @Published var showFuckingSheet = false @@ -204,7 +203,7 @@ extension MonthView { Divider() LazyVGrid(columns: columns, spacing: 15) { ForEach(entries, id: \.self) { entry in - if daysFilter.currentFilters.contains(Int(entry.weekDay)) { + if filteredDays.currentFilters.contains(Int(entry.weekDay)) { shape.view(withText: Text(""), bgColor: entry.mood == .placeholder ? .clear : moodTint.color(forMood: entry.mood), textColor: .clear) diff --git a/Shared/views/SettingsView/SettingsView.swift b/Shared/views/SettingsView/SettingsView.swift index 19ee225..4ac501f 100644 --- a/Shared/views/SettingsView/SettingsView.swift +++ b/Shared/views/SettingsView/SettingsView.swift @@ -175,7 +175,7 @@ struct SettingsView: View { } } .frame(minWidth: 0, maxWidth: .infinity) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var addTestDataCell: some View { @@ -190,7 +190,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var clearDB: some View { @@ -205,7 +205,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var whyBackgroundMode: some View { @@ -229,7 +229,7 @@ struct SettingsView: View { } } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var showOnboardingButton: some View { @@ -245,7 +245,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var cloudKitEnable: some View { @@ -266,7 +266,7 @@ struct SettingsView: View { .padding(.bottom) } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var cloudKitStatus: some View { @@ -281,7 +281,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var canDelete: some View { @@ -298,7 +298,7 @@ struct SettingsView: View { } } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var exportData: some View { @@ -314,7 +314,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var importData: some View { @@ -330,7 +330,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } private var randomIcons: some View { @@ -461,7 +461,7 @@ struct SettingsView: View { .padding() } .fixedSize(horizontal: false, vertical: true) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } } diff --git a/Shared/views/Sharing/SharingListView.swift b/Shared/views/Sharing/SharingListView.swift index fb2df85..59a0e87 100644 --- a/Shared/views/Sharing/SharingListView.swift +++ b/Shared/views/Sharing/SharingListView.swift @@ -123,7 +123,7 @@ struct SharingListView: View { } } .frame(height: 88) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .scaledToFill() .clipped() .contentShape(Path(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 88))) diff --git a/Shared/views/SwitchableView.swift b/Shared/views/SwitchableView.swift index e6c9a95..8fccafd 100644 --- a/Shared/views/SwitchableView.swift +++ b/Shared/views/SwitchableView.swift @@ -98,7 +98,7 @@ struct SwitchableView: View { theme.currentTheme.secondaryBGColor ) .contentShape(Rectangle()) - .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) .padding(.bottom, 30) .onTapGesture { viewType = viewType.next() diff --git a/Shared/views/YearView/YearView.swift b/Shared/views/YearView/YearView.swift index da39646..0e7ad98 100644 --- a/Shared/views/YearView/YearView.swift +++ b/Shared/views/YearView/YearView.swift @@ -9,8 +9,6 @@ import SwiftUI import CoreData struct YearView: View { - @EnvironmentObject var daysFilter: DaysFilterClass - 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 @@ -24,7 +22,8 @@ struct YearView: View { @AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default @AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = DefaultTextColor.textColor - @StateObject private var viewModel = YearViewModel() + @StateObject public var viewModel: YearViewModel + @StateObject private var filteredDays = DaysFilterClass.shared //[ // 2001: [0: [], 1: [], 2: []], // 2002: [0: [], 1: [], 2: []] @@ -79,7 +78,7 @@ struct YearView: View { let yearEntries = PersistenceController.shared.getData(startDate: firstOfYear, endDate: lastOfYear, - includedDays: daysFilter.currentFilters) + includedDays: filteredDays.currentFilters) Text(String(yearKey)) .font(.title) .foregroundColor(textColor) @@ -144,14 +143,14 @@ struct YearView: View { } private struct monthGridView: View { - @EnvironmentObject var daysFilter: DaysFilterClass - + @StateObject private var filteredDays = DaysFilterClass.shared + let monthData: [DayChartView] var body: some View { VStack { ForEach(monthData, id: \.self) { view in - if daysFilter.currentFilters.contains(view.weekDay) { + if filteredDays.currentFilters.contains(view.weekDay) { view } else { view.filteredDaysView @@ -165,9 +164,9 @@ struct YearView: View { struct YearView_Previews: PreviewProvider { static var previews: some View { Group { - YearView() + YearView(viewModel: YearViewModel()) - YearView() + YearView(viewModel: YearViewModel()) .preferredColorScheme(.dark) } } diff --git a/Shared/views/YearView/YearViewModel.swift b/Shared/views/YearView/YearViewModel.swift index 973b975..3a6a72d 100644 --- a/Shared/views/YearView/YearViewModel.swift +++ b/Shared/views/YearView/YearViewModel.swift @@ -22,6 +22,10 @@ class YearViewModel: ObservableObject { } init() { + updateData() + } + + private func updateData() { let filteredEntries = PersistenceController.shared.getData(startDate: Date(timeIntervalSince1970: 0), endDate: Date(), includedDays: selectedDays)