Modern Apps git

← Modern-Apps.git

cast: pin the TV's audio controls and fix its play/pause glyph

Commit
cca9e67963f5c9720140b7cff2008897064577e4
Author
vayun-mathur <[email protected]>
When
2026-08-24 00:43 UTC (3 months ago)
Parents
d93a8a4

Diff

cast/tv/src/main/java/com/vayunmathur/cast/tv/platform/MirrorActivity.kt
diff --git a/cast/tv/src/main/java/com/vayunmathur/cast/tv/platform/MirrorActivity.kt b/cast/tv/src/main/java/com/vayunmathur/cast/tv/platform/MirrorActivity.ktindex 85a6ce2954..7ff2882972 100644--- a/cast/tv/src/main/java/com/vayunmathur/cast/tv/platform/MirrorActivity.kt+++ b/cast/tv/src/main/java/com/vayunmathur/cast/tv/platform/MirrorActivity.kt@@ -71,6 +71,16 @@ class MirrorActivity : ComponentActivity(), SurfaceHolder.Callback {     /** Whether the controls are on screen. Any key press reveals them; a timer takes them away. */     private var overlayVisible by mutableStateOf(false) +    /**+     * Whether the controls stay up rather than timing out.+     *+     * **True for an audio-only session, because there is nothing behind them to get out of the way+     * of.** The auto-hide exists so a seek bar does not sit on top of a film; with no picture it only+     * takes the one thing on screen away and leaves the user pressing a key to find out where playback+     * is. Read from the session rather than fixed, so screen mirroring and video are unchanged.+     */+    private var overlayPinned = false+     /**      * A scrub the user is still composing, in milliseconds, or -1 when none is in progress.      *@@ -104,6 +114,8 @@ class MirrorActivity : ComponentActivity(), SurfaceHolder.Callback {         // the receiver is never handed somewhere to draw. A full-screen black rectangle over silence         // would read as a fault rather than as music.         val hasVideo = (ReceiverController.state.value.phase as? ReceiverPhase.Mirroring)?.hasVideo != false+        overlayPinned = !hasVideo+        overlayVisible = overlayPinned         container = FrameLayout(this).apply {             setBackgroundColor(android.graphics.Color.BLACK)             if (hasVideo) {@@ -140,6 +152,10 @@ class MirrorActivity : ComponentActivity(), SurfaceHolder.Callback {         lifecycleScope.launch {             ReceiverController.state.collectLatest { state ->                 if (state.phase is ReceiverPhase.Mirroring) {+                    // Settled here as well as in onCreate: the phase may not have arrived yet when the+                    // Activity is built, and this is the first moment the session is known for certain.+                    overlayPinned = !state.phase.hasVideo+                    if (overlayPinned) overlayVisible = true                     fitToFrame(state.phase.width, state.phase.height)                 } else {                     finish()@@ -200,7 +216,9 @@ class MirrorActivity : ComponentActivity(), SurfaceHolder.Callback {             ?: return super.dispatchKeyEvent(event)          if (event.keyCode == KeyEvent.KEYCODE_BACK) {-            if (event.action == KeyEvent.ACTION_UP && overlayVisible) {+            // Pinned controls cannot be dismissed, so back means what it always means rather than+            // needing two presses to leave a screen that never changes.+            if (event.action == KeyEvent.ACTION_UP && overlayVisible && !overlayPinned) {                 hideOverlay()                 return true             }@@ -290,6 +308,8 @@ class MirrorActivity : ComponentActivity(), SurfaceHolder.Callback {     private fun revealOverlay() {         overlayVisible = true         hideJob?.cancel()+        hideJob = null+        if (overlayPinned) return         hideJob = lifecycleScope.launch {             delay(OVERLAY_AUTO_HIDE_MS)             // A scrub in progress is an interaction, however long the user has been holding the key.
cast/tv/src/main/java/com/vayunmathur/cast/tv/ui/TransportOverlay.kt
diff --git a/cast/tv/src/main/java/com/vayunmathur/cast/tv/ui/TransportOverlay.kt b/cast/tv/src/main/java/com/vayunmathur/cast/tv/ui/TransportOverlay.ktindex ba2ca2cd61..61fc0f158c 100644--- a/cast/tv/src/main/java/com/vayunmathur/cast/tv/ui/TransportOverlay.kt+++ b/cast/tv/src/main/java/com/vayunmathur/cast/tv/ui/TransportOverlay.kt@@ -119,12 +119,15 @@ fun TransportOverlay(                     style = MaterialTheme.typography.bodyLarge,                     color = Color.White,                 )-                // The one place the paused/buffering distinction is drawn: a stall and a pause look-                // identical on a frozen picture, and only one of them is the user's own doing.+                // **The action the centre key will take, not a description of the state.** Read as a+                // status it would be the other way round, and both readings are defensible - which is+                // exactly why it has to match the button it sits next to. Buffering is its own case:+                // a stall and a pause look identical on a frozen picture, and only one of them is the+                // user's own doing.                 Text(                     text = when {                         state.buffering -> "…"-                        !state.playing -> "❚❚"+                        state.playing -> "❚❚"                         else -> "▶"                     },                     style = MaterialTheme.typography.bodyLarge,