From 6a8de0dc6d4f4bcb7b74478f85eddcb929215ce2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 22 Jan 2025 16:21:23 +0100 Subject: [PATCH] fix: preference to only store watch positions for video doesn't work --- .../main/java/com/github/libretube/helpers/PlayerHelper.kt | 5 ++++- .../com/github/libretube/services/AbstractPlayerService.kt | 5 ++++- .../github/libretube/ui/sheets/VideoOptionsBottomSheet.kt | 2 +- app/src/main/res/values/array.xml | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index 1a70db157..437784ae8 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -166,7 +166,10 @@ object PlayerHelper { get() = watchPositionsPref in listOf("always", "videos") val watchPositionsAudio: Boolean - get() = watchPositionsPref == "always" + get() = watchPositionsPref in listOf("always", "audio") + + val watchPositionsAny: Boolean + get() = watchPositionsVideo || watchPositionsAudio val watchHistoryEnabled: Boolean get() = PreferenceHelper.getBoolean( diff --git a/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt b/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt index 3b22b80a2..7f75dcb9d 100644 --- a/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/AbstractPlayerService.kt @@ -313,7 +313,10 @@ abstract class AbstractPlayerService : MediaLibraryService(), MediaLibrarySessio abstract suspend fun startPlayback() private fun saveWatchPosition() { - if (isTransitioning || !PlayerHelper.watchPositionsVideo) return + val watchPositionsEnabled = + (PlayerHelper.watchPositionsAudio && isAudioOnlyPlayer) || (PlayerHelper.watchPositionsVideo && !isAudioOnlyPlayer) + + if (isTransitioning || !watchPositionsEnabled) return exoPlayer?.let { PlayerHelper.saveWatchPosition(it, videoId) } } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt index 2b043e386..f23dd1d94 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt @@ -141,7 +141,7 @@ class VideoOptionsBottomSheet : BaseBottomSheet() { } // show the mark as watched or unwatched option if watch positions are enabled - if (PlayerHelper.watchPositionsVideo || PlayerHelper.watchHistoryEnabled) { + if (PlayerHelper.watchPositionsAny || PlayerHelper.watchHistoryEnabled) { val watchPositionEntry = runBlocking(Dispatchers.IO) { DatabaseHolder.Database.watchPositionDao().findById(videoId) } diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 413f484b2..98aee920a 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -439,12 +439,14 @@ @string/always @string/videos + @string/audio @string/never always videos + audio never