From 9d91530a3e937f06cac6810909b24dc54e476c9a Mon Sep 17 00:00:00 2001 From: Nishant Mishra Date: Tue, 9 Dec 2025 18:40:11 +0530 Subject: [PATCH] fix(service): disable autostart of next session if alarm was stopped due to timeout --- .../java/org/nsh07/pomodoro/service/TimerService.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 88aa940..7f7ae42 100644 --- a/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt +++ b/app/src/main/java/org/nsh07/pomodoro/service/TimerService.kt @@ -430,7 +430,7 @@ class TimerService : Service() { autoAlarmStopScope = CoroutineScope(Dispatchers.IO).launch { delay(1 * 60 * 1000) - stopAlarm() + stopAlarm(fromAutoStop = true) } if (settingsState.vibrateEnabled) { @@ -444,7 +444,13 @@ class TimerService : Service() { } } - fun stopAlarm() { + /** + * Stops ringing the alarm and vibration, and performs related necessary actions + * + * @param fromAutoStop Whether the function was triggered automatically by the program instead of + * intentionally by the user + */ + fun stopAlarm(fromAutoStop: Boolean = false) { val settingsState = _settingsState.value autoAlarmStopScope?.cancel() @@ -474,7 +480,8 @@ class TimerService : Service() { }, paused = true, complete = false ) - if (settingsState.autostartNextSession) toggleTimer() + if (settingsState.autostartNextSession && !fromAutoStop) // auto start next session + toggleTimer() } private fun initializeMediaPlayer(): MediaPlayer? {