This commit is contained in:
Trey t
2022-02-18 18:58:38 -06:00
parent 065b7bcac1
commit 1cf38cb854
16 changed files with 501 additions and 176 deletions

View File

@@ -11,7 +11,6 @@
1C02589E27B9821700EB91AC /* CenterTiledImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C02589D27B9821700EB91AC /* CenterTiledImage.swift */; };
1C0DAB45279DB0FB003B1F21 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1C0DAB47279DB0FB003B1F21 /* Localizable.strings */; };
1C10E24E27A1AB110047948B /* UserDefaultsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */; };
1C10E24F27A1AB1D0047948B /* OnboardingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4975279C84090092F1B4 /* OnboardingData.swift */; };
1C10E25027A1AB220047948B /* OnboardingDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03774279A294800D26164 /* OnboardingDay.swift */; };
1C10E25127A1AB320047948B /* OnboardingTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03776279A295600D26164 /* OnboardingTitle.swift */; };
1C2618FA2795E41D00FDC148 /* Charts in Frameworks */ = {isa = PBXBuildFile; productRef = 1C2618F92795E41D00FDC148 /* Charts */; };
@@ -29,6 +28,11 @@
1C358FC227B4D227002C83A6 /* WeekTotalTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */; };
1C361F0A27C0356000E832FC /* HomeViewTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C361F0927C0356000E832FC /* HomeViewTwo.swift */; };
1C361F0C27C0356B00E832FC /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C361F0B27C0356B00E832FC /* MainTabView.swift */; };
1C361F0D27C03BDF00E832FC /* OnboardingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4975279C84090092F1B4 /* OnboardingData.swift */; };
1C361F0F27C03C0E00E832FC /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B75278C8119001C4FEA /* LocalNotification.swift */; };
1C361F1127C03C3D00E832FC /* OnboardingTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CA03772279A293D00D26164 /* OnboardingTime.swift */; };
1C361F1427C03C8600E832FC /* OnboardingDataDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C361F1327C03C8600E832FC /* OnboardingDataDataManager.swift */; };
1C361F1727C046D800E832FC /* MonthDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C361F1627C046D800E832FC /* MonthDetailView.swift */; };
1C4FF3BB27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BA27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift */; };
1C4FF3BC27BEDF6600BE8F34 /* ShowBasedOnVoteLogics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BA27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift */; };
1C4FF3BE27BEDF9100BE8F34 /* PersistenceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BD27BEDF9100BE8F34 /* PersistenceHelper.swift */; };
@@ -41,6 +45,8 @@
1C4FF3C927BEE0C300BE8F34 /* PersistenceHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4FF3BD27BEDF9100BE8F34 /* PersistenceHelper.swift */; };
1C5F4976279C84090092F1B4 /* OnboardingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4975279C84090092F1B4 /* OnboardingData.swift */; };
1C5F4978279C945E0092F1B4 /* UserDefaultsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */; };
1C658D7727C0744D003231EE /* PersistenceUPDATE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C658D7627C0744D003231EE /* PersistenceUPDATE.swift */; };
1C658D7827C0744D003231EE /* PersistenceUPDATE.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C658D7627C0744D003231EE /* PersistenceUPDATE.swift */; };
1C683FCA2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; };
1C683FCB2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; };
1C683FCC2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; };
@@ -75,7 +81,6 @@
1CD90B16278C7DE0001C4FEA /* Feels.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90AEB278C7DDF001C4FEA /* Feels.xcdatamodeld */; };
1CD90B17278C7DE0001C4FEA /* Feels.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90AEB278C7DDF001C4FEA /* Feels.xcdatamodeld */; };
1CD90B18278C7DE0001C4FEA /* FeelsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90AED278C7DDF001C4FEA /* FeelsApp.swift */; };
1CD90B19278C7DE0001C4FEA /* FeelsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90AED278C7DDF001C4FEA /* FeelsApp.swift */; };
1CD90B1C278C7DE0001C4FEA /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90AEF278C7DDF001C4FEA /* Persistence.swift */; };
1CD90B1E278C7DE0001C4FEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1CD90AF0278C7DE0001C4FEA /* Assets.xcassets */; };
1CD90B1F278C7DE0001C4FEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1CD90AF0278C7DE0001C4FEA /* Assets.xcassets */; };
@@ -99,7 +104,6 @@
1CD90B6E278C7F8B001C4FEA /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CD90B6B278C7F78001C4FEA /* CloudKit.framework */; };
1CD90B71278C80CA001C4FEA /* Feels.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90AEB278C7DDF001C4FEA /* Feels.xcdatamodeld */; };
1CD90B76278C8119001C4FEA /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B75278C8119001C4FEA /* LocalNotification.swift */; };
1CD90B77278C8119001C4FEA /* LocalNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD90B75278C8119001C4FEA /* LocalNotification.swift */; };
1CEC966F27B9C29300CC8688 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CEC966E27B9C29300CC8688 /* IconView.swift */; };
1CEC967127B9C2BB00CC8688 /* CustomIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CEC967027B9C2BB00CC8688 /* CustomIcon.swift */; };
1CEC967227B9C9FB00CC8688 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CEC966E27B9C29300CC8688 /* IconView.swift */; };
@@ -163,6 +167,8 @@
1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekTotalTemplate.swift; sourceTree = "<group>"; };
1C361F0927C0356000E832FC /* HomeViewTwo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewTwo.swift; sourceTree = "<group>"; };
1C361F0B27C0356B00E832FC /* MainTabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabView.swift; sourceTree = "<group>"; };
1C361F1327C03C8600E832FC /* OnboardingDataDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingDataDataManager.swift; sourceTree = "<group>"; };
1C361F1627C046D800E832FC /* MonthDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthDetailView.swift; sourceTree = "<group>"; };
1C4FF3BA27BEDDF000BE8F34 /* ShowBasedOnVoteLogics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowBasedOnVoteLogics.swift; sourceTree = "<group>"; };
1C4FF3BD27BEDF9100BE8F34 /* PersistenceHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistenceHelper.swift; sourceTree = "<group>"; };
1C4FF3BF27BEE06900BE8F34 /* PersistenceGET.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistenceGET.swift; sourceTree = "<group>"; };
@@ -170,6 +176,7 @@
1C4FF3C627BEE09E00BE8F34 /* PersistenceADD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistenceADD.swift; sourceTree = "<group>"; };
1C5F4975279C84090092F1B4 /* OnboardingData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingData.swift; sourceTree = "<group>"; };
1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsStore.swift; sourceTree = "<group>"; };
1C658D7627C0744D003231EE /* PersistenceUPDATE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistenceUPDATE.swift; sourceTree = "<group>"; };
1C683FC92792281400745862 /* Stats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stats.swift; sourceTree = "<group>"; };
1C744F2B278CE15600953A57 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
1CA0376F2799FFA600D26164 /* ContentModeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentModeViewModel.swift; sourceTree = "<group>"; };
@@ -294,6 +301,15 @@
path = SharingTemplates;
sourceTree = "<group>";
};
1C361F1827C046E400E832FC /* HomeViewTwo */ = {
isa = PBXGroup;
children = (
1C361F0927C0356000E832FC /* HomeViewTwo.swift */,
1C361F1627C046D800E832FC /* MonthDetailView.swift */,
);
path = HomeViewTwo;
sourceTree = "<group>";
};
1C4FF3C527BEE07800BE8F34 /* Persisence */ = {
isa = PBXGroup;
children = (
@@ -302,6 +318,7 @@
1C4FF3C227BEE07200BE8F34 /* PersistenceDELETE.swift */,
1C4FF3BF27BEE06900BE8F34 /* PersistenceGET.swift */,
1C4FF3BD27BEDF9100BE8F34 /* PersistenceHelper.swift */,
1C658D7627C0744D003231EE /* PersistenceUPDATE.swift */,
);
path = Persisence;
sourceTree = "<group>";
@@ -333,14 +350,14 @@
1C358FB927B35252002C83A6 /* ActivityViewController.swift */,
1CAD602F27A5C1C800C520BD /* AddMoodHeaderView.swift */,
1CAD603127A5C1C800C520BD /* BGView.swift */,
1CAD603227A5C1C800C520BD /* HomeView.swift */,
1C02589B27B9677A00EB91AC /* CreateIconView.swift */,
1CB101C427B62A2D00D1C033 /* EmptyView.swift */,
1CAD602E27A5C1C800C520BD /* FilterView.swift */,
1CAD602D27A5C1C800C520BD /* GraphView.swift */,
1CAD603027A5C1C800C520BD /* HeaderPercView.swift */,
1CAD603327A5C1C800C520BD /* HeaderStatsView.swift */,
1C361F0927C0356000E832FC /* HomeViewTwo.swift */,
1CAD603227A5C1C800C520BD /* HomeView.swift */,
1C361F1827C046E400E832FC /* HomeViewTwo */,
1CEC966E27B9C29300CC8688 /* IconView.swift */,
1C361F0B27C0356B00E832FC /* MainTabView.swift */,
1CAD602C27A5C1C800C520BD /* SettingsView.swift */,
@@ -462,6 +479,7 @@
1CD90B61278C7EBA001C4FEA /* Mood.swift */,
1CD90B62278C7EBA001C4FEA /* MoodEntryExtension.swift */,
1CB101C627B81CAC00D1C033 /* MoodMetrics.swift */,
1C361F1327C03C8600E832FC /* OnboardingDataDataManager.swift */,
1C358FAC27ADD0C3002C83A6 /* Theme.swift */,
1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */,
);
@@ -703,7 +721,9 @@
1CB101C527B62A2D00D1C033 /* EmptyView.swift in Sources */,
1CB101C727B81CAC00D1C033 /* MoodMetrics.swift in Sources */,
1CAD603627A5C1C800C520BD /* GraphView.swift in Sources */,
1C361F1727C046D800E832FC /* MonthDetailView.swift in Sources */,
1CD90B66278C7EBA001C4FEA /* MoodEntryExtension.swift in Sources */,
1C658D7727C0744D003231EE /* PersistenceUPDATE.swift in Sources */,
1C358FB327B0ADA4002C83A6 /* SharingTemplate.swift in Sources */,
1C358FB827B0AEE3002C83A6 /* LongestStreakTemplate.swift in Sources */,
1C358FB127B0AD87002C83A6 /* SharingListView.swift in Sources */,
@@ -719,6 +739,7 @@
1C361F0C27C0356B00E832FC /* MainTabView.swift in Sources */,
1CEC967127B9C2BB00CC8688 /* CustomIcon.swift in Sources */,
1C361F0A27C0356000E832FC /* HomeViewTwo.swift in Sources */,
1C361F1427C03C8600E832FC /* OnboardingDataDataManager.swift in Sources */,
1C358FAD27ADD0C3002C83A6 /* Theme.swift in Sources */,
1C02589C27B9677A00EB91AC /* CreateIconView.swift in Sources */,
1C358FC227B4D227002C83A6 /* WeekTotalTemplate.swift in Sources */,
@@ -732,8 +753,6 @@
1CD90B64278C7EBA001C4FEA /* Mood.swift in Sources */,
1CD90B17278C7DE0001C4FEA /* Feels.xcdatamodeld in Sources */,
1CD90B67278C7EBA001C4FEA /* MoodEntryExtension.swift in Sources */,
1CD90B77278C8119001C4FEA /* LocalNotification.swift in Sources */,
1CD90B19278C7DE0001C4FEA /* FeelsApp.swift in Sources */,
1CD90B5E278C7EAD001C4FEA /* Random.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -762,6 +781,7 @@
buildActionMask = 2147483647;
files = (
1CD90B65278C7EBA001C4FEA /* Mood.swift in Sources */,
1C361F1127C03C3D00E832FC /* OnboardingTime.swift in Sources */,
1CEC967227B9C9FB00CC8688 /* IconView.swift in Sources */,
1C4FF3BC27BEDF6600BE8F34 /* ShowBasedOnVoteLogics.swift in Sources */,
1C4FF3C927BEE0C300BE8F34 /* PersistenceHelper.swift in Sources */,
@@ -769,6 +789,7 @@
1CD90B5F278C7EAD001C4FEA /* Random.swift in Sources */,
1CD90B68278C7EBA001C4FEA /* MoodEntryExtension.swift in Sources */,
1CD90B71278C80CA001C4FEA /* Feels.xcdatamodeld in Sources */,
1C658D7827C0744D003231EE /* PersistenceUPDATE.swift in Sources */,
1C10E25127A1AB320047948B /* OnboardingTitle.swift in Sources */,
1CB101C827B81CAC00D1C033 /* MoodMetrics.swift in Sources */,
1C683FCB2792281400745862 /* Stats.swift in Sources */,
@@ -777,9 +798,10 @@
1C4FF3C427BEE07200BE8F34 /* PersistenceDELETE.swift in Sources */,
1C4FF3C827BEE09E00BE8F34 /* PersistenceADD.swift in Sources */,
1C4FF3C127BEE06900BE8F34 /* PersistenceGET.swift in Sources */,
1C10E24F27A1AB1D0047948B /* OnboardingData.swift in Sources */,
1C361F0D27C03BDF00E832FC /* OnboardingData.swift in Sources */,
1CD90B52278C7E7A001C4FEA /* FeelsWidget.intentdefinition in Sources */,
1CD90B4D278C7E7A001C4FEA /* FeelsWidget.swift in Sources */,
1C361F0F27C03C0E00E832FC /* LocalNotification.swift in Sources */,
1C10E24E27A1AB110047948B /* UserDefaultsStore.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -10,9 +10,10 @@ import CoreData
class ContentModeViewModel: ObservableObject {
@Published var grouped = [Int: [Int: [MoodEntry]]]()
@Published public private(set) var savedOnboardingData = UserDefaultsStore.getOnboarding()
@Published var numberOfItems = 0
let addMonthStartWeekdayPadding: Bool
var hasNoData: Bool {
grouped.isEmpty
}
@@ -35,60 +36,66 @@ class ContentModeViewModel: ObservableObject {
// }.reduce(0, +)
}
init() {
init(addMonthStartWeekdayPadding: Bool) {
self.addMonthStartWeekdayPadding = addMonthStartWeekdayPadding
PersistenceController.shared.switchContainerListeners.append {
self.getGroupedData()
self.getGroupedData(addMonthStartWeekdayPadding: self.addMonthStartWeekdayPadding)
}
updateData()
}
private func getGroupedData() {
private func getGroupedData(addMonthStartWeekdayPadding: Bool) {
grouped = PersistenceController.shared.splitIntoYearMonth()
if addMonthStartWeekdayPadding {
var newGrouped = [Int: [Int: [MoodEntry]]]()
let allYears = grouped.keys.sorted(by: > )
for year in allYears {
var newMonth = [Int: [MoodEntry]]()
let oldMonths = grouped[year]!
let monthKeys = oldMonths.keys.sorted(by: > )
for key in monthKeys {
if let entries = oldMonths[key] {
let sortedEntries = entries.sorted(by: { $0.forDate! < $1.forDate! })
var mutableEntries = sortedEntries
if let firstDate = sortedEntries.first {
let date = firstDate.forDate!
let weekday = Int16(Calendar.current.component(.weekday, from: date))
for _ in 1..<weekday {
mutableEntries.insert(PersistenceController.shared.generateObjectNotInArray(), at: 0)
}
}
newMonth[key] = mutableEntries
}
newGrouped[year] = newMonth
}
}
grouped = newGrouped
}
numberOfItems = numberOfEntries
}
public func updateOnboardingData(onboardingData: OnboardingData) {
self.savedOnboardingData = UserDefaultsStore.saveOnboarding(onboardingData: onboardingData)
LocalNotification.scheduleReminder(atTime: onboardingData.date, withTitle: onboardingData.title)
}
public func updateData() {
getGroupedData()
getGroupedData(addMonthStartWeekdayPadding: self.addMonthStartWeekdayPadding)
}
public func add(mood: Mood, forDate date: Date, entryType: EntryType) {
PersistenceController.shared.add(mood: mood, forDate: date, entryType: entryType)
getGroupedData()
updateData()
}
public func update(entry: MoodEntry, toMood mood: Mood) {
let forDate = entry.forDate!
if let entry = PersistenceController.shared.getEntry(byDate: entry.forDate!) {
PersistenceController.shared.viewContext.delete(entry)
}
do {
try PersistenceController.shared.viewContext.save()
getGroupedData()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
PersistenceController.shared.add(mood: mood, forDate: forDate, entryType: .listView)
do {
try PersistenceController.shared.viewContext.save()
getGroupedData()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
if PersistenceController.shared.update(entryDate: entry.forDate!, withModd: mood) {
updateData()
}
}
@@ -112,7 +119,7 @@ class ContentModeViewModel: ObservableObject {
do {
try PersistenceController.shared.viewContext.save()
getGroupedData()
updateData()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
@@ -120,4 +127,27 @@ class ContentModeViewModel: ObservableObject {
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
}
static func updateTitleHeader(forEntry entry: MoodEntry?) -> String {
guard let entry = entry else {
return ""
}
guard let forDate = entry.forDate else {
return ""
}
let components = Calendar.current.dateComponents([.day, .month, .year], from: forDate)
// let day = components.day!
let month = components.month!
let year = components.year!
let monthName = Random.monthName(fromMonthInt: month)
let weekday = Random.weekdayName(fromDate:entry.forDate!)
let dayz = Random.dayFormat(fromDate:entry.forDate!)
let string = weekday + " " + monthName + " " + dayz + " " + String(year)
return String(format: String(localized: "content_view_fill_in_missing_entry"), string)
}
}

View File

@@ -15,6 +15,7 @@ enum Mood: Int {
case good
case great
case missing
case placeholder
var strValue: String {
switch self {
@@ -30,6 +31,8 @@ enum Mood: Int {
return String(localized: "mood_value_great")
case .missing:
return String(localized: "mood_value_missing")
case .placeholder:
return String("placeholder")
}
}
@@ -47,6 +50,8 @@ enum Mood: Int {
return .green
case .missing:
return Color(uiColor: UIColor.systemGray2)
case .placeholder:
return .clear
}
}
@@ -69,6 +74,8 @@ enum Mood: Int {
return Image("great", bundle: .main)
case .missing:
return Image("missing", bundle: .main)
case .placeholder:
return Image("missing", bundle: .main)
}
}
@@ -87,6 +94,8 @@ enum Mood: Int {
return Image("GreatGraphic", bundle: .main)
case .missing:
return Image("MissingGraphic", bundle: .main)
case .placeholder:
return Image("MissingGraphic", bundle: .main)
}
}
}

View File

@@ -0,0 +1,19 @@
//
// OnboardingDataDataManager.swift
// Feels (iOS)
//
// Created by Trey Tartt on 2/18/22.
//
import Foundation
final class OnboardingDataDataManager {
static let shared = OnboardingDataDataManager()
@Published public private(set) var savedOnboardingData = UserDefaultsStore.getOnboarding()
public func updateOnboardingData(onboardingData: OnboardingData) {
let onboardingData = UserDefaultsStore.saveOnboarding(onboardingData: onboardingData)
LocalNotification.scheduleReminder(atTime: onboardingData.date, withTitle: onboardingData.title)
}
}

View File

@@ -6,6 +6,7 @@
//
import Foundation
import UserNotifications
// this is getting passed around and filled out
// class and vars

View File

@@ -21,7 +21,8 @@ struct OnboardingMain: View {
OnboardingTitle(onboardingData: onboardingData)
OnboardingWrapup(onboardingData: onboardingData, completionClosure: { _ in
OnboardingWrapup(onboardingData: onboardingData,
completionClosure: { _ in
updateBoardingDataClosure(onboardingData)
})
}

View File

@@ -51,6 +51,17 @@ extension PersistenceController {
}
}
func generateObjectNotInArray() -> MoodEntry {
let newItem = MoodEntry(context: childContext)
newItem.timestamp = Date()
newItem.moodValue = Int16(Mood.placeholder.rawValue)
newItem.forDate = Date()
newItem.weekDay = Int16(Calendar.current.component(.weekday, from: Date()))
newItem.canEdit = false
newItem.canDelete = false
return newItem
}
func populateTestData() {
for idx in 1..<120 {
let newItem = MoodEntry(context: viewContext)

View File

@@ -0,0 +1,40 @@
//
// PersistenceUPDATE.swift
// Feels
//
// Created by Trey Tartt on 2/18/22.
//
import Foundation
extension PersistenceController {
@discardableResult
public func update(entryDate: Date, withModd mood: Mood) -> Bool {
if let entry = PersistenceController.shared.getEntry(byDate: entryDate) {
viewContext.delete(entry)
}
do {
try PersistenceController.shared.viewContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
return false
}
add(mood: mood, forDate: entryDate, entryType: .listView)
do {
try viewContext.save()
return true
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
return false
}
}
}

View File

@@ -18,6 +18,8 @@ struct GroupUserDefaults {
}
}
typealias MoodGroupingMetrics = (mood: Mood, total: Int, percent: Float)
class Random {
static var tomorrowMidnightThirty: Date {
let components = DateComponents(hour: 0, minute: 30, second: 0)
@@ -49,6 +51,25 @@ class Random {
formatter.numberStyle = .ordinal
return formatter.string(from: NSNumber(integerLiteral: day)) ?? ""
}
static func createTotalPerc(fromEntries entries: [MoodEntry]) -> [MoodGroupingMetrics] {
var returnData = [MoodGroupingMetrics]()
for (_, mood) in Mood.allValues.enumerated() {
let moodEntries = entries.filter({
Int($0.moodValue) == mood.rawValue
})
let total = moodEntries.count
let perc = (Float(total) / Float(entries.count)) * 100
returnData.append((mood, total, perc))
}
returnData = returnData.sorted(by: {
$0.0.rawValue > $1.0.rawValue
})
return returnData
}
}
extension Date: RawRepresentable {

View File

@@ -40,6 +40,6 @@ struct EmptyHomeView: View {
struct EmptyHomeView_Previews: PreviewProvider {
static var previews: some View {
EmptyHomeView(viewModel: ContentModeViewModel())
EmptyHomeView(viewModel: ContentModeViewModel(addMonthStartWeekdayPadding: false))
}
}

View File

@@ -17,8 +17,6 @@ struct HomeViewConstants {
struct HomeView: View {
@Environment(\.managedObjectContext) private var viewContext
@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.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -46,7 +44,7 @@ struct HomeView: View {
@State private var headerOpacity: Double = 1.0
//
@ObservedObject var viewModel = ContentModeViewModel()
@ObservedObject var viewModel = ContentModeViewModel(addMonthStartWeekdayPadding: false)
init(){
UIPageControl.appearance().currentPageIndicatorTintColor = UIColor.label
@@ -56,7 +54,7 @@ struct HomeView: View {
var body: some View {
mainView
.alert(updateTitleHeader(forEntry: selectedEntry),
.alert(ContentModeViewModel.updateTitleHeader(forEntry: selectedEntry),
isPresented: $showUpdateEntryAlert) {
ForEach(Mood.allValues) { mood in
Button(mood.strValue, action: {
@@ -112,30 +110,7 @@ struct HomeView: View {
// SCROLLING DOWN
headerHeight = newValue
}
private func updateTitleHeader(forEntry entry: MoodEntry?) -> String {
guard let entry = entry else {
return ""
}
guard let forDate = entry.forDate else {
return ""
}
let components = Calendar.current.dateComponents([.day, .month, .year], from: forDate)
// let day = components.day!
let month = components.month!
let year = components.year!
let monthName = Random.monthName(fromMonthInt: month)
let weekday = Random.weekdayName(fromDate:entry.forDate!)
let dayz = Random.dayFormat(fromDate:entry.forDate!)
let string = weekday + " " + monthName + " " + dayz + " " + String(year)
return String(format: String(localized: "content_view_fill_in_missing_entry"), string)
}
// MARK: Views
public var mainView: some View {
VStack {
@@ -153,8 +128,7 @@ struct HomeView: View {
.opacity(headerOpacity)
VStack {
SmallRollUpHeaderView(fakeData: false,
backDays: $currentSelectedHeaderViewBackDays,
SmallRollUpHeaderView(entries: getBackEntries(),
viewType: $currentSelectedHeaderViewViewType)
.background(
Color(theme.currentTheme.secondaryBGColor)
@@ -200,7 +174,7 @@ struct HomeView: View {
viewModel.updateData()
}
}, updateBoardingDataClosure: { onboardingData in
viewModel.updateOnboardingData(onboardingData: onboardingData)
OnboardingDataDataManager.shared.updateOnboardingData(onboardingData: onboardingData)
})
}.padding(.trailing)
}
@@ -293,6 +267,13 @@ struct HomeView: View {
}
.cornerRadius(10, corners: [.topLeft, .topRight])
}
func getBackEntries() -> [MoodEntry] {
var daysAgo = Calendar.current.date(byAdding: .day, value: -self.currentSelectedHeaderViewBackDays, to: Date())!
daysAgo = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: daysAgo)!
return PersistenceController.shared.getData(startDate: daysAgo, endDate: Date(), includedDays: [1,2,3,4,5,6,7])
}
}
// view that make up the list body

View File

@@ -1,20 +0,0 @@
//
// HomeViewTwo.swift
// Feels (iOS)
//
// Created by Trey Tartt on 2/18/22.
//
import SwiftUI
struct HomeViewTwo: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
struct HomeViewTwo_Previews: PreviewProvider {
static var previews: some View {
HomeViewTwo()
}
}

View File

@@ -0,0 +1,110 @@
//
// HomeViewTwo.swift
// Feels (iOS)
//
// Created by Trey Tartt on 2/18/22.
//
import SwiftUI
struct HomeViewTwo: View {
@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
@ObservedObject var viewModel = ContentModeViewModel(addMonthStartWeekdayPadding: true)
@StateObject private var selectedDetail = StupidAssDetailViewObservableObject()
class StupidAssDetailViewObservableObject: ObservableObject {
@Published var fuckingWrapped: MonthDetailView? = nil
@Published var showFuckingSheet = false
}
let columns = [
GridItem(.flexible(minimum: 5, maximum: 400)),
GridItem(.flexible(minimum: 5, maximum: 400)),
GridItem(.flexible(minimum: 5, maximum: 400)),
GridItem(.flexible(minimum: 5, maximum: 400)),
GridItem(.flexible(minimum: 5, maximum: 400)),
GridItem(.flexible(minimum: 5, maximum: 400)),
GridItem(.flexible(minimum: 5, maximum: 400))
]
var body: some View {
ScrollView {
topView
.frame(maxWidth: .infinity, alignment: .leading)
.frame(height: 200)
.background(
.blue
)
LazyVStack(spacing: 5, pinnedViews: [.sectionHeaders]) {
ForEach(viewModel.grouped.sorted(by: { $0.key > $1.key }), id: \.key) { year, months in
// for reach month
ForEach(months.sorted(by: { $0.key > $1.key }), id: \.key) { month, entries in
Section(header: homeViewTwoSectionHeaderView(month: month, year: year)) {
homeViewTwoMonthListView(month: month, year: year, entries: entries)
}
.onTapGesture{
let deailView = MonthDetailView(monthInt: month,
yearInt: year,
entries: entries)
selectedDetail.fuckingWrapped = deailView
selectedDetail.showFuckingSheet = true
}
}
.padding(.bottom)
}
}
.padding([.leading, .trailing])
}.sheet(isPresented: $selectedDetail.showFuckingSheet,
onDismiss: didDismiss) {
selectedDetail.fuckingWrapped
}
}
func didDismiss() {
selectedDetail.showFuckingSheet = false
selectedDetail.fuckingWrapped = nil
}
}
extension HomeViewTwo {
private var topView: some View {
HStack {
Text("dis top")
}
}
}
// view that make up the list body
extension HomeViewTwo {
private func homeViewTwoSectionHeaderView(month: Int, year: Int) -> some View {
Text("\(Random.monthName(fromMonthInt: month)) \(String(year))")
.font(.body)
.foregroundColor(Color(UIColor.label))
.frame(maxWidth: .infinity, alignment: .leading)
.background(
Color(theme.currentTheme.secondaryBGColor)
)
}
private func homeViewTwoMonthListView(month: Int, year: Int, entries: [MoodEntry]) -> some View {
LazyVGrid(columns: columns, spacing: 15) {
ForEach(entries, id: \.self) { entry in
Circle()
.foregroundColor(entry.mood.color)
.frame(minHeight: 5, idealHeight: 20, maxHeight: 50, alignment: .center)
}
}
}
}
struct HomeViewTwo_Previews: PreviewProvider {
static var previews: some View {
HomeViewTwo()
}
}

View File

@@ -0,0 +1,122 @@
//
// MonthDetailView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 2/18/22.
//
import SwiftUI
struct MonthDetailView: View {
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@AppStorage(UserDefaultsStore.Keys.deleteEnable.rawValue, store: GroupUserDefaults.groupDefaults) private var deleteEnabled = true
@State private var showingUpdateEntryAlert = false
let monthInt: Int
let yearInt: Int
let entries: [MoodEntry]
lazy var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd"
return dateFormatter
}()
let columns = [
GridItem(.flexible(minimum: 5, maximum: 50)),
GridItem(.flexible(minimum: 5, maximum: 50)),
GridItem(.flexible(minimum: 5, maximum: 50)),
GridItem(.flexible(minimum: 5, maximum: 50)),
GridItem(.flexible(minimum: 5, maximum: 50)),
GridItem(.flexible(minimum: 5, maximum: 50)),
GridItem(.flexible(minimum: 5, maximum: 50))
]
var body: some View {
VStack {
Text("\(Random.monthName(fromMonthInt: monthInt)) \(String(yearInt))")
.font(.title)
.foregroundColor(Color(UIColor.label))
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(
Color(theme.currentTheme.secondaryBGColor)
)
ScrollView {
LazyVGrid(columns: columns, spacing: 25) {
ForEach(entries, id: \.self) { entry in
VStack {
if entry.mood != .placeholder {
Text(entry.forDate!,
format: Date.FormatStyle().day())
.font(.title3)
.foregroundColor(Color(UIColor.label))
entry.mood.icon
.resizable()
.frame(minWidth: 5,
maxWidth: 50,
minHeight: 5,
maxHeight: 50,
alignment: .center)
.aspectRatio(contentMode: .fit)
.foregroundColor(entry.mood.color)
}
}
.alert(ContentModeViewModel.updateTitleHeader(forEntry: entry),
isPresented: $showingUpdateEntryAlert) {
ForEach(Mood.allValues) { mood in
Button(mood.strValue, action: {
PersistenceController.shared.update(entryDate: entry.forDate!, withModd: mood)
// viewModel.update(entry: selectedEntry, toMood: mood)
})
}
if deleteEnabled,
entry.mood != .missing {
Button(String(localized: "content_view_delete_entry"), action: {
PersistenceController.shared.update(entryDate: entry.forDate!, withModd: Mood.missing)
// viewModel.update(entry: selectedEntry, toMood: Mood.missing)
})
}
Button(String(localized: "content_view_fill_in_missing_entry_cancel"), role: .cancel, action: {
})
}
}
}
}
.padding([.leading, .trailing])
monthDetails
.frame(maxWidth: .infinity, alignment: .leading)
.background(
Color(theme.currentTheme.secondaryBGColor)
)
}
}
private var monthDetails: some View {
VStack {
SmallRollUpHeaderView(entries: entries,
viewType: .constant(.total))
SmallRollUpHeaderView(entries: entries,
viewType: .constant(.percentageCircle))
.padding(.top, -20)
}
.padding()
}
}
struct MonthDetailView_Previews: PreviewProvider {
static var previews: some View {
MonthDetailView(monthInt: 5, yearInt: 2022, entries:
PersistenceController.shared.randomEntries(count: 30).sorted(by: {
$0.forDate! < $1.forDate!
}))
}
}

View File

@@ -9,10 +9,16 @@ import SwiftUI
struct MainTabView: View {
@AppStorage(UserDefaultsStore.Keys.needsOnboarding.rawValue, store: GroupUserDefaults.groupDefaults) private var needsOnboarding = true
@ObservedObject var viewModel = ContentModeViewModel()
let onboardingData = OnboardingDataDataManager.shared.savedOnboardingData
var body: some View {
TabView {
HomeViewTwo()
.tabItem {
Label(String(localized: "content_view_tab_main"), systemImage: "list.dash")
}
HomeView()
.tabItem {
Label(String(localized: "content_view_tab_main"), systemImage: "list.dash")
@@ -30,10 +36,10 @@ struct MainTabView: View {
}.sheet(isPresented: $needsOnboarding, onDismiss: {
}, content: {
OnboardingMain(onboardingData: viewModel.savedOnboardingData,
OnboardingMain(onboardingData: onboardingData,
updateBoardingDataClosure: { onboardingData in
needsOnboarding = false
viewModel.updateOnboardingData(onboardingData: onboardingData)
OnboardingDataDataManager.shared.updateOnboardingData(onboardingData: onboardingData)
})
})
}

View File

@@ -9,47 +9,18 @@ import SwiftUI
struct SmallRollUpHeaderView: View {
@Binding var viewType: MainSwitchableViewType
@Binding var backDays: Int
typealias Model = (mood: Mood, total: Int, percent: Float)
private var entries = [Model]()
let entries: [MoodEntry]
private var moodMetrics = [MoodGroupingMetrics]()
init(fakeData: Bool, backDays: Binding<Int>, viewType: Binding<MainSwitchableViewType>) {
init(entries: [MoodEntry], viewType: Binding<MainSwitchableViewType>) {
self.entries = entries
self._viewType = viewType
self._backDays = backDays
var moodEntries: [MoodEntry]?
if fakeData {
moodEntries = PersistenceController.shared.randomEntries(count: 10)
} else {
var daysAgo = Calendar.current.date(byAdding: .day, value: -self.backDays, to: Date())!
daysAgo = Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: daysAgo)!
moodEntries = PersistenceController.shared.getData(startDate: daysAgo, endDate: Date(), includedDays: [1,2,3,4,5,6,7])
}
let totalEntryCount = moodEntries?.count ?? 0
if let moodEntries = moodEntries {
for (_, mood) in Mood.allValues.enumerated() {
let moodEntries = moodEntries.filter({
Int($0.moodValue) == mood.rawValue
})
let total = moodEntries.count
let perc = (Float(total) / Float(totalEntryCount)) * 100
entries.append((mood, total, perc))
}
}
entries = entries.sorted(by: {
$0.0.rawValue > $1.0.rawValue
})
moodMetrics = Random.createTotalPerc(fromEntries: entries)
}
private func textView(forModel model: Model) -> Text {
private func textView(forModel model: MoodGroupingMetrics) -> Text {
switch viewType {
case .total:
return Text(String(model.total))
@@ -60,12 +31,43 @@ struct SmallRollUpHeaderView: View {
}
}
private var modelTextViews: some View {
private var textViews: some View {
HStack {
ForEach(entries, id: \.0) { model in
ForEach(moodMetrics, id: \.0) { model in
textView(forModel: model)
.font(.title2)
.fontWeight(.bold)
.lineLimit(1)
.foregroundColor(model.mood.color)
.frame(width: 70, height: 70)
}
}
.padding([.top, .bottom])
}
private var circularViews: some View {
HStack {
ForEach(moodMetrics, id: \.0) { model in
ZStack {
Circle().fill(model.mood.color)
.frame(minWidth: 5,
maxWidth: 70,
minHeight: 5,
maxHeight: 70,
alignment: .center)
.overlay(
textView(forModel: model)
.font(.title3)
.fontWeight(.bold)
.lineLimit(1)
.clipShape(ContainerRelativeShape()).padding()
.foregroundColor(Color(UIColor.white))
.minimumScaleFactor(0.1)
)
}
}
}
.padding([.top, .bottom])
}
private var viewOnViewtype : some View {
@@ -79,51 +81,21 @@ struct SmallRollUpHeaderView: View {
}
}
private var textViews: some View {
HStack {
ForEach(entries, id: \.0) { model in
textView(forModel: model)
.font(.title2)
.fontWeight(.bold)
.lineLimit(1)
.foregroundColor(model.mood.color)
.frame(width: 50, height: 50)
}
}
.padding([.top, .bottom])
}
private var circularViews: some View {
HStack {
ForEach(entries, id: \.0) { model in
ZStack {
Circle().fill(model.mood.color)
.frame(width: 50, height: 50)
textView(forModel: model)
.font(.title3)
.fontWeight(.bold)
.frame(width: 40, height: 40)
.scaledToFill()
.minimumScaleFactor(0.5)
.lineLimit(1)
.foregroundColor(Color(UIColor.white))
}
}
}
.padding([.top, .bottom])
}
var body: some View {
viewOnViewtype
.frame(minWidth: 0, maxWidth: .infinity)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
struct SmallHeaderView_Previews: PreviewProvider {
static var previews: some View {
SmallRollUpHeaderView(fakeData: true, backDays: .constant(30), viewType: .constant(.total))
SmallRollUpHeaderView(fakeData: true, backDays: .constant(7), viewType: .constant(.total))
Group {
SmallRollUpHeaderView(entries: PersistenceController.shared.randomEntries(count: 10),
viewType: .constant(.total))
SmallRollUpHeaderView(entries: PersistenceController.shared.randomEntries(count: 10),
viewType: .constant(.total))
.frame(height: 20)
}
}
}