fix: Filling empty data for days when app was not opened not working for more than 1 month
This commit is contained in:
@@ -32,6 +32,7 @@ import org.nsh07.pomodoro.data.StatRepository
|
|||||||
import org.nsh07.pomodoro.data.TimerRepository
|
import org.nsh07.pomodoro.data.TimerRepository
|
||||||
import org.nsh07.pomodoro.utils.millisecondsToStr
|
import org.nsh07.pomodoro.utils.millisecondsToStr
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
import java.time.temporal.ChronoUnit
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
class TimerViewModel(
|
class TimerViewModel(
|
||||||
@@ -101,10 +102,11 @@ class TimerViewModel(
|
|||||||
val today = LocalDate.now()
|
val today = LocalDate.now()
|
||||||
|
|
||||||
// Fills dates between today and lastDate with 0s to ensure continuous history
|
// Fills dates between today and lastDate with 0s to ensure continuous history
|
||||||
while ((lastDate?.until(today)?.days ?: -1) > 0) {
|
if (lastDate != null)
|
||||||
lastDate = lastDate?.plusDays(1)
|
while (ChronoUnit.DAYS.between(lastDate, today) > 0) {
|
||||||
statRepository.insertStat(Stat(lastDate!!, 0, 0, 0, 0, 0))
|
lastDate = lastDate?.plusDays(1)
|
||||||
}
|
statRepository.insertStat(Stat(lastDate!!, 0, 0, 0, 0, 0))
|
||||||
|
}
|
||||||
|
|
||||||
delay(1500)
|
delay(1500)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user