diff --git a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt index a3c348c..bd69f62 100644 --- a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt +++ b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt @@ -69,6 +69,8 @@ class TimerService : Service() { private val cs by lazy { timerRepository.colorScheme } + private lateinit var notificationStyle: NotificationCompat.ProgressStyle + override fun onBind(intent: Intent?): IBinder? { return null } @@ -101,6 +103,8 @@ class TimerService : Service() { } private fun toggleTimer() { + updateProgressSegments() + if (timerState.value.timerRunning) { notificationBuilder.clearActions().addTimerActions( this, R.drawable.play, "Start" @@ -194,42 +198,7 @@ class TimerService : Service() { ) .setContentText("Up next: $nextTimer (${timerState.value.nextTimeStr})") .setStyle( - NotificationCompat.ProgressStyle() - .also { - // Add all the Focus, Short break and long break intervals in order - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { - // Android 16 and later supports live updates - // Set progress bar sections if on Baklava or later - for (i in 0.. timerRepository.focusTime.toInt() - TimerMode.SHORT_BREAK -> timerRepository.shortBreakTime.toInt() - else -> timerRepository.longBreakTime.toInt() - } - ) - ) - } - } + notificationStyle .setProgress( // Set the current progress by filling the previous intervals and part of the current interval if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { (totalTime - remainingTime) + ((cycles + 1) / 2) * timerRepository.focusTime.toInt() + (cycles / 2) * timerRepository.shortBreakTime.toInt() @@ -249,6 +218,45 @@ class TimerService : Service() { } } + private fun updateProgressSegments() { + notificationStyle = NotificationCompat.ProgressStyle() + .also { + // Add all the Focus, Short break and long break intervals in order + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) { + // Android 16 and later supports live updates + // Set progress bar sections if on Baklava or later + for (i in 0.. timerRepository.focusTime.toInt() + TimerMode.SHORT_BREAK -> timerRepository.shortBreakTime.toInt() + else -> timerRepository.longBreakTime.toInt() + } + ) + ) + } + } + } + private fun resetTimer() { skipScope.launch { saveTimeToDb()