From e7e03697d6e05f43e9766c2320a23535802ab60e Mon Sep 17 00:00:00 2001 From: Nicholas Wallace Date: Sun, 2 Feb 2025 12:49:08 -0700 Subject: [PATCH 1/3] Fix: shake to reset only during grace period or while playing --- .../com/audiobookshelf/app/managers/SleepTimerManager.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt index 43ab6980d..ddf4aa4b1 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt @@ -343,9 +343,12 @@ constructor(private val playerNotificationService: PlayerNotificationService) { } } - /** Handles the shake event to reset the sleep timer. */ + /** + * Handles the shake event to reset the sleep timer. Shaking to reset only works during the 2 + * minute grace period after the timer ends or while media is playing. + */ fun handleShake() { - if (sleepTimerRunning || sleepTimerFinishedAt > 0L) { + if ((sleepTimerRunning && getIsPlaying()) || sleepTimerFinishedAt > 0L) { if (DeviceManager.deviceData.deviceSettings?.disableShakeToResetSleepTimer == true) { Log.d(tag, "Shake to reset sleep timer is disabled") return From 5fd21c83937faecc6ac3ecede262ab8ef4fa973d Mon Sep 17 00:00:00 2001 From: Nicholas Wallace Date: Sun, 2 Feb 2025 13:00:28 -0700 Subject: [PATCH 2/3] Change: sleep timer EoC cutoff to be 10 seconds --- .../com/audiobookshelf/app/managers/SleepTimerManager.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt index ddf4aa4b1..98fbff470 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt @@ -276,8 +276,11 @@ constructor(private val playerNotificationService: PlayerNotificationService) { } val timeLeftInChapter = currentChapterEndTimeMs - getCurrentTime() - return if (timeLeftInChapter < 2000L) { - Log.i(tag, "Getting chapter sleep timer time and current chapter has less than 2s remaining") + // If less than 10 seconds remain in the chapter, set the timer to the next chapter or track + // This handles the auto-rewind from not playing media for a little bit to select the next + // chapter + return if (timeLeftInChapter < 10000L) { + Log.i(tag, "Getting chapter sleep timer time and current chapter has less than 10s remaining") val nextChapterEndTimeMs = playerNotificationService.getEndTimeOfNextChapterOrTrack() if (nextChapterEndTimeMs == null || currentChapterEndTimeMs == nextChapterEndTimeMs) { Log.e( From e4e76794146c2b92b5d7c260ac84cd8595eec262 Mon Sep 17 00:00:00 2001 From: Nicholas Wallace Date: Sun, 2 Feb 2025 14:23:58 -0700 Subject: [PATCH 3/3] Fix: sleep timer gets stuck at 1 second --- .../audiobookshelf/app/managers/SleepTimerManager.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt index 98fbff470..c7b7aaa43 100644 --- a/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt +++ b/android/app/src/main/java/com/audiobookshelf/app/managers/SleepTimerManager.kt @@ -264,7 +264,7 @@ constructor(private val playerNotificationService: PlayerNotificationService) { } /** - * Gets the chapter end time for use in End of Chapter timers. If less than 2 seconds remain in + * Gets the chapter end time for use in End of Chapter timers. If less than 10 seconds remain in * the chapter, then use the next chapter. * @return Long? - the chapter end time in milliseconds, or null if there is no current session. */ @@ -335,6 +335,14 @@ constructor(private val playerNotificationService: PlayerNotificationService) { return } + // If timer was cleared by going negative on time, clear the sleep timer length so pressing + // play allows playback to continue without the sleep timer continuously setting for 1 second. + if (sleepTimerLength == 1000L) { + Log.d(tag, "Sleep timer cleared by manually subtracting time, clearing sleep timer") + sleepTimerFinishedAt = 0L + return + } + // Automatically rewind in the book if settings are enabled tryRewindAutoSleepTimer() @@ -466,7 +474,7 @@ constructor(private val playerNotificationService: PlayerNotificationService) { // Start an auto sleep timer val currentHour = currentCalendar.get(Calendar.HOUR_OF_DAY) val currentMin = currentCalendar.get(Calendar.MINUTE) - Log.i(tag, "Starting sleep timer at $currentHour:$currentMin") + Log.i(tag, "Starting auto sleep timer at $currentHour:$currentMin") // Automatically rewind in the book if settings is enabled tryRewindAutoSleepTimer()