Modern Apps git

← Modern-Apps.git

youpipe: auto-hide player controls after 2s with keep-visible accessibility setting

Commit
e4a31500950041758560c3bdd19ad149ac727335
Author
Vayun Mathur <[email protected]>
When
2026-08-13 19:54 UTC (3 months ago)
Parents
f425754

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 25cf98fbc8..2abcca448b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/GeneralSettingsPage.kt@@ -41,6 +41,7 @@ fun GeneralSettingsPage(     val deArrowEnabled by ypvm.deArrowEnabled.collectAsState()     val youtubeLanguage by ypvm.youtubeLanguage.collectAsState()     val defaultPage by ypvm.defaultPage.collectAsState()+    val keepControlsVisible by ypvm.keepPlayerControlsVisible.collectAsState()      AppScaffold(         title = stringResource(R.string.settings_general_content),@@ -64,6 +65,14 @@ fun GeneralSettingsPage(                     onCheckedChange = { ypvm.setDeArrowEnabled(it) },                 )             }+            SettingsSection(title = stringResource(R.string.label_player)) {+                SettingsSwitchRow(+                    title = stringResource(R.string.label_keep_controls_visible),+                    supportingText = stringResource(R.string.label_keep_controls_visible_description),+                    checked = keepControlsVisible,+                    onCheckedChange = { ypvm.setKeepPlayerControlsVisible(it) },+                )+            }             SettingsSection(title = stringResource(R.string.label_youtube_content)) {                 LanguageSelector(                     selectedCode = youtubeLanguage,
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 887c0ae087..d4f13e57d6 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt@@ -154,6 +154,9 @@ fun VideoPlayer(         currentAudioStream = filtered.maxByOrNull { it.bitrate } ?: filtered.firstOrNull()     }     var isControlsVisible by remember { mutableStateOf(true) }+    var isPlaying by remember { mutableStateOf(false) }+    var controlsInteractionTick by remember { mutableStateOf(0) }+    val keepControlsVisible by ypvm.keepPlayerControlsVisible.collectAsState()     var currentPosition by remember { mutableLongStateOf(0L) }     var bufferedPosition by remember { mutableLongStateOf(0L) }     var duration by remember { mutableLongStateOf(0L) }@@ -233,16 +236,20 @@ fun VideoPlayer(      DisposableEffect(controller) {         val player = controller ?: return@DisposableEffect onDispose {}+        // Sync initial playing state once controller is available+        isPlaying = player.isPlaying         val listener = object : Player.Listener {             override fun onEvents(player: Player, events: Player.Events) {                 if (events.contains(Player.EVENT_TIMELINE_CHANGED) || events.contains(Player.EVENT_PLAYBACK_STATE_CHANGED)) {                     duration = player.duration.coerceAtLeast(0L)                     isBuffering = player.playbackState == Player.STATE_BUFFERING+                    isPlaying = player.isPlaying                 }             }-            override fun onIsPlayingChanged(isPlaying: Boolean) {+            override fun onIsPlayingChanged(isPlayingNow: Boolean) {+                isPlaying = isPlayingNow                 context.findActivity().setPictureInPictureParams(PictureInPictureParams.Builder().apply {-                    setAutoEnterEnabled(isPlaying)+                    setAutoEnterEnabled(isPlayingNow)                 }.build())             }             override fun onVideoSizeChanged(videoSize: VideoSize) {@@ -405,16 +412,73 @@ fun VideoPlayer(     val isPipMode = rememberIsInPipMode()     val scope = rememberCoroutineScope() +    // When paused, keep controls visible (no auto-hide). When playing resumes, re-show and start timer.+    LaunchedEffect(isPlaying) {+        if (isPlaying) {+            isControlsVisible = true+            controlsInteractionTick+++        } else {+            isControlsVisible = true+        }+    }++    // Auto-hide controls after 2 seconds of inactivity while playing. Resets on any interaction.+    LaunchedEffect(+        isControlsVisible, isPlaying, keepControlsVisible, isLocked, isDragging,+        isVideoMenuExpanded, isLanguageMenuExpanded, isCaptionMenuExpanded,+        isSpeedMenuExpanded, isChapterMenuVisible, isPipMode, controlsInteractionTick+    ) {+        if (!isControlsVisible) return@LaunchedEffect+        if (keepControlsVisible) return@LaunchedEffect+        if (isLocked) return@LaunchedEffect+        if (!isPlaying) return@LaunchedEffect+        if (isDragging) return@LaunchedEffect+        if (isVideoMenuExpanded || isLanguageMenuExpanded || isCaptionMenuExpanded || isSpeedMenuExpanded || isChapterMenuVisible) return@LaunchedEffect+        if (isPipMode) return@LaunchedEffect+        delay(CONTROLS_AUTO_HIDE_DELAY_MS)+        isControlsVisible = false+    }++    // Accessibility toggle: when "keep controls visible" is enabled, force controls on.+    LaunchedEffect(keepControlsVisible) {+        if (keepControlsVisible) {+            isControlsVisible = true+        } else {+            // Re-arm timer when re-enabling auto-hide while playing.+            if (isPlaying && isControlsVisible) controlsInteractionTick+++        }+    }+     val modifier = if(isFullscreen) Modifier.fillMaxHeight() else Modifier.aspectRatio(16f / 9f)      Box(         modifier = modifier             .fillMaxWidth()-            .pointerInput(Unit) {+            .pointerInput(isLocked, keepControlsVisible) {                 detectTapGestures(-                    onTap = { isControlsVisible = !isControlsVisible },+                    onTap = {+                        if (isLocked) {+                            isControlsVisible = true+                            controlsInteractionTick+++                            return@detectTapGestures+                        }+                        if (isControlsVisible) {+                            // When auto-hide is disabled for accessibility, tapping keeps controls visible and resets timer.+                            if (keepControlsVisible) {+                                controlsInteractionTick+++                            } else {+                                isControlsVisible = false+                            }+                        } else {+                            isControlsVisible = true+                            controlsInteractionTick+++                        }+                    },                     onDoubleTap = { offset ->                         if (isLocked) return@detectTapGestures+                        // 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)@@ -809,6 +873,7 @@ fun VideoPlayer( }  private const val HISTORY_UPSERT_INTERVAL_MS = 5000L+private const val CONTROLS_AUTO_HIDE_DELAY_MS = 2000L  /** Formats a tempo multiplier for display: whole values as "2", fractional as "1.5". */ private fun formatTempo(speed: Float): String {
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 4d67d3bbd9..a7191d9ca5 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt@@ -1065,6 +1065,18 @@ class YouPipeViewModel(         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), DEFAULT_SPONSOR_CATEGORIES)     val sponsorBlockCategories: StateFlow<Set<String>> = _sponsorBlockCategories +    private val _keepPlayerControlsVisible: StateFlow<Boolean> = DataStoreUtils+        .getInstance(application)+        .booleanFlow("keep_player_controls_visible")+        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)+    val keepPlayerControlsVisible: StateFlow<Boolean> = _keepPlayerControlsVisible++    fun setKeepPlayerControlsVisible(keepVisible: Boolean) {+        viewModelScope.launch {+            DataStoreUtils.getInstance(getApplication()).setBoolean("keep_player_controls_visible", keepVisible)+        }+    }+     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 329686e63b..aa4739ab76 100644--- a/youpipe/src/main/res/values/strings.xml+++ b/youpipe/src/main/res/values/strings.xml@@ -288,4 +288,11 @@     <string name="lock_controls">Lock controls</string>     <!-- Player controls: content description for the unlock button shown while controls are locked. Verb phrase -->     <string name="unlock_controls">Unlock controls</string>++    <!-- Player section header in general settings. Noun -->+    <string name="label_player">Player</string>+    <!-- Toggle: keep video player controls always visible instead of auto-hiding. Verb phrase -->+    <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> </resources>