youpipe: phone resume bars no longer pin 'fully watched' after a second
- Commit
bc93782b3e1443d1399885ea2d513accb06a04d0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-30 22:53 UTC (5 days ago)
- Parents
bc18c11
Watch progress is stored in milliseconds but video duration is seconds, and every phone call site divided ms by s directly: 30 s watched of a 300 s video computed 100f instead of 0.1f, so any video with more than ~1 second watched rendered a completely full resume bar. The TV path had already been fixed (with a comment naming exactly this bug); the phone path had not. All four phone call sites now go through the pure watchedPercent(progressMs, durationSeconds) in the shared VideoRow mapping (ms->s, 0 for unstarted/unknown duration, clamped to [0,1]), and videoRowState coerces the percentage so no future caller can pin the weighted bar segments. Downloads, subscription aggregation and stream selection were audited and cleared. New tests pin the fractions and clamps. Verified: :youpipe:testDevUnitTest BUILD SUCCESSFUL; 25 lint errors are pre-existing on untouched files.
Diff
youpipe/src/main/java/com/vayunmathur/youpipe/ui/SearchPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SearchPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SearchPage.ktindex e572f73194..0e84776878 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SearchPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SearchPage.kt@@ -97,7 +97,7 @@ fun SearchPage( videoInfo = video, showAuthor = true, reason = reason,- percentWatched = if (video.duration > 0) (watched.toDouble() / video.duration).toFloat() else 0f,+ percentWatched = watchedPercent(watched, video.duration), deArrowTitle = deArrow?.title, deArrowThumbnailURL = deArrow?.thumbnailUrl, )
youpipe/src/main/java/com/vayunmathur/youpipe/ui/SubscriptionVideosPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SubscriptionVideosPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SubscriptionVideosPage.ktindex 8296d1b8bd..6288772c70 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SubscriptionVideosPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SubscriptionVideosPage.kt@@ -66,7 +66,7 @@ fun SubscriptionVideosPage( context = context, videoInfo = video, showAuthor = true,- percentWatched = if (video.duration > 0) (watched.toDouble() / video.duration).toFloat() else 0f,+ percentWatched = watchedPercent(watched, video.duration), deArrowTitle = deArrow?.title, deArrowThumbnailURL = deArrow?.thumbnailUrl, )
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoItem.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoItem.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoItem.ktindex b5ed166e5a..4009316df8 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoItem.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoItem.kt@@ -69,7 +69,7 @@ fun VideoItem( val historyFlow = remember(videoInfo.videoID) { youPipeViewModel.historyById(videoInfo.videoID) } val historyItem by historyFlow.collectAsState(initial = null) val timeWatched = historyItem?.progress ?: 0- val percentWatched = if (videoInfo.duration > 0) timeWatched.toDouble() / videoInfo.duration.toDouble() else 0.0+ val percentWatched = watchedPercent(timeWatched, videoInfo.duration) val deArrowEnabled by youPipeViewModel.deArrowEnabled.collectAsState() val deArrowCache by youPipeViewModel.deArrowCache.collectAsState()@@ -91,7 +91,7 @@ fun VideoItem( videoInfo = videoInfo, showAuthor = showAuthor, reason = reason,- percentWatched = percentWatched.toFloat(),+ percentWatched = percentWatched, deArrowTitle = deArrowData?.title, deArrowThumbnailURL = deArrowData?.thumbnailUrl, ),
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.ktindex b8f5dfb696..a4f9c39cbb 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt@@ -247,7 +247,7 @@ fun VideoPage( context = context, videoInfo = related, showAuthor = true,- percentWatched = if (related.duration > 0) (watched.toDouble() / related.duration).toFloat() else 0f,+ percentWatched = watchedPercent(watched, related.duration), deArrowTitle = relatedDeArrow?.title, deArrowThumbnailURL = relatedDeArrow?.thumbnailUrl, )
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoRow.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoRow.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoRow.ktindex 9bcdbf1ae9..e39979e4df 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoRow.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoRow.kt@@ -44,6 +44,22 @@ import com.vayunmathur.youpipe.platform.VideoRowState import com.vayunmathur.youpipe.platform.YouPipeViewModel import com.vayunmathur.youpipe.network.decodeHtml +/**+ * Fraction watched for a resume bar, in `[0f, 1f]`.+ *+ * [progressMs] is a persisted watch position in milliseconds+ * (`HistoryVideo.progress`, written from the player's millisecond playhead);+ * [durationSeconds] is a [VideoInfo] duration in seconds. Dividing the former+ * by the latter without converting pins the bar full after about a second of+ * watching, which is how the phone rows behaved before this helper (the TV+ * rows already converted). Unknown/live durations and non-positive progress+ * show no bar; over-long positions clamp to complete.+ */+fun watchedPercent(progressMs: Long, durationSeconds: Long): Float {+ if (progressMs <= 0L || durationSeconds <= 0L) return 0f+ return (progressMs / 1_000.0 / durationSeconds).toFloat().coerceIn(0f, 1f)+}+ /** * Resolve [videoInfo] into the display state [VideoRow] draws. *@@ -78,7 +94,9 @@ fun videoRowState( }, reason = reason, channelKey = videoInfo.author.lowercase(),- percentWatched = percentWatched,+ // The thumbnail bar weights its two segments by this fraction and by+ // `1f - this`; an out-of-range caller value would pin or invert it.+ percentWatched = percentWatched.coerceIn(0f, 1f), deArrowThumbnail = deArrowThumbnailURL != null, )
youpipe/src/test/java/com/vayunmathur/youpipe/ui/WatchedPercentTest.kt
diff --git a/youpipe/src/test/java/com/vayunmathur/youpipe/ui/WatchedPercentTest.kt b/youpipe/src/test/java/com/vayunmathur/youpipe/ui/WatchedPercentTest.ktnew file mode 100644index 0000000000..f9aaeb7dd7--- /dev/null+++ b/youpipe/src/test/java/com/vayunmathur/youpipe/ui/WatchedPercentTest.kt@@ -0,0 +1,35 @@+package com.vayunmathur.youpipe.ui++import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Regression test for the phone resume bars: persisted watch positions are+ * milliseconds and [VideoInfo] durations are seconds, so the fraction must+ * convert before dividing. The pre-fix phone call sites divided ms by+ * seconds directly (e.g. 30_000 ms into a 300 s video gave 100f, not 0.1f),+ * and the thumbnail bar then rendered fully watched.+ */+class WatchedPercentTest {++ @Test+ fun `milliseconds progress over seconds duration`() {+ assertEquals(0.1f, watchedPercent(progressMs = 30_000L, durationSeconds = 300L))+ assertEquals(0.5f, watchedPercent(progressMs = 60_000L, durationSeconds = 120L))+ assertEquals(0.0167f, watchedPercent(progressMs = 2_000L, durationSeconds = 120L), absoluteTolerance = 0.0001f)+ }++ @Test+ fun `unstarted and unknown duration show no bar`() {+ assertEquals(0f, watchedPercent(progressMs = 0L, durationSeconds = 300L))+ assertEquals(0f, watchedPercent(progressMs = -1L, durationSeconds = 300L))+ assertEquals(0f, watchedPercent(progressMs = 30_000L, durationSeconds = 0L))+ assertEquals(0f, watchedPercent(progressMs = 30_000L, durationSeconds = -5L))+ }++ @Test+ fun `position past the end clamps to complete`() {+ assertEquals(1f, watchedPercent(progressMs = 301_000L, durationSeconds = 300L))+ assertEquals(1f, watchedPercent(progressMs = 300_000L, durationSeconds = 300L))+ }+}