From f6aa7efeed620ed126b12a24e5e48df94b9917ec Mon Sep 17 00:00:00 2001 From: Clar Fon <15850505+clarfonthey@users.noreply.github.com> Date: Sat, 8 Mar 2025 05:38:46 -0500 Subject: [PATCH] fix: bound time remaining to mark a video as watched (#7173) --- .../java/com/github/libretube/db/DatabaseHelper.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt index 59470c3f6..09f5b952e 100644 --- a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt +++ b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt @@ -15,6 +15,12 @@ import kotlinx.coroutines.withContext object DatabaseHelper { private const val MAX_SEARCH_HISTORY_SIZE = 20 + // can only mark as watched if less than 60s remaining + private const val ABSOLUTE_WATCHED_THRESHOLD = 60.0f + + // can only mark as watched if at least 75% watched + private const val RELATIVE_WATCHED_THRESHOLD = 0.75f + suspend fun addToWatchHistory(watchHistoryItem: WatchHistoryItem) = withContext(Dispatchers.IO) { Database.watchHistoryDao().insert(watchHistoryItem) @@ -79,8 +85,8 @@ object DatabaseHelper { if (durationSeconds == null) return false val progress = positionMillis / 1000 - // show video only in feed when watched less than 90% - return progress > 0.9f * durationSeconds + + return durationSeconds - progress <= ABSOLUTE_WATCHED_THRESHOLD && progress >= RELATIVE_WATCHED_THRESHOLD * durationSeconds } suspend fun filterUnwatched(streams: List): List {