ref: increase watch threshold

This commit is contained in:
tapframe 2026-05-05 12:06:14 +05:30
parent d433a5cab4
commit fa7c8068b3
2 changed files with 9 additions and 20 deletions

View file

@ -1,8 +1,7 @@
package com.nuvio.app.features.watching.domain package com.nuvio.app.features.watching.domain
private const val InProgressStartThresholdFraction = 0.02f private const val CompletionThresholdFraction = 0.90
private const val CompletionThresholdFraction = 0.85 private const val ProgressStoreThresholdMs = 1_000L
private const val InProgressStartThresholdMinMs = 30_000L
private const val UpcomingNextSeasonWindowDays = 7 private const val UpcomingNextSeasonWindowDays = 7
fun watchedKey( fun watchedKey(
@ -14,17 +13,7 @@ fun watchedKey(
fun shouldStoreProgress( fun shouldStoreProgress(
positionMs: Long, positionMs: Long,
durationMs: Long, durationMs: Long,
): Boolean { ): Boolean = positionMs >= ProgressStoreThresholdMs
val thresholdMs = if (durationMs > 0L) {
maxOf(
InProgressStartThresholdMinMs,
(durationMs * InProgressStartThresholdFraction).toLong(),
)
} else {
1L
}
return positionMs >= thresholdMs
}
fun isProgressComplete( fun isProgressComplete(
positionMs: Long, positionMs: Long,

View file

@ -26,17 +26,17 @@ class WatchProgressRulesTest {
} }
@Test @Test
fun `save threshold uses max of thirty seconds and two percent`() { fun `save threshold starts after one second`() {
assertFalse(shouldStoreWatchProgress(positionMs = 29_999L, durationMs = 600_000L)) assertFalse(shouldStoreWatchProgress(positionMs = 999L, durationMs = 600_000L))
assertTrue(shouldStoreWatchProgress(positionMs = 30_000L, durationMs = 600_000L)) assertTrue(shouldStoreWatchProgress(positionMs = 1_000L, durationMs = 600_000L))
assertFalse(shouldStoreWatchProgress(positionMs = 119_999L, durationMs = 6_000_000L)) assertTrue(shouldStoreWatchProgress(positionMs = 1_000L, durationMs = 0L))
assertTrue(shouldStoreWatchProgress(positionMs = 120_000L, durationMs = 6_000_000L))
} }
@Test @Test
fun `completion detects watched threshold remaining time and ended state`() { fun `completion detects watched threshold remaining time and ended state`() {
assertTrue(isWatchProgressComplete(positionMs = 920_000L, durationMs = 1_000_000L, isEnded = false)) assertTrue(isWatchProgressComplete(positionMs = 920_000L, durationMs = 1_000_000L, isEnded = false))
assertTrue(isWatchProgressComplete(positionMs = 850_000L, durationMs = 1_000_000L, isEnded = false)) assertTrue(isWatchProgressComplete(positionMs = 900_000L, durationMs = 1_000_000L, isEnded = false))
assertFalse(isWatchProgressComplete(positionMs = 899_999L, durationMs = 1_000_000L, isEnded = false))
assertTrue(isWatchProgressComplete(positionMs = 1L, durationMs = 0L, isEnded = true)) assertTrue(isWatchProgressComplete(positionMs = 1L, durationMs = 0L, isEnded = true))
assertFalse(isWatchProgressComplete(positionMs = 200_000L, durationMs = 1_000_000L, isEnded = false)) assertFalse(isWatchProgressComplete(positionMs = 200_000L, durationMs = 1_000_000L, isEnded = false))
} }