change a bunch of shit to get importing / adding new vote have the right weekday

This commit is contained in:
Trey t
2022-04-05 22:33:12 -05:00
parent dec8f2d84d
commit 6fa4e2db26
17 changed files with 141 additions and 190 deletions

View File

@@ -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"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -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)
}
}
}

View File

@@ -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)
}
}
}

View File

@@ -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<MoodEntry>(entityName: "MoodEntry")
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "forDate", ascending: false)]

View File

@@ -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<MoodEntry>(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<MoodEntry>(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")
}
}
}

View File

@@ -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)
}
}

View File

@@ -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: {

View File

@@ -20,7 +20,6 @@ struct MainTabView: View {
let customizeView: CustomizeView
var body: some View {
Self._printChanges()
return TabView {
dayView
.tabItem {

View File

@@ -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)

View File

@@ -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