Skip to content

Commit

Permalink
fix: can not auto switch to next Pomo
Browse files Browse the repository at this point in the history
  • Loading branch information
odeinjul committed Aug 16, 2023
1 parent 02e0fdc commit 30adb34
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Pomodomo/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
"size" : "256x256"
},
{
"filename" : "Icon.png",
"filename" : "Icon 1.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "Icon 1.png",
"filename" : "Icon.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
Expand Down
Binary file modified Pomodomo/Assets.xcassets/AppIcon.appiconset/Icon 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Pomodomo/Assets.xcassets/AppIcon.appiconset/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Pomodomo/Assets.xcassets/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Pomodomo/Model/PomodomoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Pomodomo: ObservableObject{
self.timeTotal = 25 * 60.0
self.color = Color("PomoRed")
case .SmallRelax:
self.timeTotal = 5 * 60.0
self.timeTotal = 4//5 * 60.0
self.color = Color("PomoGreen")
case .LongRelax:
self.timeTotal = 15 * 60.0
Expand All @@ -55,7 +55,7 @@ class Pomodomo: ObservableObject{
self.timeTotal = 25 * 60.0
self.color = Color("PomoRed")
case .SmallRelax:
self.timeTotal = 5 * 60.0
self.timeTotal = 4//5 * 60.0
self.color = Color("PomoGreen")
case .LongRelax:
self.timeTotal = 15 * 60.0
Expand Down
14 changes: 8 additions & 6 deletions Pomodomo/View/PomodomoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ struct PomodomoTextView: View {
}
Text("\(secondsToHoursMinutesSeconds(Int(pomodomoCurrent.timeTotal - pomodomoCurrent.timePassed)))")
.onReceive(timer) { _ in
if (pomodomoCurrent.timePassed <= pomodomoCurrent.timeTotal && !stop) {
//print(pomodomoCurrent.timePassed)
if (pomodomoCurrent.timePassed < pomodomoCurrent.timeTotal && !stop) {
pomodomoCurrent.timePassed += 1.0
print("\(pomodomoCurrent.timePassed)")
}
else if(pomodomoCurrent.timePassed == pomodomoCurrent.timeTotal) {
do{
Expand All @@ -169,7 +169,9 @@ struct PomodomoTextView: View {
}catch{
print("Failed to play sound")
}
addRecord(context: context, date: Date.now, count: 1, time: 25)
if(pomodomoCurrent.type == PomodomoType.Pomo) {
addRecord(context: context, date: Date.now, count: 1, time: 25)
}
NextPomo(pomodomoCurrent: pomodomoCurrent, stop: &stop, colorChangeAction: colorChangeAction)
}
}
Expand All @@ -181,6 +183,7 @@ struct PomodomoTextView: View {
}

func NextPomo (pomodomoCurrent: Pomodomo, stop: inout Bool, colorChangeAction: @escaping (Color) -> Void)-> Void {
stop = true
pomodomoCount += 1
pomodomoCount %= 8
if (pomodomoCount == 7) {
Expand All @@ -191,8 +194,9 @@ func NextPomo (pomodomoCurrent: Pomodomo, stop: inout Bool, colorChangeAction:
pomodomoCurrent.setType(.SmallRelax)
}
timerColor = pomodomoCurrent.color
pomodomoCurrent.timePassed = 0
/*
withAnimation {
withAnimation {
colorChangeAction(timerColor)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
Expand All @@ -201,8 +205,6 @@ func NextPomo (pomodomoCurrent: Pomodomo, stop: inout Bool, colorChangeAction:
}
}
*/

stop = true
}

struct PomodomoView_Previews: PreviewProvider {
Expand Down
31 changes: 17 additions & 14 deletions Pomodomo/View/StaticsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ struct StaticsView: View {
var calendar = Calendar(identifier: .gregorian)

var body: some View {
/*
VStack {
StaticsYearView()

Button("Add") {
addRecord(context: context, date: Date.now, count: 1, time: 25)
}
Expand All @@ -25,7 +27,9 @@ struct StaticsView: View {
}
print("HI")
}
}

}*/
StaticsYearView()
}
}

Expand Down Expand Up @@ -55,19 +59,19 @@ func fetchRecordsForPastWeek(day: Date, context: NSManagedObjectContext) -> [Dou


let components = calendar.dateComponents([.year, .weekOfYear, .weekday], from: day)
print("---")
print(day)
print((components.weekday! - 1))
//print("---")
//print(day)
//print((components.weekday! - 1))
guard let startDate = calendar.date(byAdding: .day, value: -(components.weekday! - 1), to: day) else {
print("Error calculating start date.")
//print("Error calculating start date.")
return []
}
guard let endDate = calendar.date(byAdding: .day, value: 7, to: startDate) else {
print("Error calculating end date.")
//xprint("Error calculating end date.")
return []
}
print(startDate)
print(endDate)
//print(startDate)
//print(endDate)


let fetchRequest: NSFetchRequest<PomoCount> = PomoCount.fetchRequest()
Expand All @@ -78,16 +82,16 @@ func fetchRecordsForPastWeek(day: Date, context: NSManagedObjectContext) -> [Dou
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
dateFormatter.timeZone = TimeZone.current // Replace with the desired time zone
let weekRecord = (1...7).map { index in
print("---")
//print("---")
let date = calendar.date(byAdding: .day, value: index, to: startDate)!
let dayRecord = records.filter {
calendar.timeZone = TimeZone.current;
print("date0: \(dateFormatter.string(from: $0.date!))");
print(calendar.isDate($0.date!, equalTo: date, toGranularity: .day));
//print("date0: \(dateFormatter.string(from: $0.date!))");
//print(calendar.isDate($0.date!, equalTo: date, toGranularity: .day));
return calendar.isDate($0.date!, equalTo: date, toGranularity: .day) }
print("date: \(dateFormatter.string(from: date))")
//print("date: \(dateFormatter.string(from: date))")
//print((dayRecord.first != nil) ? dayRecord.first!.date : 0)
print(Double((dayRecord.first != nil) ? dayRecord.first!.time : 0))
//print(Double((dayRecord.first != nil) ? dayRecord.first!.time : 0))
if (date > Date()) {
return -1.0
}
Expand Down Expand Up @@ -115,7 +119,6 @@ struct StaticsYearView: View {
let startDate = Calendar.current.date(byAdding: .day, value: -subDay, to: Date())
let records = fetchRecordsForPastWeek(day: startDate!, context: context)
StaticsColumnView(intensities: records)
//Text("\(startDate!)")
}
Spacer()
}
Expand Down

0 comments on commit 30adb34

Please sign in to comment.