diff --git a/FeelsWidget/Assets.xcassets/default_image/xmark-solid.imageset/Contents.json b/FeelsWidget/Assets.xcassets/default_image/xmark-solid.imageset/Contents.json new file mode 100644 index 0000000..29e51cc --- /dev/null +++ b/FeelsWidget/Assets.xcassets/default_image/xmark-solid.imageset/Contents.json @@ -0,0 +1,24 @@ +{ + "images" : [ + { + "filename" : "xmark-solid.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/FeelsWidget/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid.png b/FeelsWidget/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid.png new file mode 100644 index 0000000..686a37b Binary files /dev/null and b/FeelsWidget/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid.png differ diff --git a/FeelsWidget/FeelsWidget.swift b/FeelsWidget/FeelsWidget.swift index 507ab01..8458fa7 100644 --- a/FeelsWidget/FeelsWidget.swift +++ b/FeelsWidget/FeelsWidget.swift @@ -32,7 +32,7 @@ struct TimeLineCreator { var timeLineView = [WatchTimelineView]() var startDayOffset = 0 - if !ShowBasedOnVoteLogics.ableToVoteBasedOnCurentTime(voteDate: UserDefaultsStore.getOnboarding().date) { + if !ShowBasedOnVoteLogics.passedTodaysVotingUnlock(voteDate: UserDefaultsStore.getOnboarding().date) { startDayOffset = 1 } diff --git a/Shared/AppDelegate.swift b/Shared/AppDelegate.swift index a60eb9e..4d00513 100644 --- a/Shared/AppDelegate.swift +++ b/Shared/AppDelegate.swift @@ -58,15 +58,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if let action = LocalNotification.ActionType(rawValue: response.actionIdentifier) { - var date: Date - - switch savedOnboardingData.inputDay { - case .Today: - date = Date() - case .Previous: - date = Calendar.current.date(byAdding: .day, value: -1, to: Date())! - } - + let date = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: savedOnboardingData) switch action { case .horrible: PersistenceController.shared.add(mood: .horrible, forDate: date, entryType: .notification) diff --git a/Shared/Assets.xcassets/default_image/xmark-solid.imageset/Contents.json b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/Contents.json new file mode 100644 index 0000000..142b7c8 --- /dev/null +++ b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "filename" : "xmark-solid.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "xmark-solid@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "xmark-solid@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid.png b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid.png new file mode 100644 index 0000000..686a37b Binary files /dev/null and b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid.png differ diff --git a/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid@2x.png b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid@2x.png new file mode 100644 index 0000000..83ab452 Binary files /dev/null and b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid@2x.png differ diff --git a/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid@3x.png b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid@3x.png new file mode 100644 index 0000000..00c61b2 Binary files /dev/null and b/Shared/Assets.xcassets/default_image/xmark-solid.imageset/xmark-solid@3x.png differ diff --git a/Shared/Models/MoodImagable.swift b/Shared/Models/MoodImagable.swift index ec44d81..398de35 100644 --- a/Shared/Models/MoodImagable.swift +++ b/Shared/Models/MoodImagable.swift @@ -54,9 +54,9 @@ final class FontAwesomeMoodImages: MoodImagable { case .great: return Image("great", bundle: .main) case .missing: - return Image("missing", bundle: .main) + return Image("xmark-solid", bundle: .main) case .placeholder: - return Image("missing", bundle: .main) + return Image("xmark-solid", bundle: .main) } } } @@ -75,9 +75,9 @@ final class EmojiMoodImages: MoodImagable { case .great: return Image(uiImage: "😀".textToImage()!) case .missing: - return Image("x-solid", bundle: .main) + return Image("xmark-solid", bundle: .main) case .placeholder: - return Image("x-solid", bundle: .main) + return Image("xmark-solid", bundle: .main) } } } @@ -96,9 +96,9 @@ final class HandEmojiMoodImages: MoodImagable { case .great: return Image(uiImage: "🙏".textToImage()!) case .missing: - return Image("x-solid", bundle: .main) + return Image("xmark-solid", bundle: .main) case .placeholder: - return Image("x-solid", bundle: .main) + return Image("xmark-solid", bundle: .main) } } } diff --git a/Shared/Models/MoodTintable.swift b/Shared/Models/MoodTintable.swift index d9280dc..d01f621 100644 --- a/Shared/Models/MoodTintable.swift +++ b/Shared/Models/MoodTintable.swift @@ -160,9 +160,9 @@ final class DefaultMoodTint: MoodTintable { case .great: return Color(hex: "31d158") case .missing: - return Color(uiColor: UIColor.lightGray) + return Color(uiColor: UIColor.systemGray2) case .placeholder: - return Color(uiColor: UIColor.lightGray) + return Color(uiColor: UIColor.systemGray2) } } @@ -179,9 +179,9 @@ final class DefaultMoodTint: MoodTintable { case .great: return Color(hex: "208939") case .missing: - return Color(uiColor: UIColor.lightGray) + return Color(uiColor: UIColor.label) case .placeholder: - return Color(uiColor: UIColor.lightGray) + return Color(uiColor: UIColor.label) } } } @@ -322,7 +322,7 @@ final class PastelTint: MoodTintable { case .missing: return Color(uiColor: UIColor.systemGray2) case .placeholder: - return Color(uiColor: UIColor.systemGray4) + return Color(uiColor: UIColor.systemGray2) } } @@ -339,9 +339,9 @@ final class PastelTint: MoodTintable { case .great: return Color(hex: "#6b7e6d") case .missing: - return Color(uiColor: UIColor.systemGray2) + return Color(uiColor: UIColor.label) case .placeholder: - return Color(uiColor: UIColor.systemGray4) + return Color(uiColor: UIColor.label) } } } diff --git a/Shared/Persisence/PersistenceADD.swift b/Shared/Persisence/PersistenceADD.swift index 78f3e26..ea7e0be 100644 --- a/Shared/Persisence/PersistenceADD.swift +++ b/Shared/Persisence/PersistenceADD.swift @@ -16,8 +16,7 @@ extension PersistenceController { }) data.forEach({ - $0.weekDay = Int16(Calendar.current.component(.weekday, from: $0.forDate!.startOfDay)) - $0.forDate = $0.forDate?.startOfDay + $0.weekDay = Int16(Calendar.current.component(.weekday, from: $0.forDate!)) }) try? viewContext.save() } @@ -32,10 +31,7 @@ extension PersistenceController { newItem.timestamp = Date() newItem.moodValue = Int16(mood.rawValue) newItem.forDate = date - - let localTime = date.toLocalTime() - newItem.weekDay = Int16(Calendar.current.component(.weekday, from: localTime)) - + newItem.weekDay = Int16(Calendar.current.component(.weekday, from: date)) newItem.canEdit = true newItem.canDelete = true newItem.entryType = Int16(entryType.rawValue) @@ -47,7 +43,9 @@ extension PersistenceController { func fillInMissingDates() { let currentOnboarding = UserDefaultsStore.getOnboarding() - let endDate = ShowBasedOnVoteLogics.getLastDateVoteShouldExist(onboardingData: currentOnboarding) + var endDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: currentOnboarding) + // since its for views take away the last date so vote is enabled + endDate = Calendar.current.date(byAdding: .day, value: -1, to: endDate)! let fetchRequest = NSFetchRequest(entityName: "MoodEntry") fetchRequest.sortDescriptors = [NSSortDescriptor(key: "forDate", ascending: false)] diff --git a/Shared/ShowBasedOnVoteLogics.swift b/Shared/ShowBasedOnVoteLogics.swift index 8e8ec46..bb6a2c5 100644 --- a/Shared/ShowBasedOnVoteLogics.swift +++ b/Shared/ShowBasedOnVoteLogics.swift @@ -28,147 +28,14 @@ import SwiftUI */ class ShowBasedOnVoteLogics { - static func returnCurrentVoteStatus(onboardingData: OnboardingData) -> (Bool, DayOptions) { - let passedTimeToVote = ShowBasedOnVoteLogics.ableToVoteBasedOnCurentTime(voteDate: onboardingData.date) + static private func returnCurrentVoteStatus(onboardingData: OnboardingData) -> (Bool, DayOptions) { + let passedTimeToVote = ShowBasedOnVoteLogics.passedTodaysVotingUnlock(voteDate: onboardingData.date) let inputDay: DayOptions = onboardingData.inputDay return (passedTimeToVote, inputDay) } - static func getLastDateVoteShouldExistOnViews(onboardingData: OnboardingData) -> Date { - var date: Date? - - switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { - case (false, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -2, to: Date()) - case (true, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be today - date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) - - case (false, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -2 - date = Calendar.current.date(byAdding: .day, value: -3, to: Date()) - case (true, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -2, to: Date()) - } - - guard let date = date else { - fatalError("missing getCurrentVotingDate") - } - - return date - } - - static func getCurrentVotingDate(onboardingData: OnboardingData) -> Date { - var date: Date? - - switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { - case (false, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) - case (true, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be today - date = Date() - - case (false, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -2 - date = Calendar.current.date(byAdding: .day, value: -2, to: Date()) - case (true, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) - } - - guard let date = date else { - fatalError("missing getCurrentVotingDate") - } - - return date - } - - static func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool { - let startDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: onboardingData).startOfDay - let endDate = startDate.endOfDay - - let fetchRequest = NSFetchRequest(entityName: "MoodEntry") - let fromPredicate = NSPredicate(format: "%@ <= %K", startDate - as NSDate, #keyPath(MoodEntry.forDate)) - let toPredicate = NSPredicate(format: "%K < %@", #keyPath(MoodEntry.forDate), endDate as NSDate) - let datePredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [fromPredicate, toPredicate]) - fetchRequest.predicate = datePredicate - let entries = try! PersistenceController.shared.viewContext.count(for: fetchRequest) - - return entries < 1 - } - - static func getVotingTitle(onboardingData: OnboardingData) -> String { - switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { - case (false, .Today): - return String(localized: "add_mood_header_view_title_yesterday") - case (true, .Today): - return String(localized: "add_mood_header_view_title_today") - - case (false, .Previous): - let date = Calendar.current.date(byAdding: .day, value: -2, to: Date())! - return String(format: String(localized: "add_mood_header_view_title"), Random.weekdayName(fromDate: date)) - case (true, .Previous): - return String(localized: "add_mood_header_view_title_yesterday") - } - } - - - /*---------------------------delete---------------------------------------*/ - - static func dateForHeaderVote(onboardingData: OnboardingData) -> Date? { - var date: Date? - - switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { - case (false, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) - case (true, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be today - date = Date() - - case (false, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -2 - date = Calendar.current.date(byAdding: .day, value: -2, to: Date()) - case (true, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) - } - - if let date = date { - return date - } - - return nil - } - - static func getLastDateVoteShouldExist(onboardingData: OnboardingData) -> Date { - var date: Date? - - switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { - case (false, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be -2 - date = Calendar.current.date(byAdding: .day, value: -2, to: Date())! - case (true, .Today): - // if we're passed time to vote and the voting type is previous - last vote should be -1 - date = Calendar.current.date(byAdding: .day, value: -1, to: Date())! - - case (false, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should be -3 - date = Calendar.current.date(byAdding: .day, value: -3, to: Date())! - case (true, .Previous): - // if we're passed time to vote and the voting type is previous - last vote should -2 - date = Calendar.current.date(byAdding: .day, value: -2, to: Date())! - } - - return date! - } - - static func ableToVoteBasedOnCurentTime(voteDate: Date) -> Bool { + static public func passedTodaysVotingUnlock(voteDate: Date) -> Bool { let currentDateComp = Calendar.current.dateComponents([.hour, .minute], from: Date()) let savedDateComp = Calendar.current.dateComponents([.hour, .minute], from: voteDate) @@ -189,5 +56,60 @@ class ShowBasedOnVoteLogics { return false } - + static public func isMissingCurrentVote(onboardingData: OnboardingData) -> Bool { + let startDate = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: onboardingData).startOfDay + let endDate = startDate.endOfDay + + let fetchRequest = NSFetchRequest(entityName: "MoodEntry") + let fromPredicate = NSPredicate(format: "%@ <= %K", startDate + as NSDate, #keyPath(MoodEntry.forDate)) + let toPredicate = NSPredicate(format: "%K < %@", #keyPath(MoodEntry.forDate), endDate as NSDate) + let datePredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [fromPredicate, toPredicate]) + fetchRequest.predicate = datePredicate + let entries = try! PersistenceController.shared.viewContext.count(for: fetchRequest) + + return entries < 1 + } + + static public func getCurrentVotingDate(onboardingData: OnboardingData) -> Date { + var date: Date? + // note to future self, this should account for midnight until next voting unlock + // the vote at 12:03 am will not be passed time, and will be for yesterday + switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { + case (false, .Today): + // if we're passed time to vote and the voting type is previous - last vote should be -1 + date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) + case (true, .Today): + // if we're passed time to vote and the voting type is previous - last vote should be today + date = Date() + + case (false, .Previous): + // if we're passed time to vote and the voting type is previous - last vote should be -2 + date = Calendar.current.date(byAdding: .day, value: -2, to: Date()) + case (true, .Previous): + // if we're passed time to vote and the voting type is previous - last vote should be -1 + date = Calendar.current.date(byAdding: .day, value: -1, to: Date()) + } + + guard let date = date else { + fatalError("missing getCurrentVotingDate") + } + + return date + } + + static public func getVotingTitle(onboardingData: OnboardingData) -> String { + switch ShowBasedOnVoteLogics.returnCurrentVoteStatus(onboardingData: onboardingData) { + case (false, .Today): + return String(localized: "add_mood_header_view_title_yesterday") + case (true, .Today): + return String(localized: "add_mood_header_view_title_today") + + case (false, .Previous): + let date = Calendar.current.date(byAdding: .day, value: -2, to: Date())! + return String(format: String(localized: "add_mood_header_view_title"), Random.weekdayName(fromDate: date)) + case (true, .Previous): + return String(localized: "add_mood_header_view_title_yesterday") + } + } } diff --git a/Shared/views/AddMoodHeaderView.swift b/Shared/views/AddMoodHeaderView.swift index bf89566..a7d492c 100644 --- a/Shared/views/AddMoodHeaderView.swift +++ b/Shared/views/AddMoodHeaderView.swift @@ -60,9 +60,8 @@ struct AddMoodHeaderView: View { } private func addItem(withMood mood: Mood) { - if let date = ShowBasedOnVoteLogics.dateForHeaderVote(onboardingData: onboardingData) { - addItemHeaderClosure(mood, date) - } + let date = ShowBasedOnVoteLogics.getCurrentVotingDate(onboardingData: onboardingData) + addItemHeaderClosure(mood, date) } } diff --git a/Shared/views/DayView/DayView.swift b/Shared/views/DayView/DayView.swift index d185131..286af45 100644 --- a/Shared/views/DayView/DayView.swift +++ b/Shared/views/DayView/DayView.swift @@ -187,7 +187,7 @@ struct DayView: View { private var headerView: some View { VStack { - if ShowBasedOnVoteLogics.isMissingCurrentVote(onboardingData: onboardingData.savedOnboardingData) { + if ShowBasedOnVoteLogics.isMissingCurrentVote(onboardingData: UserDefaultsStore.getOnboarding()) { AddMoodHeaderView(addItemHeaderClosure: { (mood, date) in viewModel.add(mood: mood, forDate: date, entryType: .header) }) @@ -300,6 +300,7 @@ extension DayView { return $0.forDate! > $1.forDate! }), id: \.self) { entry in if filteredDays.currentFilters.contains(Int(entry.weekDay)) { +// let _ = print(entry.forDate, entry.weekDay, filteredDays.currentFilters) EntryListView(entry: entry) .contentShape(Rectangle()) .onTapGesture(perform: { diff --git a/Shared/views/MainTabView.swift b/Shared/views/MainTabView.swift index 7b89ba2..59e74bf 100644 --- a/Shared/views/MainTabView.swift +++ b/Shared/views/MainTabView.swift @@ -20,7 +20,6 @@ struct MainTabView: View { let customizeView: CustomizeView var body: some View { - Self._printChanges() return TabView { dayView .tabItem { diff --git a/Shared/views/MonthView/MonthView.swift b/Shared/views/MonthView/MonthView.swift index 2a8d82e..47caf14 100644 --- a/Shared/views/MonthView/MonthView.swift +++ b/Shared/views/MonthView/MonthView.swift @@ -109,16 +109,6 @@ struct MonthView: View { } extension MonthView { - private var topView: some View { - VStack { - if ShowBasedOnVoteLogics.isMissingCurrentVote(onboardingData: onboardingData.savedOnboardingData) { - Text("Vote") - } - Text("dis top") - .foregroundColor(theme.currentTheme.secondaryBGColor) - } - } - private var settingsButtonView: some View { HStack { Spacer() @@ -204,7 +194,6 @@ extension MonthView { LazyVGrid(columns: columns, spacing: 15) { ForEach(entries, id: \.self) { entry in if filteredDays.currentFilters.contains(Int(entry.weekDay)) { - let _ = print(entry.weekDay, entry.forDate, filteredDays.currentFilters, entry.id) 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 15add4c..c3eccd8 100644 --- a/Shared/views/SettingsView/SettingsView.swift +++ b/Shared/views/SettingsView/SettingsView.swift @@ -95,7 +95,7 @@ struct SettingsView: View { guard let selectedFile: URL = try result.get().first else { return } if selectedFile.startAccessingSecurityScopedResource() { let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss +0000" + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" dateFormatter.timeZone = TimeZone(abbreviation: "UTC") guard let input = String(data: try Data(contentsOf: selectedFile), encoding: .utf8) else { return } @@ -104,7 +104,8 @@ struct SettingsView: View { var rows = input.components(separatedBy: "\n") rows.removeFirst() for row in rows { - let columns = row.components(separatedBy: ",") + let stripped = row.replacingOccurrences(of: " +0000", with: "") + let columns = stripped.components(separatedBy: ",") if columns.count != 7 { continue } @@ -112,13 +113,13 @@ struct SettingsView: View { moodEntry.canDelete = Bool(columns[0])! moodEntry.canEdit = Bool(columns[1])! moodEntry.entryType = Int16(columns[2])! - moodEntry.forDate = dateFormatter.date(from: columns[3]) + moodEntry.forDate = dateFormatter.date(from: columns[3])! moodEntry.moodValue = Int16(columns[4])! - moodEntry.timestamp = dateFormatter.date(from: columns[5]) + moodEntry.timestamp = dateFormatter.date(from: columns[5])! - let localTime = dateFormatter.date(from: columns[3])!.toLocalTime() + 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))) try! PersistenceController.shared.viewContext.save() } PersistenceController.shared.saveAndRunDataListerners() @@ -508,7 +509,7 @@ 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