youpipe: notification-style progress bar, fix double-tap skip (#666, #809)
- Commit
47ee143a3bcd5120a3b81a9e29fa8f619bf57e5c- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-13 19:38 UTC (1 month ago)
- Parents
68ff269
Diff
youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.ktindex ed01bee369..6097b5174b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.kt@@ -43,6 +43,7 @@ fun GeneralSettingsPage( val youtubeLanguage by ypvm.youtubeLanguage.collectAsState() val defaultPage by ypvm.defaultPage.collectAsState() val keepControlsVisible by ypvm.keepPlayerControlsVisible.collectAsState()+ val notificationStyleProgress by ypvm.notificationStyleProgressBar.collectAsState() AppScaffold( title = stringResource(R.string.settings_general_content),@@ -74,6 +75,12 @@ fun GeneralSettingsPage( checked = keepControlsVisible, onCheckedChange = { ypvm.setKeepPlayerControlsVisible(it) }, )+ SettingsSwitchRow(+ title = stringResource(R.string.label_notification_style_progress),+ supportingText = stringResource(R.string.label_notification_style_progress_description),+ checked = notificationStyleProgress,+ onCheckedChange = { ypvm.setNotificationStyleProgressBar(it) },+ ) } SettingsSection(title = stringResource(R.string.label_youtube_content)) { LanguageSelector(
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.ktindex 6ce3892880..3442e584b8 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt@@ -15,6 +15,8 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color@@ -72,6 +74,7 @@ fun VideoPlayer( val context = LocalContext.current val viewConfiguration = LocalViewConfiguration.current val hasAudio = audioStreams.isNotEmpty()+ val useNotificationStyleBar by ypvm.notificationStyleProgressBar.collectAsState() val modifier = if (isFullscreen) Modifier.fillMaxHeight() else Modifier.aspectRatio(aspectRatio) @@ -104,12 +107,19 @@ fun VideoPlayer( // Any gesture re-shows controls and resets auto-hide timer. isControlsVisible = true controlsInteractionTick++- val isRightSide = offset.x > size.width / 2- if (isRightSide) {- controller?.seekTo(currentPosition + 10000L)- } else {- controller?.seekTo(currentPosition - 10000L)- }+ // Read position and duration from the player at tap time, not from the+ // snapshots captured when this gesture block was keyed: those go stale and+ // a seek from ~0 makes the video appear to restart instead of skipping (#809).+ // Keys stay stable on purpose: re-keying per position tick would restart+ // gesture detection every 300 ms and break double-tap/long-press outright.+ val player = controller ?: return@detectTapGestures+ val target = doubleTapSeekTarget(+ player.currentPosition,+ player.duration,+ offset.x > size.width / 2,+ )+ player.seekTo(target)+ CastPlayback.update { it.copy(positionMs = target) } }, onPress = { if (isLocked) return@detectTapGestures@@ -248,6 +258,8 @@ fun VideoPlayer( currentPosition = currentPosition, bufferedPosition = bufferedPosition, duration = duration,+ isPlaying = isPlaying,+ useNotificationStyle = useNotificationStyleBar, sponsorSegments = sponsorSegments, onSeekChange = { position -> CastPlayback.update { state ->@@ -258,6 +270,10 @@ fun VideoPlayer( controller?.seekTo(currentPosition) CastPlayback.update { it.copy(dragging = false) } },+ onSeekTo = { position ->+ controller?.seekTo(position)+ CastPlayback.update { it.copy(positionMs = position) }+ }, isFullscreen = isFullscreen, onLock = { isLocked = true@@ -301,3 +317,22 @@ fun VideoPlayer( } /** Cast-request sizing, the casting panel and tempo formatting live in VideoPlayerCasting.kt. */++/** How far one double-tap on either side of the player moves playback. */+internal const val DOUBLE_TAP_SKIP_MS = 10_000L++/**+ * Where a double-tap skip lands, given the position at tap time.+ *+ * Pure so it is unit-testable; the gesture handler reads the live player position and clamps here.+ * An unknown duration ([durationMs] <= 0, e.g. `C.TIME_UNSET`) means forward seeks are unbounded+ * and backward seeks still floor at zero.+ */+internal fun doubleTapSeekTarget(currentPosition: Long, durationMs: Long, forward: Boolean): Long {+ val end = durationMs.takeIf { it > 0 } ?: Long.MAX_VALUE+ return if (forward) {+ (currentPosition + DOUBLE_TAP_SKIP_MS).coerceAtMost(end)+ } else {+ (currentPosition - DOUBLE_TAP_SKIP_MS).coerceAtLeast(0L)+ }+}
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerNotificationProgressBar.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerNotificationProgressBar.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerNotificationProgressBar.ktnew file mode 100644index 0000000000..7f4d726a70--- /dev/null+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerNotificationProgressBar.kt@@ -0,0 +1,87 @@+package com.vayunmathur.youpipe.ui++import androidx.compose.foundation.Canvas+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.geometry.Size+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.semantics.ProgressBarRangeInfo+import androidx.compose.ui.semantics.progressBarRangeInfo+import androidx.compose.ui.semantics.semantics+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.youpipe.util.SponsorSegment++/**+ * Slim notification-style replacement for the player seek slider: a thin bar showing buffered and+ * played portions with sponsor-segment markers, tap-to-seek. The played portion has two visual+ * states mirroring the notification media controls: full-strength while playing, dimmed while+ * paused.+ */+@Composable+fun VideoPlayerNotificationProgressBar(+ currentPosition: Long,+ bufferedPosition: Long,+ duration: Long,+ isPlaying: Boolean,+ sponsorSegments: List<SponsorSegment>,+ onSeekTo: (Long) -> Unit,+ modifier: Modifier = Modifier,+) {+ val playedFraction = if (duration > 0) currentPosition.toFloat() / duration else 0f+ val bufferedFraction = if (duration > 0) bufferedPosition.toFloat() / duration else 0f+ val playedColor =+ if (isPlaying) MaterialTheme.colorScheme.primary else Color.White.copy(alpha = 0.55f)+ // 28dp touch target around the 4dp visual bar so taps land without pixel-hunting.+ Box(+ modifier = modifier+ .fillMaxWidth()+ .height(28.dp)+ .semantics {+ progressBarRangeInfo = ProgressBarRangeInfo(+ current = currentPosition.toFloat(),+ range = 0f..duration.toFloat().coerceAtLeast(1f),+ )+ }+ .pointerInput(duration, onSeekTo) {+ detectTapGestures(+ onTap = { offset ->+ if (duration > 0) {+ onSeekTo(+ ((offset.x / size.width) * duration).toLong().coerceIn(0L, duration),+ )+ }+ },+ )+ },+ contentAlignment = Alignment.Center,+ ) {+ Canvas(modifier = Modifier.fillMaxWidth().height(4.dp)) {+ drawRect(color = Color.White.copy(alpha = 0.2f))+ drawRect(+ color = Color.White.copy(alpha = 0.3f),+ size = Size(size.width * bufferedFraction.coerceIn(0f, 1f), size.height),+ )+ sponsorSegments.forEach { segment ->+ val startX = (segment.start.toFloat() / duration) * size.width+ val endX = (segment.end.toFloat() / duration) * size.width+ drawRect(+ color = Color.Yellow.copy(alpha = 0.7f),+ topLeft = Offset(startX, 0f),+ size = Size(endX - startX, size.height),+ )+ }+ drawRect(+ color = playedColor,+ size = Size(size.width * playedFraction.coerceIn(0f, 1f), size.height),+ )+ }+ }+}
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerSeekRow.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerSeekRow.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerSeekRow.ktindex 59c04dcac1..8c991b1904 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerSeekRow.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayerSeekRow.kt@@ -33,15 +33,22 @@ import com.vayunmathur.youpipe.util.SponsorSegment * The seek row pinned to the bottom of the controls overlay: elapsed/total times, * the buffered and position sliders with sponsor-segment markers, and the * lock/fullscreen buttons.+ *+ * When [useNotificationStyle] is set (Settings > Player), the sliders are swapped for+ * [VideoPlayerNotificationProgressBar]: a slim notification-style two-state+ * (playing/paused) bar with tap-to-seek. */ @Composable internal fun VideoPlayerSeekRow( currentPosition: Long, bufferedPosition: Long, duration: Long,+ isPlaying: Boolean,+ useNotificationStyle: Boolean, sponsorSegments: List<SponsorSegment>, onSeekChange: (Long) -> Unit, onSeekFinished: () -> Unit,+ onSeekTo: (Long) -> Unit, isFullscreen: Boolean, onLock: () -> Unit, onFullscreenChange: (Boolean) -> Unit,@@ -65,40 +72,51 @@ internal fun VideoPlayerSeekRow( ) } Box(contentAlignment = Alignment.CenterStart) {- Slider(- value = if (duration > 0) bufferedPosition.toFloat() else 0f,- onValueChange = { },- valueRange = 0f..(duration.toFloat().coerceAtLeast(1f)),- colors = SliderDefaults.colors(- thumbColor = Color.Transparent,- activeTrackColor = Color.White.copy(alpha = 0.3f),- inactiveTrackColor = Color.Transparent+ if (useNotificationStyle) {+ VideoPlayerNotificationProgressBar(+ currentPosition = currentPosition,+ bufferedPosition = bufferedPosition,+ duration = duration,+ isPlaying = isPlaying,+ sponsorSegments = sponsorSegments,+ onSeekTo = onSeekTo, )- )- if (duration > 0) {- Canvas(modifier = Modifier.fillMaxWidth().height(4.dp).padding(horizontal = 20.dp)) {- sponsorSegments.forEach { segment ->- val startX = (segment.start.toFloat() / duration) * size.width- val endX = (segment.end.toFloat() / duration) * size.width- drawRect(- color = Color.Yellow.copy(alpha = 0.7f),- topLeft = Offset(startX, 0f),- size = Size(endX - startX, size.height)- )+ } else {+ Slider(+ value = if (duration > 0) bufferedPosition.toFloat() else 0f,+ onValueChange = { },+ valueRange = 0f..(duration.toFloat().coerceAtLeast(1f)),+ colors = SliderDefaults.colors(+ thumbColor = Color.Transparent,+ activeTrackColor = Color.White.copy(alpha = 0.3f),+ inactiveTrackColor = Color.Transparent+ )+ )+ if (duration > 0) {+ Canvas(modifier = Modifier.fillMaxWidth().height(4.dp).padding(horizontal = 20.dp)) {+ sponsorSegments.forEach { segment ->+ val startX = (segment.start.toFloat() / duration) * size.width+ val endX = (segment.end.toFloat() / duration) * size.width+ drawRect(+ color = Color.Yellow.copy(alpha = 0.7f),+ topLeft = Offset(startX, 0f),+ size = Size(endX - startX, size.height)+ )+ } } }- }- Slider(- value = if (duration > 0) currentPosition.toFloat() else 0f,- onValueChange = { onSeekChange(it.toLong()) },- onValueChangeFinished = onSeekFinished,- valueRange = 0f..(duration.toFloat().coerceAtLeast(1f)),- colors = SliderDefaults.colors(- thumbColor = MaterialTheme.colorScheme.primary,- activeTrackColor = MaterialTheme.colorScheme.primary,- inactiveTrackColor = Color.White.copy(alpha = 0.2f)+ Slider(+ value = if (duration > 0) currentPosition.toFloat() else 0f,+ onValueChange = { onSeekChange(it.toLong()) },+ onValueChangeFinished = onSeekFinished,+ valueRange = 0f..(duration.toFloat().coerceAtLeast(1f)),+ colors = SliderDefaults.colors(+ thumbColor = MaterialTheme.colorScheme.primary,+ activeTrackColor = MaterialTheme.colorScheme.primary,+ inactiveTrackColor = Color.White.copy(alpha = 0.2f)+ ) )- )+ } } } Spacer(Modifier.padding(4.dp))
youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.ktindex f4f09c4331..bad1b6215b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt@@ -483,6 +483,12 @@ class YouPipeViewModel( .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false) val keepPlayerControlsVisible: StateFlow<Boolean> = _keepPlayerControlsVisible + private val _notificationStyleProgressBar: StateFlow<Boolean> = DataStoreUtils+ .getInstance(application)+ .booleanFlow("notification_style_progress_bar")+ .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)+ val notificationStyleProgressBar: StateFlow<Boolean> = _notificationStyleProgressBar+ /** * The tempo multiplier, kept across videos. *@@ -510,6 +516,12 @@ class YouPipeViewModel( } } + fun setNotificationStyleProgressBar(enabled: Boolean) {+ viewModelScope.launch {+ DataStoreUtils.getInstance(getApplication()).setBoolean("notification_style_progress_bar", enabled)+ }+ }+ fun setDeArrowEnabled(enabled: Boolean) { viewModelScope.launch { DataStoreUtils.getInstance(getApplication()).setBoolean("dearrow_enabled", enabled)
youpipe/src/main/res/values/strings.xml
diff --git a/youpipe/src/main/res/values/strings.xml b/youpipe/src/main/res/values/strings.xmlindex ab34d95ed0..78205a4737 100644--- a/youpipe/src/main/res/values/strings.xml+++ b/youpipe/src/main/res/values/strings.xml@@ -274,6 +274,10 @@ <string name="label_keep_controls_visible">Keep player controls visible</string> <!-- Description for keep-controls toggle: controls stay on screen rather than hiding after inactivity. Accessibility feature --> <string name="label_keep_controls_visible_description">Controls stay on screen instead of hiding after 2 seconds. Useful for accessibility.</string>+ <!-- Toggle: replace the player seek slider with a slim notification-style two-state (playing/paused) progress bar. Verb phrase -->+ <string name="label_notification_style_progress">Notification-style progress bar</string>+ <!-- Description for notification-style progress toggle -->+ <string name="label_notification_style_progress_description">Replace the seek slider with a slim bar like the notification controls. It looks different when playing vs paused.</string> <!-- Casting the video to a TV through the MA Cast app. --> <!-- Content description for the cast button in the player controls -->
youpipe/src/test/java/com/vayunmathur/youpipe/ui/DoubleTapSeekTest.kt
diff --git a/youpipe/src/test/java/com/vayunmathur/youpipe/ui/DoubleTapSeekTest.kt b/youpipe/src/test/java/com/vayunmathur/youpipe/ui/DoubleTapSeekTest.ktnew file mode 100644index 0000000000..cb8f9fdad2--- /dev/null+++ b/youpipe/src/test/java/com/vayunmathur/youpipe/ui/DoubleTapSeekTest.kt@@ -0,0 +1,39 @@+package com.vayunmathur.youpipe.ui++import kotlin.test.Test+import kotlin.test.assertEquals++class DoubleTapSeekTest {++ @Test+ fun `forward seek advances by the skip amount`() {+ assertEquals(70_000L, doubleTapSeekTarget(60_000L, 300_000L, forward = true))+ }++ @Test+ fun `backward seek retreats by the skip amount`() {+ assertEquals(50_000L, doubleTapSeekTarget(60_000L, 300_000L, forward = false))+ }++ @Test+ fun `backward seek near start floors at zero instead of restarting from duration`() {+ assertEquals(0L, doubleTapSeekTarget(5_000L, 300_000L, forward = false))+ }++ @Test+ fun `forward seek near end clamps at duration`() {+ assertEquals(300_000L, doubleTapSeekTarget(295_000L, 300_000L, forward = true))+ }++ @Test+ fun `unknown duration leaves forward seeks unbounded`() {+ assertEquals(310_000L, doubleTapSeekTarget(300_000L, -1L, forward = true))+ }++ @Test+ fun `mid-video skips never land near zero`() {+ // The #809 regression: a stale captured position sought from ~0 and the video restarted.+ val target = doubleTapSeekTarget(120_000L, 300_000L, forward = true)+ assertEquals(130_000L, target)+ }+}