Modern Apps git

← Modern-Apps.git

youpipe: dense TV grids, play on select, YouTube-style overlay

Commit
87b3e5625230eed5ff27128ec7327f814315aa70
Author
vayun-mathur <[email protected]>
When
2026-10-26 00:25 UTC (1 month ago)
Parents
d1aee59

Diff

youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.ktindex c36c0149b8..ef8241bfa2 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.kt@@ -98,27 +98,28 @@ fun TvAddToPlaylistPage(     }      TvInitialFocus(closeFocus)-    Column(Modifier.fillMaxSize()) {-        TvScreenHeader(-            title = stringResource(R.string.add_to_playlist),-            actions = {-                TvButton(-                    text = stringResource(UiR.string.ok),-                    onClick = ::confirm,-                    primary = true,-                )-                TvButton(-                    text = stringResource(UiR.string.cancel),-                    onClick = { backStack.pop() },-                )-            },-        )-        LazyColumn(-            state = rememberLazyListState(),-            modifier = Modifier.fillMaxSize(),-            contentPadding = tvContentPadding(top = 14.dp),-            verticalArrangement = Arrangement.spacedBy(8.dp),-        ) {+    TvSettingsBody {+        Column(Modifier.fillMaxSize()) {+            TvScreenHeader(+                title = stringResource(R.string.add_to_playlist),+                actions = {+                    TvButton(+                        text = stringResource(UiR.string.ok),+                        onClick = ::confirm,+                        primary = true,+                    )+                    TvButton(+                        text = stringResource(UiR.string.cancel),+                        onClick = { backStack.pop() },+                    )+                },+            )+            LazyColumn(+                state = rememberLazyListState(),+                modifier = Modifier.fillMaxSize(),+                contentPadding = tvContentPadding(top = 14.dp),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {             items(playlists, key = { it.id }) { playlist ->                 val checked = playlist.id in staged                 TvListRow(@@ -167,6 +168,7 @@ fun TvAddToPlaylistPage(                     )                 }             }+            }         }     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.ktindex 34ac6ba91e..d4d3c2b2b9 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.kt@@ -4,9 +4,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState@@ -24,10 +21,10 @@ import com.vayunmathur.library.image.ImageRequest import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.tv.TvScreenHeader-import com.vayunmathur.library.tv.tvContentPadding import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.data.Subscription@@ -36,7 +33,7 @@ import com.vayunmathur.youpipe.util.YouPipeViewModel import com.vayunmathur.youpipe.util.decodeHtml  /**- * TV channel page: avatar header + subscribe button + video grid.+ * TV channel page: avatar header + subscribe button + 4-column video grid.  *  * Mirrors the phone `ChannelPage` binding (`loadChannel`, subscriptions for membership).  * The header and subscribe button are stacked focus targets — not a scrolling collapse —@@ -117,19 +114,12 @@ fun TvChannelPage(         when {             channelInfo == null -> TvLoading()             rows.isEmpty() -> TvEmptyState(title = stringResource(R.string.empty_recommendations))-            else -> LazyVerticalGrid(-                columns = GridCells.Fixed(TV_GRID_COLUMNS),-                state = rememberLazyGridState(),-                modifier = Modifier.fillMaxSize(),-                contentPadding = tvContentPadding(top = 14.dp),-                verticalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(28.dp),-                horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(20.dp),-            ) {+            else -> TvGrid(columns = TV_GRID_COLUMNS, modifier = Modifier.fillMaxSize()) {                 items(rows.size, key = { rows[it].row.videoID }) { index ->                     val item = rows[index]                     TvVideoCard(                         item = item,-                        onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },+                        onOpen = { backStack.playVideo(item.row.videoID) },                     )                 }             }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.ktindex 9499ff2a24..f07d89a1d5 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.kt@@ -67,68 +67,70 @@ fun TvCreateCategoryPage(         (id != null || categoryName !in categoryNames)      TvInitialFocus(nameFocus)-    Column(Modifier.fillMaxSize()) {-        TvScreenHeader(-            title = if (id == null) {-                stringResource(R.string.title_create_subscription_category)-            } else {-                stringResource(R.string.title_update_subscription_category)-            },-            actions = {-                TvButton(-                    text = if (id == null) {-                        stringResource(UiR.string.create)-                    } else {-                        stringResource(R.string.action_update)-                    },-                    onClick = {-                        scope.launch {-                            ypvm.replaceCategory(id, categoryName, selectedSubscriptions.map { it.id })-                            backStack.pop()-                        }-                    },-                    enabled = canConfirm,-                    primary = true,-                )-            },-        )-        TvTextField(-            value = categoryName,-            onValueChange = { categoryName = it },-            placeholder = stringResource(R.string.label_category_name),-            focusRequester = nameFocus,-            modifier = Modifier.fillMaxWidth().padding(start = 48.dp, end = 48.dp, bottom = 8.dp),-        )-        LazyColumn(-            state = rememberLazyListState(),-            modifier = Modifier.fillMaxSize(),-            contentPadding = tvContentPadding(),-            verticalArrangement = Arrangement.spacedBy(8.dp),-        ) {-            item(key = "select-label") {-                androidx.tv.material3.Text(-                    text = stringResource(R.string.label_select_subscriptions),-                    style = androidx.tv.material3.MaterialTheme.typography.titleMedium,-                )-            }-            items(subscriptions, key = { it.id }) { subscription ->-                val checked = subscription in selectedSubscriptions-                TvListRow(-                    headline = subscription.name.decodeHtml(),-                    trailing = if (checked) {-                        { IconCheck() }-                    } else {-                        null-                    },-                    selected = checked,-                    onClick = {-                        selectedSubscriptions = if (checked) {-                            selectedSubscriptions - subscription+    TvSettingsBody {+        Column(Modifier.fillMaxSize()) {+            TvScreenHeader(+                title = if (id == null) {+                    stringResource(R.string.title_create_subscription_category)+                } else {+                    stringResource(R.string.title_update_subscription_category)+                },+                actions = {+                    TvButton(+                        text = if (id == null) {+                            stringResource(UiR.string.create)+                        } else {+                            stringResource(R.string.action_update)+                        },+                        onClick = {+                            scope.launch {+                                ypvm.replaceCategory(id, categoryName, selectedSubscriptions.map { it.id })+                                backStack.pop()+                            }+                        },+                        enabled = canConfirm,+                        primary = true,+                    )+                },+            )+            TvTextField(+                value = categoryName,+                onValueChange = { categoryName = it },+                placeholder = stringResource(R.string.label_category_name),+                focusRequester = nameFocus,+                modifier = Modifier.fillMaxWidth().padding(start = 48.dp, end = 48.dp, bottom = 8.dp),+            )+            LazyColumn(+                state = rememberLazyListState(),+                modifier = Modifier.fillMaxSize(),+                contentPadding = tvContentPadding(),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {+                item(key = "select-label") {+                    androidx.tv.material3.Text(+                        text = stringResource(R.string.label_select_subscriptions),+                        style = androidx.tv.material3.MaterialTheme.typography.titleMedium,+                    )+                }+                items(subscriptions, key = { it.id }) { subscription ->+                    val checked = subscription in selectedSubscriptions+                    TvListRow(+                        headline = subscription.name.decodeHtml(),+                        trailing = if (checked) {+                            { IconCheck() }                         } else {-                            selectedSubscriptions + subscription-                        }-                    },-                )+                            null+                        },+                        selected = checked,+                        onClick = {+                            selectedSubscriptions = if (checked) {+                                selectedSubscriptions - subscription+                            } else {+                                selectedSubscriptions + subscription+                            }+                        },+                    )+                }             }         }     }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.ktindex 755dd5d502..8da4c892f5 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.kt@@ -42,12 +42,13 @@ fun TvCreatePlaylistPage(     val canCreate = name.isNotBlank() && allPlaylists.none { it.name == name.trim() }      TvInitialFocus(createFocus)-    Column(Modifier.fillMaxSize()) {-        TvScreenHeader(title = stringResource(R.string.title_create_playlist))-        Column(-            Modifier.padding(start = 48.dp, end = 48.dp),-            verticalArrangement = Arrangement.spacedBy(16.dp),-        ) {+    TvSettingsBody {+        Column(Modifier.fillMaxSize()) {+            TvScreenHeader(title = stringResource(R.string.title_create_playlist))+            Column(+                Modifier.padding(start = 48.dp, end = 48.dp),+                verticalArrangement = Arrangement.spacedBy(16.dp),+            ) {             TvTextField(                 value = name,                 onValueChange = { name = it },@@ -78,6 +79,7 @@ fun TvCreatePlaylistPage(                     onClick = { backStack.pop() },                 )             }+            }         }     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.ktindex 6c1141ed85..240f47fb94 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.kt@@ -65,10 +65,11 @@ fun TvDataSettingsPage(      Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {         TvScreenHeader(title = stringResource(R.string.settings_data))-        Column(-            Modifier.padding(start = 48.dp, end = 48.dp, bottom = 44.dp),-            verticalArrangement = Arrangement.spacedBy(8.dp),-        ) {+        TvSettingsBody {+            Column(+                Modifier.padding(start = 48.dp, end = 48.dp, bottom = 44.dp),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {             if (isLoading) {                 CircularProgressIndicator(progress = { progress })             }@@ -101,6 +102,7 @@ fun TvDataSettingsPage(                 headline = stringResource(R.string.label_import_youtube),                 onClick = { youtubeLauncher.launch("application/zip") },             )+            }         }     }     if (confirmClear) {
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.ktindex d34f50c6a7..824ab170e2 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.kt@@ -3,11 +3,6 @@ package com.vayunmathur.youpipe.tv import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue@@ -16,19 +11,20 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp+import com.vayunmathur.library.image.ImageRequest+import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid+import com.vayunmathur.library.tv.TvInfoCard import com.vayunmathur.library.tv.TvInitialFocus-import com.vayunmathur.library.tv.TvProgressStrip-import com.vayunmathur.library.tv.TvRowCard import com.vayunmathur.library.tv.TvScreenHeader-import com.vayunmathur.library.tv.TvShelf-import com.vayunmathur.library.tv.tvContentPadding-import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.tv.tvFullWidth+import com.vayunmathur.library.tv.tvGridHeader import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.R as UiR@@ -38,9 +34,10 @@ import com.vayunmathur.youpipe.util.DownloadManager import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV downloads: active downloads with cancel + completed downloads as a grid, with D-pad- * multiselect. Mirrors the phone `DownloadedVideosPage` binding (activeDownloads +- * downloadedVideosByRecency). Selection deletes; BACK clears first.+ * TV downloads: active downloads as full-width [TvInfoCard]s with progress, completed+ * downloads as a 4-column grid of thumbnails, with D-pad multiselect. Mirrors the phone+ * `DownloadedVideosPage` binding (activeDownloads + downloadedVideosByRecency).+ * Selection deletes; BACK clears first.  */ @Composable fun TvDownloadsPage(@@ -53,6 +50,8 @@ fun TvDownloadsPage(     val historyById = remember(downloadedVideos) { emptyMap<Long, Long>() }     val context = LocalContext.current     val firstFocus = remember { FocusRequester() }+    val activeTitle = stringResource(R.string.download)+    val doneTitle = stringResource(R.string.title_downloads)      var selectedIds by remember { mutableStateOf(setOf<Long>()) }     var selectedActiveIds by remember { mutableStateOf(setOf<Long>()) }@@ -104,78 +103,71 @@ fun TvDownloadsPage(             },         )         val activeList = remember(activeDownloads) { activeDownloads.toList() }-        if (activeList.isNotEmpty()) {-            // Active downloads: progress rows. Cancel lives in the header delete flow —-            // long-press a row to select it, then delete cancels the download. No nested-            // buttons: a D-pad cannot land "inside" a row.-            TvShelf(title = stringResource(R.string.download)) {-                items(-                    activeList.size,-                    key = { index -> "active-${activeList[index].first}" },-                ) { index ->+        if (rows.isEmpty() && activeList.isEmpty()) {+            TvEmptyState(title = stringResource(R.string.playlist_empty))+            return@Column+        }+        TvGrid(columns = TV_GRID_COLUMNS, modifier = Modifier.fillMaxSize().weight(1f)) {+            if (activeList.isNotEmpty()) {+                tvGridHeader(+                    key = "active-header",+                    title = activeTitle,+                    first = true,+                )+                items(activeList.size, key = { index -> "active-${activeList[index].first}" }) { index ->                     val (videoID, status) = activeList[index]                     val isSelected = videoID in selectedActiveIds-                    TvRowCard(+                    fun toggle() {+                        selectedActiveIds = if (isSelected) {+                            selectedActiveIds - videoID+                        } else {+                            selectedActiveIds + videoID+                        }+                    }+                    TvInfoCard(                         title = status.videoInfo.name,+                        onClick = { if (isSelectionMode) toggle() },                         subtitle = "${(status.progress * 100).toInt()}%" +                             if (isSelected) "  •  ✓" else "",                         leading = {-                            CircularProgressIndicator(-                                progress = { status.progress.toFloat() },-                                modifier = Modifier.size(40.dp),-                            )-                        },-                        width = 420.dp,-                        onClick = {-                            if (isSelectionMode) {-                                selectedActiveIds = if (isSelected) {-                                    selectedActiveIds - videoID-                                } else {-                                    selectedActiveIds + videoID-                                }-                            }-                        },-                        onLongClick = {-                            selectedActiveIds = if (isSelected) {-                                selectedActiveIds - videoID-                            } else {-                                selectedActiveIds + videoID+                            if (status.videoInfo.thumbnailURL.isNotEmpty()) {+                                AsyncImage(+                                    model = ImageRequest.Builder(context)+                                        .data(status.videoInfo.thumbnailURL)+                                        .memoryCacheKey("dl-thumb-$videoID")+                                        .build(),+                                    contentDescription = null,+                                    modifier = Modifier.fillMaxSize(),+                                    contentScale = ContentScale.Crop,+                                )                             }                         },+                        leadingSize = 96.dp,+                        progress = status.progress.toFloat(),+                        onLongClick = ::toggle,                     )                 }             }-        }-        if (rows.isEmpty() && activeList.isEmpty()) {-            TvEmptyState(title = stringResource(R.string.playlist_empty))-            return@Column-        }-        LazyVerticalGrid(-            columns = GridCells.Fixed(TV_GRID_COLUMNS),-            state = rememberLazyGridState(),-            modifier = Modifier.fillMaxSize().padding(top = 8.dp),-            contentPadding = tvContentPadding(),-            verticalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(28.dp),-            horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(20.dp),-        ) {-            items(rows.size, key = { rows[it].row.videoID }) { index ->-                val item = rows[index]-                val isSelected = item.info.videoID in selectedIds-                TvSelectableCard(-                    item = item,-                    selected = isSelected,-                    inSelectionMode = isSelectionMode,-                    onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },-                    onToggleSelect = {-                        val id = item.info.videoID-                        selectedIds = if (isSelected) selectedIds - id else selectedIds + id-                    },-                    modifier = if (index == 0 && activeList.isEmpty()) {-                        Modifier.focusRequester(firstFocus)-                    } else {-                        Modifier-                    },+            if (rows.isNotEmpty()) {+                tvGridHeader(+                    key = "done-header",+                    title = doneTitle,+                    first = activeList.isEmpty(),                 )+                items(rows.size, key = { rows[it].row.videoID }) { index ->+                    val item = rows[index]+                    val isSelected = item.info.videoID in selectedIds+                    TvSelectableCard(+                        item = item,+                        selected = isSelected,+                        inSelectionMode = isSelectionMode,+                        onOpen = { backStack.playVideo(item.row.videoID) },+                        onToggleSelect = {+                            val id = item.info.videoID+                            selectedIds = if (isSelected) selectedIds - id else selectedIds + id+                        },+                    )+                }             }         }     }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDpadInput.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDpadInput.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDpadInput.ktindex 50d6bf6fe6..eeb9c45c70 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDpadInput.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDpadInput.kt@@ -1,37 +1,27 @@ package com.vayunmathur.youpipe.tv -import android.app.Activity-import android.media.AudioManager import android.view.KeyEvent-import androidx.core.content.getSystemService import com.vayunmathur.youpipe.platform.CastPlayback-import kotlin.math.roundToInt  /**- * The TV remote map, copied from `cast/tv`'s `MirrorActivity.dispatchKeyEvent` — not imported,- * because the receiver's commands cross a socket while these drive the local MediaController.+ * The TV remote map for the player, modelled on YouTube for TV.  *- * Attached by [TvMainActivity] so every TV screen shares one map:+ * Controls hidden (just watching):+ * - CENTER/ENTER/UP/DOWN: bring the controls up (focus lands on play/pause); the press that+ *   wakes them does not also act, so nobody loses their place by accident.+ * - LEFT/RIGHT: ±10s scrub preview while held, committed on release - no need to open anything.  *- * - CENTER/ENTER: toggle play/pause (when controls are visible; otherwise reveal them first).- * - LEFT/RIGHT: ±10s scrub preview while held, committed on release (KEY_UP).- * - UP/DOWN: nudge the shared `STREAM_MUSIC` volume — the same level the phone owns, so it- *   survives the session and still applies when playback comes back to the phone.- * - NEXT/PREV: related-video next / back-stack previous, via `CastPlayback.onNavigate`- *   (the player screen installs it; with nothing installed the keys fall through).- * - BACK: dismiss the overlay first (transport, chapter sheet, dialog), only then navigate.- *   The overlay registers itself via [overlayDismiss]; unregistered means "nothing to dismiss".+ * Controls visible: the D-pad belongs to the focus system (buttons, related row), except while+ * the seek bar holds focus, where LEFT/RIGHT scrub. Every press re-arms the auto-hide.  *- * Like the receiver, a press that wakes hidden controls does not also toggle: with nothing on- * screen the press reads as "show me the controls", and pausing instead would cost the user- * their place. Skips and volume are unambiguous and always act.+ * Media keys (play/pause/next/prev/FF/REW) act whenever a player is attached. BACK dismisses the+ * topmost overlay first via [overlayDismiss]; only then does it navigate. Volume keys are left to+ * the system, which already moves the shared media level.  */ object TvDpadInput {     /**      * Dismiss the topmost overlay if one is showing; true when something was dismissed.-     *-     * The player screen sets this while the transport, chapter sheet or a dialog is up.-     * Last writer wins — only one TV screen is ever composed at a time.+     * Last writer wins - only one player is ever composed at a time.      */     var overlayDismiss: (() -> Boolean)? = null @@ -39,62 +29,45 @@ object TvDpadInput {     var scrubPreviewMs: Long? = null         private set -    /**-     * Whether the player surface currently holds focus.-     *-     * Set by `TvPlayer`'s surface focus listener. The gesture map (scrub, volume, toggle) only-     * claims D-pad keys while this is true — otherwise UP/DOWN/LEFT/RIGHT belong to focus-     * traversal (related list, option rows, tab strip). Media keys (play/pause/next/prev) act-     * whenever a player is attached, wherever focus sits. This is the one difference from the-     * receiver's map, which has no focusable UI to share the remote with.-     */-    var playerFocused: Boolean = false--    private var attached: android.content.Context? = null+    /** Set by the overlay's seek bar: while it holds focus, LEFT/RIGHT scrub. */+    var seekFocused: Boolean = false -    fun attach(activity: Activity) {-        // Application context, not the activity: volume nudges outlive any composition and a-        // static activity reference would leak the whole window on rotation.-        attached = activity.applicationContext-    }--    fun detach(activity: Activity) {-        attached = null-    }+    /** Set by the player while a full-screen option sheet is open: keys go to the sheet. */+    var sheetOpen: Boolean = false -    /**-     * Handle a key before the focus system sees it. Returns true when claimed.-     *-     * Called from `TvMainActivity.dispatchKeyEvent` — the same seam `MirrorActivity` uses —-     * so volume keys are seen before the system volume UI and BACK is seen before nav.-     * BACK-dismiss runs first, scrub-commit on release second, wake-then-act third.-     */+    /** Handle a key before the focus system sees it. Returns true when claimed. */     fun onKeyEvent(event: KeyEvent): Boolean {         if (event.keyCode == KeyEvent.KEYCODE_BACK) return handleBack(event)+        if (player() == null) return false         if (event.action == KeyEvent.ACTION_UP && isScrubKey(event.keyCode)) {-            // Only a scrub this map started is committed — otherwise the release belongs to+            // Only a scrub this map started is committed; otherwise the release belongs to             // whatever (or nothing) handled the press.             if (scrubPreviewMs == null) return false             commitScrub()             return true         }         if (event.action != KeyEvent.ACTION_DOWN) return false-        // Media keys act whenever a player is attached, wherever focus sits.-        if (isMediaKey(event.keyCode)) return handleMediaKey(event)-        // The D-pad gesture map only runs while the player surface holds focus; everywhere-        // else the keys belong to focus traversal (lists, option rows, tab strip).-        if (player() == null || !playerFocused) {-            // Still wake the overlay: a press anywhere says "show me the controls".-            if (player() != null) TvTransportState.reveal()-            return false-        }-        if (TvTransportState.controlsHidden) {-            TvTransportState.reveal()-            // A press that wakes the controls does not also toggle — but scrub and volume-            // reveal the very bar they move, so they still act.-            if (isToggleKey(event.keyCode)) return true+        if (isMediaKey(event.keyCode)) return handleMediaKey(event.keyCode)+        if (sheetOpen) return false+        if (TvTransportState.controlsHidden) return handleWhileHidden(event.keyCode)+        TvTransportState.reveal()+        // A scrub in progress keeps scrubbing even before focus has landed on the seek bar.+        if ((seekFocused || scrubPreviewMs != null) && isScrubKey(event.keyCode)) {+            scrubBy(if (event.keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) SCRUB_STEP_MS else -SCRUB_STEP_MS)+            return true         }-        return handleKeyDown(event)+        return false+    }++    private fun handleWhileHidden(keyCode: Int): Boolean = when (keyCode) {+        KeyEvent.KEYCODE_DPAD_RIGHT -> { scrubBy(SCRUB_STEP_MS); true }+        KeyEvent.KEYCODE_DPAD_LEFT -> { scrubBy(-SCRUB_STEP_MS); true }+        KeyEvent.KEYCODE_DPAD_CENTER,+        KeyEvent.KEYCODE_ENTER,+        KeyEvent.KEYCODE_DPAD_UP,+        KeyEvent.KEYCODE_DPAD_DOWN,+        -> { TvTransportState.reveal(); true }+        else -> false     }      private fun handleBack(event: KeyEvent): Boolean {@@ -104,7 +77,6 @@ object TvDpadInput {         return false     } -    /** Play/pause/next/previous: no focus needed, claimed whenever a player is attached. */     private fun isMediaKey(keyCode: Int): Boolean = when (keyCode) {         KeyEvent.KEYCODE_MEDIA_PLAY,         KeyEvent.KEYCODE_MEDIA_PAUSE,@@ -117,50 +89,15 @@ object TvDpadInput {         else -> false     } -    private fun handleMediaKey(event: KeyEvent): Boolean {-        if (player() == null) return false-        when (event.keyCode) {+    private fun handleMediaKey(keyCode: Int): Boolean {+        when (keyCode) {             KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE -> toggle()-            KeyEvent.KEYCODE_MEDIA_PLAY -> setPlaying(true)-            KeyEvent.KEYCODE_MEDIA_PAUSE -> setPlaying(false)-            KeyEvent.KEYCODE_MEDIA_NEXT -> navigate(next = true)-            KeyEvent.KEYCODE_MEDIA_PREVIOUS -> navigate(next = false)-            KeyEvent.KEYCODE_MEDIA_FAST_FORWARD -> skip(forward = true)-            KeyEvent.KEYCODE_MEDIA_REWIND -> skip(forward = false)-        }-        return true-    }--    /** One D-pad press while the player surface holds focus: toggle, scrub, or volume. */-    private fun handleKeyDown(event: KeyEvent): Boolean {-        when (event.keyCode) {-            KeyEvent.KEYCODE_DPAD_CENTER,-            KeyEvent.KEYCODE_ENTER,-            KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE,-            -> toggle()--            KeyEvent.KEYCODE_MEDIA_PLAY -> setPlaying(true)-            KeyEvent.KEYCODE_MEDIA_PAUSE -> setPlaying(false)--            KeyEvent.KEYCODE_DPAD_RIGHT -> scrubBy(SCRUB_STEP_MS)-            KeyEvent.KEYCODE_DPAD_LEFT -> scrubBy(-SCRUB_STEP_MS)--            // The remote's dedicated keys, where it has them. Discrete skips, not scrub previews.-            KeyEvent.KEYCODE_MEDIA_FAST_FORWARD -> skip(forward = true)-            KeyEvent.KEYCODE_MEDIA_REWIND -> skip(forward = false)--            KeyEvent.KEYCODE_MEDIA_NEXT -> navigate(next = true)-            KeyEvent.KEYCODE_MEDIA_PREVIOUS -> navigate(next = false)--            KeyEvent.KEYCODE_DPAD_UP,-            KeyEvent.KEYCODE_VOLUME_UP,-            -> nudgeVolume(up = true)--            KeyEvent.KEYCODE_DPAD_DOWN,-            KeyEvent.KEYCODE_VOLUME_DOWN,-            -> nudgeVolume(up = false)--            else -> return false+            KeyEvent.KEYCODE_MEDIA_PLAY -> player()?.play()+            KeyEvent.KEYCODE_MEDIA_PAUSE -> player()?.pause()+            KeyEvent.KEYCODE_MEDIA_NEXT -> CastPlayback.onNavigate?.invoke(true)+            KeyEvent.KEYCODE_MEDIA_PREVIOUS -> CastPlayback.onNavigate?.invoke(false)+            KeyEvent.KEYCODE_MEDIA_FAST_FORWARD -> skip(SCRUB_STEP_MS)+            KeyEvent.KEYCODE_MEDIA_REWIND -> skip(-SCRUB_STEP_MS)         }         return true     }@@ -170,18 +107,12 @@ object TvDpadInput {     private fun toggle() {         val target = player() ?: return         if (target.isPlaying) target.pause() else target.play()-    }--    private fun setPlaying(playing: Boolean) {-        val target = player() ?: return-        if (playing) target.play() else target.pause()+        TvTransportState.reveal()     }      /**-     * Move the scrub preview, starting from live playback on the first press.-     *-     * Accumulated locally and committed once on release — one seek per gesture, not one per-     * key-repeat, which is both kinder to ExoPlayer and what holding the key means.+     * Move the scrub preview, starting from live playback on the first press. Accumulated and+     * committed once on release: one seek per gesture, not one per key-repeat.      */     private fun scrubBy(deltaMs: Long) {         val transport = CastPlayback.transport.value@@ -199,60 +130,22 @@ object TvDpadInput {         TvTransportState.reveal()     } -    private fun skip(forward: Boolean) {+    private fun skip(deltaMs: Long) {         val transport = CastPlayback.transport.value         val end = transport.durationMs.takeIf { it > 0 } ?: Long.MAX_VALUE-        val target = if (forward) {-            (transport.positionMs + SKIP_MS).coerceAtMost(end)-        } else {-            (transport.positionMs - SKIP_MS).coerceAtLeast(0)-        }+        val target = (transport.positionMs + deltaMs).coerceIn(0, end)         player()?.seekTo(target)         CastPlayback.update { it.copy(positionMs = target) }         TvTransportState.reveal()     } -    private fun navigate(next: Boolean) {-        CastPlayback.onNavigate?.invoke(next)-    }--    /**-     * Nudge the shared media volume.-     *-     * The same level the phone owns (`STREAM_MUSIC`): the remote moves it and the gain follows-     * on the next snapshot, so the level is still there when playback returns to the phone.-     */-    private fun nudgeVolume(up: Boolean) {-        val activity = attached ?: return-        val audio = activity.getSystemService<AudioManager>() ?: return-        val max = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC)-        if (max <= 0) return-        val current = audio.getStreamVolume(AudioManager.STREAM_MUSIC)-        val step = (max / VOLUME_STEPS).coerceAtLeast(1)-        val next = (current + if (up) step else -step).coerceIn(0, max)-        runCatching { audio.setStreamVolume(AudioManager.STREAM_MUSIC, next, 0) }-        TvTransportState.flashVolume(next.toFloat() / max)-    }-     private fun isScrubKey(keyCode: Int): Boolean =         keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT -    private fun isToggleKey(keyCode: Int): Boolean =-        keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||-            keyCode == KeyEvent.KEYCODE_ENTER ||-            keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE--    /** How far one D-pad press moves the scrub preview. Matches the receiver's aim-sized step. */-    const val SCRUB_STEP_MS = 10_000L--    /** Discrete skip for the dedicated FF/REW keys — matches the phone's own skip buttons. */-    private const val SKIP_MS = 10_000L--    /** Volume steps across the full range; the TV remote nudges rather than jumps. */-    private const val VOLUME_STEPS = 20-     /** Cancel a scrub without committing (overlay dismissed mid-scrub). */     fun cancelScrub() {         scrubPreviewMs = null     }++    private const val SCRUB_STEP_MS = 10_000L }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.ktindex f7653c0cf7..a4ef99593e 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.kt@@ -3,7 +3,6 @@ package com.vayunmathur.youpipe.tv import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll@@ -12,7 +11,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember-import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester@@ -34,6 +32,7 @@ import com.vayunmathur.youpipe.util.YouPipeViewModel  *  * Same DataStore bindings as the phone `GeneralSettingsPage`; dropdowns become D-pad  * option rows (one focusable row per choice) because a TV has no dropdown convention.+ * The list is constrained to a readable max width.  */ @Composable fun TvGeneralSettingsPage(@@ -55,75 +54,71 @@ fun TvGeneralSettingsPage(     }      TvInitialFocus(firstFocus)-    Column(-        Modifier.fillMaxSize().verticalScroll(rememberScrollState()),-    ) {-        TvScreenHeader(title = stringResource(R.string.settings_general_content))-        Column(-            Modifier.padding(-                start = 48.dp,-                end = 48.dp,-                bottom = 44.dp,-            ),-            verticalArrangement = Arrangement.spacedBy(8.dp),-        ) {-            Text(-                text = stringResource(R.string.label_default_page),-                style = MaterialTheme.typography.titleMedium,-            )-            com.vayunmathur.youpipe.DEFAULT_PAGE_OPTIONS.forEachIndexed { index, (key, labelRes) ->-                TvListRow(-                    headline = stringResource(labelRes),-                    trailing = if (defaultPage == key) {-                        { IconCheck() }-                    } else {-                        null-                    },-                    onClick = { ypvm.setDefaultPage(key) },-                    modifier = if (index == 0) Modifier.focusRequester(firstFocus) else Modifier,+    TvSettingsBody {+        Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {+            TvScreenHeader(title = stringResource(R.string.settings_general_content))+            Column(+                Modifier.padding(start = 48.dp, end = 48.dp, bottom = 44.dp),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {+                Text(+                    text = stringResource(R.string.label_default_page),+                    style = MaterialTheme.typography.titleMedium,+                )+                com.vayunmathur.youpipe.DEFAULT_PAGE_OPTIONS.forEachIndexed { index, (key, labelRes) ->+                    TvListRow(+                        headline = stringResource(labelRes),+                        trailing = if (defaultPage == key) {+                            { IconCheck() }+                        } else {+                            null+                        },+                        onClick = { ypvm.setDefaultPage(key) },+                        modifier = if (index == 0) Modifier.focusRequester(firstFocus) else Modifier,+                    )+                }+                TvSwitchRow(+                    headline = stringResource(R.string.label_dearrow),+                    supporting = stringResource(R.string.label_dearrow_description),+                    checked = deArrowEnabled,+                    onCheckedChange = { ypvm.setDeArrowEnabled(it) },+                )+                TvSwitchRow(+                    headline = stringResource(R.string.label_keep_controls_visible),+                    supporting = stringResource(R.string.label_keep_controls_visible_description),+                    checked = keepControlsVisible,+                    onCheckedChange = { ypvm.setKeepPlayerControlsVisible(it) },+                )+                TvSwitchRow(+                    headline = stringResource(R.string.label_notification_style_progress),+                    supporting = stringResource(R.string.label_notification_style_progress_description),+                    checked = notificationStyleProgress,+                    onCheckedChange = { ypvm.setNotificationStyleProgressBar(it) },+                )+                Text(+                    text = stringResource(R.string.label_youtube_language),+                    style = MaterialTheme.typography.titleMedium,                 )-            }-            TvSwitchRow(-                headline = stringResource(R.string.label_dearrow),-                supporting = stringResource(R.string.label_dearrow_description),-                checked = deArrowEnabled,-                onCheckedChange = { ypvm.setDeArrowEnabled(it) },-            )-            TvSwitchRow(-                headline = stringResource(R.string.label_keep_controls_visible),-                supporting = stringResource(R.string.label_keep_controls_visible_description),-                checked = keepControlsVisible,-                onCheckedChange = { ypvm.setKeepPlayerControlsVisible(it) },-            )-            TvSwitchRow(-                headline = stringResource(R.string.label_notification_style_progress),-                supporting = stringResource(R.string.label_notification_style_progress_description),-                checked = notificationStyleProgress,-                onCheckedChange = { ypvm.setNotificationStyleProgressBar(it) },-            )-            Text(-                text = stringResource(R.string.label_youtube_language),-                style = MaterialTheme.typography.titleMedium,-            )-            TvListRow(-                headline = stringResource(R.string.label_system_default),-                trailing = if (youtubeLanguage.isBlank()) {-                    { IconCheck() }-                } else {-                    null-                },-                onClick = { ypvm.setYouTubeLanguage("") },-            )-            YouPipeViewModel.Companion.YOUTUBE_LANGUAGES.forEach { (code, name) ->                 TvListRow(-                    headline = name,-                    trailing = if (youtubeLanguage == code) {+                    headline = stringResource(R.string.label_system_default),+                    trailing = if (youtubeLanguage.isBlank()) {                         { IconCheck() }                     } else {                         null                     },-                    onClick = { ypvm.setYouTubeLanguage(code) },+                    onClick = { ypvm.setYouTubeLanguage("") },                 )+                YouPipeViewModel.Companion.YOUTUBE_LANGUAGES.forEach { (code, name) ->+                    TvListRow(+                        headline = name,+                        trailing = if (youtubeLanguage == code) {+                            { IconCheck() }+                        } else {+                            null+                        },+                        onClick = { ypvm.setYouTubeLanguage(code) },+                    )+                }             }         }     }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.ktindex f9e2d2d307..25b708ddc4 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.kt@@ -3,10 +3,6 @@ package com.vayunmathur.youpipe.tv import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue@@ -17,13 +13,12 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvDialog import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvScreenHeader-import com.vayunmathur.library.tv.tvContentPadding import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack@@ -31,13 +26,13 @@ import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV history: a 4-column grid of [TvVideoCard]s with D-pad multiselect and a clear-all+ * TV history: a 4-column grid of video cards with D-pad multiselect and a clear-all  * action in the header.  *  * The phone uses long-press to enter selection and a FAB to delete. A TV has no long-press  * convention and no FAB within reach — CENTER on a card opens it, long-press (where the- * remote has it) OR the header "Select" toggle enters selection, and delete/clear are- * focused buttons in the header. BACK clears the selection first.+ * remote has it) toggles selection, and delete/clear are focused buttons in the header.+ * BACK clears the selection first.  */ @Composable fun TvHistoryPage(@@ -90,14 +85,7 @@ fun TvHistoryPage(             TvEmptyState(title = stringResource(R.string.empty_recommendations))             return@Column         }-        LazyVerticalGrid(-            columns = GridCells.Fixed(TV_GRID_COLUMNS),-            state = rememberLazyGridState(),-            modifier = Modifier.fillMaxSize(),-            contentPadding = tvContentPadding(top = 14.dp),-            verticalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(28.dp),-            horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(20.dp),-        ) {+        TvGrid(columns = TV_GRID_COLUMNS, modifier = Modifier.fillMaxSize().weight(1f)) {             items(rows.size, key = { rows[it].row.videoID }) { index ->                 val item = rows[index]                 val isSelected = item.row.videoID in selectedIds@@ -105,7 +93,7 @@ fun TvHistoryPage(                     item = item,                     selected = isSelected,                     inSelectionMode = inSelectionMode,-                    onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },+                    onOpen = { backStack.playVideo(item.row.videoID) },                     onToggleSelect = {                         selectedIds = if (isSelected) {                             selectedIds - item.row.videoID
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.ktindex 576581e018..405244160c 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.kt@@ -1,11 +1,6 @@ package com.vayunmathur.youpipe.tv -import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.rememberScrollState-import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState@@ -16,41 +11,25 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester-import androidx.compose.ui.layout.ContentScale-import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp-import com.vayunmathur.library.image.ImageRequest-import com.vayunmathur.library.image.compose.AsyncImage-import com.vayunmathur.library.tv.TvBackdrop import com.vayunmathur.library.tv.TvButton-import com.vayunmathur.library.tv.TvDialog import com.vayunmathur.library.tv.TvEmptyState-import com.vayunmathur.library.tv.TvHeroText+import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus-import com.vayunmathur.library.tv.TvListRow import com.vayunmathur.library.tv.TvLoading-import com.vayunmathur.library.tv.TvShelf-import com.vayunmathur.library.tv.tvContentStart-import com.vayunmathur.library.ui.IconMoreVert-import com.vayunmathur.library.ui.IconPlay+import com.vayunmathur.library.tv.tvGridHeader+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R-import com.vayunmathur.youpipe.ui.VideoInfo import com.vayunmathur.youpipe.util.YouPipeViewModel-import com.vayunmathur.youpipe.util.blockChannel-import com.vayunmathur.youpipe.util.boostChannel import com.vayunmathur.youpipe.util.loadRecommendations-import com.vayunmathur.youpipe.util.pinChannel-import com.vayunmathur.youpipe.util.removeInterest  /**- * TV home: an immersive hero for the focused video above shelves of 16:9 cards.+ * TV home: one scrolling 4-column grid of 16:9 cards, like the phone/tablet FeedGrid.  *- * The hero carries the recommendation reason as its eyebrow, with Play/Resume as the one- * primary action and "More like this" / "Not interested" / "More" as secondary buttons.- * Training actions live here and in the options dialog — never as buttons stacked inside- * every card. Continuing content gets its own "Continue watching" shelf from history.+ * Sections mirror the phone feed: Continue watching (history resume) as a header + one+ * row, then recommendations. No hero. Training actions live in the long-press options+ * dialog and the video page's visible More button — never inside cards.  */ @Composable fun TvHomeFeedPage(@@ -77,30 +56,18 @@ fun TvHomeFeedPage(         ypvm = ypvm,         historyProgressMsById = historyById,     )-    // Latest uploads across subscriptions — the same feed the subscription screen reads,-    // trimmed to one shelf here.-    val latestSubs by remember { ypvm.subscriptionVideosFor(null) }-        .collectAsState(initial = emptyList())-    val latestSubRows = rememberTvVideoRows(-        videos = remember(latestSubs) { latestSubs.take(TV_LATEST_SUBS_COUNT) },-        ypvm = ypvm,-        historyProgressMsById = historyById,-    ) -    var focusedId by remember { mutableStateOf<Long?>(null) }     var optionsFor by remember { mutableStateOf<TvVideoRow?>(null) }-    val heroItem = remember(rows, continueRows, latestSubRows, focusedId) {-        sequenceOf(rows, continueRows, latestSubRows).flatten().firstOrNull { it.row.videoID == focusedId }-            ?: rows.firstOrNull()-    }-    val playFocus = remember { FocusRequester() }+    val firstFocus = remember { FocusRequester() }+    val continueTitle = stringResource(R.string.tv_shelf_continue)+    val forYouTitle = stringResource(R.string.tv_shelf_for_you)      if (rows.isEmpty() && !recommendationsLoading) {         TvEmptyState(             title = stringResource(R.string.empty_recommendations),             action = {                 TvButton(-                    text = stringResource(com.vayunmathur.library.ui.R.string.retry),+                    text = stringResource(UiR.string.retry),                     onClick = { ypvm.loadRecommendations() },                 )             },@@ -112,107 +79,45 @@ fun TvHomeFeedPage(         return     } -    // Keyed on content arriving, not on the hero: re-keying on the hero would yank focus back-    // to Play every time a card is focused.-    TvInitialFocus(playFocus)-    Box(Modifier.fillMaxSize()) {-        heroItem?.let { hero ->-            TvBackdrop(key = hero.row.videoID) { _ ->-                if (hero.row.thumbnailURL.isNotEmpty()) {-                    val context = LocalContext.current-                    AsyncImage(-                        model = ImageRequest.Builder(context)-                            .data(hero.row.thumbnailURL)-                            .memoryCacheKey(-                                "video-thumb-${hero.row.videoID}-" +-                                    if (hero.row.deArrowThumbnail) "da" else "yt",-                            )-                            .build(),-                        contentDescription = null,-                        modifier = Modifier.fillMaxSize(),-                        contentScale = ContentScale.Crop,-                    )-                }+    TvInitialFocus(firstFocus)+    TvGrid(columns = TV_GRID_COLUMNS, modifier = Modifier.fillMaxSize()) {+        if (continueRows.isNotEmpty()) {+            tvGridHeader(+                key = "continue-header",+                title = continueTitle,+                first = true,+            )+            items(continueRows.size, key = { continueRows[it].row.videoID }) { index ->+                val item = continueRows[index]+                TvVideoCard(+                    item = item,+                    onOpen = { backStack.playVideo(item.row.videoID) },+                    onLongClick = { optionsFor = item },+                    modifier = if (index == 0) {+                        Modifier.focusRequester(firstFocus)+                    } else {+                        Modifier+                    },+                )             }         }-        Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {-            heroItem?.let { hero ->-                Column(Modifier.padding(start = tvContentStart(), top = 56.dp, bottom = 28.dp)) {-                    TvHeroText(-                        title = hero.row.title,-                        eyebrow = hero.row.reason?.let {-                            LocalContext.current.getString(R.string.recommendation_reason, it)-                        },-                        meta = listOfNotNull(-                            hero.row.author,-                            hero.row.stats.takeIf { it.isNotBlank() },-                        ),-                        actions = {-                            val watched = historyById[hero.row.videoID] ?: 0L-                            TvButton(-                                text = stringResource(-                                    if (watched > 0L) R.string.tv_action_resume-                                    else com.vayunmathur.library.ui.R.string.play,-                                ),-                                onClick = { backStack.add(TvRoute.Video(hero.row.videoID)) },-                                icon = { IconPlay() },-                                primary = true,-                                modifier = Modifier.focusRequester(playFocus),-                            )-                            TvButton(-                                text = stringResource(R.string.action_more_like_this),-                                onClick = { ypvm.boostChannel(hero.row.channelKey) },-                            )-                            TvButton(-                                text = stringResource(R.string.action_not_interested),-                                onClick = { ypvm.removeInterest(channelKey = hero.row.channelKey) },-                            )-                            TvButton(-                                text = stringResource(R.string.tv_action_video_options),-                                onClick = { optionsFor = hero },-                                icon = { IconMoreVert() },-                            )-                        },-                    )-                }-            }-            if (continueRows.isNotEmpty()) {-                TvShelf(title = stringResource(R.string.tv_shelf_continue)) {-                    items(continueRows.size, key = { continueRows[it].row.videoID }) { index ->-                        val item = continueRows[index]-                        TvVideoCard(-                            item = item,-                            onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },-                            onFocus = { focusedId = item.row.videoID },-                            onLongClick = { optionsFor = item },-                        )-                    }-                }-            }-            if (latestSubRows.isNotEmpty()) {-                TvShelf(title = stringResource(R.string.tv_shelf_latest_subs)) {-                    items(latestSubRows.size, key = { latestSubRows[it].row.videoID }) { index ->-                        val item = latestSubRows[index]-                        TvVideoCard(-                            item = item,-                            onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },-                            onFocus = { focusedId = item.row.videoID },-                            onLongClick = { optionsFor = item },-                        )-                    }-                }-            }-            TvShelf(title = stringResource(R.string.tv_shelf_for_you)) {-                items(rows.size, key = { rows[it].row.videoID }) { index ->-                    val item = rows[index]-                    TvVideoCard(-                        item = item,-                        onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },-                        onFocus = { focusedId = item.row.videoID },-                        onLongClick = { optionsFor = item },-                    )-                }-            }+        tvGridHeader(+            key = "for-you-header",+            title = forYouTitle,+            first = continueRows.isEmpty(),+        )+        items(rows.size, key = { rows[it].row.videoID }) { index ->+            val item = rows[index]+            TvVideoCard(+                item = item,+                onOpen = { backStack.playVideo(item.row.videoID) },+                onLongClick = { optionsFor = item },+                modifier = if (continueRows.isEmpty() && index == 0) {+                    Modifier.focusRequester(firstFocus)+                } else {+                    Modifier+                },+            )         }     } @@ -220,86 +125,10 @@ fun TvHomeFeedPage(         TvVideoOptionsDialog(             item = item,             onDismiss = { optionsFor = null },-            onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },+            onOpen = { backStack.playVideo(item.row.videoID) },             ypvm = ypvm,         )     } } -/**- * The recommendation-training dialog: not-interested / more-like / pin / block for one- * video's channel. Opened via long-press AND the hero's visible "More" button — never- * buttons stacked inside every card.- */-@Composable-internal fun TvVideoOptionsDialog(-    item: TvVideoRow,-    onDismiss: () -> Unit,-    onOpen: () -> Unit,-    ypvm: YouPipeViewModel,-) {-    TvDialog(-        title = item.row.title,-        onDismissRequest = onDismiss,-        body = listOfNotNull(item.row.author, item.row.stats.takeIf { it.isNotBlank() })-            .joinToString("  •  ").takeIf { it.isNotBlank() },-        buttons = {-            TvButton(text = stringResource(com.vayunmathur.library.ui.R.string.play), onClick = {-                onDismiss()-                onOpen()-            }, primary = true)-            TvButton(-                text = stringResource(com.vayunmathur.library.ui.R.string.close),-                onClick = onDismiss,-            )-        },-        content = {-            TvOptionsList(item, onDismiss, ypvm)-        },-    )-}--/** The four training rows of the video options dialog. Split for FileLength. */-@Composable-private fun TvOptionsList(-    item: TvVideoRow,-    onDismiss: () -> Unit,-    ypvm: YouPipeViewModel,-) {-    Column {-        TvListRow(-            headline = stringResource(R.string.action_not_interested),-            supporting = item.row.reason?.let {-                LocalContext.current.getString(R.string.recommendation_reason, it)-            },-            onClick = {-                ypvm.removeInterest(channelKey = item.row.channelKey)-                onDismiss()-            },-        )-        TvListRow(-            headline = stringResource(R.string.action_more_like_this),-            onClick = {-                ypvm.boostChannel(item.row.channelKey)-                onDismiss()-            },-        )-        TvListRow(-            headline = stringResource(R.string.action_pin_channel),-            onClick = {-                ypvm.pinChannel(item.row.channelKey)-                onDismiss()-            },-        )-        TvListRow(-            headline = stringResource(R.string.action_block_channel),-            onClick = {-                ypvm.blockChannel(item.row.channelKey)-                onDismiss()-            },-        )-    }-}--private const val TV_CONTINUE_COUNT = 10-private const val TV_LATEST_SUBS_COUNT = 12+private const val TV_CONTINUE_COUNT = 4
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.ktindex 96694bd0e5..e39cfd7b32 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.kt@@ -2,23 +2,12 @@ package com.vayunmathur.youpipe.tv  import android.view.KeyEvent import androidx.activity.viewModels-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Text import com.vayunmathur.library.tv.MaTvTheme import com.vayunmathur.library.tv.TvAccent-import com.vayunmathur.library.tv.TvIcon-import com.vayunmathur.library.ui.IconPlay import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.youpipe.DEFAULT_PAGE_KEY-import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.data.SubscriptionRepository import com.vayunmathur.youpipe.util.YouPipeViewModel import com.vayunmathur.youpipe.util.YouPipeViewModelFactory@@ -49,12 +38,6 @@ class TvMainActivity : MaActivity() {         // Honor the "Open to" default page (same DataStore key + mapping the phone uses),         // read synchronously here because this runs in onCreate before setContent.         initialBackStack = tvDefaultBackStack(DataStoreUtils.getInstance(this).getString(DEFAULT_PAGE_KEY))-        TvDpadInput.attach(this)-    }--    override fun onDestroy() {-        TvDpadInput.detach(this)-        super.onDestroy()     }      /**@@ -80,18 +63,3 @@ class TvMainActivity : MaActivity() {         TvNavigation(youPipeViewModel, initialBackStack)     } }--/** The rail brand: play glyph + "YouPipe", shown at the top of the expanded rail. */-@Composable-internal fun TvBrand(modifier: Modifier = Modifier) {-    Row(modifier, verticalAlignment = Alignment.CenterVertically) {-        TvIcon { IconPlay() }-        Text(-            text = stringResource(R.string.app_name),-            style = MaterialTheme.typography.titleLarge,-            color = MaterialTheme.colorScheme.onSurface,-            maxLines = 1,-            modifier = Modifier.padding(start = 12.dp),-        )-    }-}
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.ktindex cec3de2ecd..bc30a79a41 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.kt@@ -73,12 +73,13 @@ fun TvManageInterestsPage(     }      TvInitialFocus(firstFocus)-    LazyColumn(-        state = rememberLazyListState(),-        modifier = Modifier.fillMaxSize(),-        contentPadding = tvContentPadding(top = 28.dp),-        verticalArrangement = Arrangement.spacedBy(8.dp),-    ) {+    TvSettingsBody {+        LazyColumn(+            state = rememberLazyListState(),+            modifier = Modifier.fillMaxSize(),+            contentPadding = tvContentPadding(top = 28.dp),+            verticalArrangement = Arrangement.spacedBy(8.dp),+        ) {         item(key = "interests-title") {             Text(                 text = stringResource(R.string.title_manage_interests),@@ -156,6 +157,7 @@ fun TvManageInterestsPage(                 onPrimary = { ypvm.unmuteKeyword(keyword) },             )         }+        }     } } 
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.ktindex cb1c3958bc..63be0855a2 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.kt@@ -109,7 +109,6 @@ private fun TvRailHost(         destinations = destinations,         selected = rail,         onSelect = { rail = it },-        brand = { TvBrand() },         // This frame is always the bottom of the TV stack: BACK from content returns to         // the rail, and BACK from the rail exits (the activity finishes).         backReturnsToRail = backStack.backStack.size <= 1,
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayer.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayer.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayer.ktindex 0deca15583..f3c56c325f 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayer.kt@@ -5,6 +5,7 @@ import android.text.format.DateUtils import android.view.WindowManager import androidx.annotation.OptIn import androidx.compose.foundation.background+import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column@@ -88,13 +89,15 @@ import kotlin.math.min  */ @OptIn(UnstableApi::class) @Composable-fun TvPlayer(+internal fun TvPlayer(     ypvm: YouPipeViewModel,     videoInfo: VideoInfo,     videoStreams: List<VideoStream>,     audioStreams: List<AudioStream>,     subtitles: List<SubtitleTrack>,     segments: List<VideoChapter>,+    startPositionMs: Long,+    chrome: TvPlayerChrome, ) {     if (videoStreams.isEmpty()) return     val context = LocalContext.current@@ -181,6 +184,9 @@ fun TvPlayer(     }      // Media item: same extras contract (audio URI + itag) the SABR source resolves in-process.+    // The first load starts at the resume point; a later reload (quality, language, captions)+    // keeps the current position instead of restarting the video.+    var started by remember(videoInfo.videoID) { mutableStateOf(false) }     LaunchedEffect(controller, currentVideoStream, currentAudioStream, videoInfo.name, subtitles) {         val player = controller ?: return@LaunchedEffect         val metadata = MediaMetadata.Builder()@@ -199,7 +205,9 @@ fun TvPlayer(                 },             )             .build()-        player.setMediaItem(item)+        val startAt = if (started) player.currentPosition.coerceAtLeast(0L) else startPositionMs+        started = true+        player.setMediaItem(item, startAt)         player.prepare()         player.play()     }@@ -257,7 +265,12 @@ fun TvPlayer(         controller?.playbackParameters = PlaybackParameters(transport.speed, pitch)     } -    // BACK dismisses the topmost overlay first: chapter sheet, then menus, then transport.+    // BACK dismisses the topmost overlay first: option sheets, then the controls.+    val anySheet = showChapters || showQuality || showLanguage || showCaptions || showSpeed+    DisposableEffect(anySheet) {+        TvDpadInput.sheetOpen = anySheet+        onDispose { TvDpadInput.sheetOpen = false }+    }     DisposableEffect(showChapters, showQuality, showLanguage, showCaptions, showSpeed, overlayVisible) {         TvDpadInput.overlayDismiss = {             when {@@ -293,7 +306,7 @@ fun TvPlayer(                 modifier = Modifier                     .fillMaxSize()                     .focusRequester(focusRequester)-                    .onFocusChanged { TvDpadInput.playerFocused = it.isFocused },+                    .focusable(),                 surfaceType = SURFACE_TYPE_SURFACE_VIEW,             )         } ?: Box(Modifier.fillMaxSize().background(Color.Black))@@ -326,6 +339,7 @@ fun TvPlayer(             onShowCaptions = { showCaptions = it },             showSpeed = showSpeed,             onShowSpeed = { showSpeed = it },+            chrome = chrome,         )     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerChrome.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerChrome.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerChrome.ktnew file mode 100644index 0000000000..279eee2da1--- /dev/null+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerChrome.kt@@ -0,0 +1,113 @@+package com.vayunmathur.youpipe.tv++import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.platform.LocalResources+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.rememberMessenger+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.youpipe.R+import com.vayunmathur.youpipe.data.Subscription+import com.vayunmathur.youpipe.ui.VideoData+import com.vayunmathur.youpipe.ui.VideoInfo+import com.vayunmathur.youpipe.ui.countString+import com.vayunmathur.youpipe.ui.uploadTimeAgo+import com.vayunmathur.youpipe.util.YouPipeViewModel++/** Everything the player overlay shows around the video, and what its buttons do. */+internal class TvPlayerChrome(+    val byline: String,+    val avatarUrl: String,+    val subscribed: Boolean,+    val related: List<TvVideoRow>,+    val onToggleSubscribe: () -> Unit,+    val onChannel: () -> Unit,+    val onDetails: () -> Unit,+    val onWatchLater: () -> Unit,+    val onSaveToPlaylist: () -> Unit,+    val onPlayRelated: (Long) -> Unit,+)++@Composable+internal fun rememberTvPlayerChrome(+    backStack: NavBackStack<TvRoute>,+    ypvm: YouPipeViewModel,+    videoID: Long,+    data: VideoData,+    relatedVideos: List<VideoInfo>,+): TvPlayerChrome {+    val context = LocalContext.current+    val resources = LocalResources.current+    val subscriptions by ypvm.subscriptions.collectAsState()+    val playlists by ypvm.playlists.collectAsState()+    val history by ypvm.historyVideos.collectAsState()+    val historyById = remember(history) { history.associate { it.id to it.progress } }+    val related = rememberTvVideoRows(relatedVideos, ypvm, historyById)+    val messenger = rememberMessenger()+    val addedToWatchLater = stringResource(R.string.tv_added_to_watch_later)+    val existingSub = subscriptions.firstOrNull { it.channelID == data.authorURL }+    val byline = if (data.views < 0) {+        resources.getString(R.string.video_info_paid_format, data.author, uploadTimeAgo(context, data.uploadDate))+    } else {+        resources.getString(+            R.string.video_info_format,+            data.author,+            countString(context, data.views),+            uploadTimeAgo(context, data.uploadDate),+        )+    }+    return TvPlayerChrome(+        byline = byline,+        avatarUrl = data.authorThumbnail,+        subscribed = existingSub != null,+        related = related,+        onToggleSubscribe = {+            if (existingSub == null) {+                ypvm.upsertSubscription(+                    Subscription(name = data.author, channelID = data.authorURL, avatarURL = data.authorThumbnail),+                )+            } else {+                ypvm.deleteSubscription(existingSub)+            }+        },+        onChannel = { backStack.add(TvRoute.Channel(data.authorURL)) },+        onDetails = { backStack.add(TvRoute.Video(videoID)) },+        onWatchLater = {+            playlists.firstOrNull { it.mandatory }?.let { watchLater ->+                ypvm.playlistOps.addVideoToPlaylist(+                    watchLater.id,+                    VideoInfo(+                        data.title, videoID, data.duration, data.views,+                        data.uploadDate, data.thumbnailURL, data.author,+                    ),+                )+                messenger.show(addedToWatchLater)+            }+        },+        onSaveToPlaylist = { backStack.add(TvRoute.AddToPlaylist(videoID, includeWatchLater = false)) },+        onPlayRelated = { backStack.setLast(TvRoute.VideoPlayerRoute(it)) },+    )+}++/** Selecting a video on TV plays it; details live behind the player's Details button. */+internal fun NavBackStack<TvRoute>.playVideo(videoID: Long) {+    add(TvRoute.VideoPlayerRoute(videoID))+}++/**+ * Play from the details page: if the details were opened from this video's player, go back to+ * it (playback never stopped) instead of stacking a second player.+ */+internal fun NavBackStack<TvRoute>.playFromDetails(videoID: Long) {+    val entries = backStack+    val previous = entries.getOrNull(entries.size - 2)+    if (previous is TvRoute.VideoPlayerRoute && previous.videoID == videoID) pop() else playVideo(videoID)+}++/** Which video `videoState` currently holds; `VideoData` carries no ID of its own. */+internal object TvLoadedVideo {+    var id: Long? = null+}
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerControls.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerControls.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerControls.ktnew file mode 100644index 0000000000..2c6a766a2b--- /dev/null+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerControls.kt@@ -0,0 +1,219 @@+package com.vayunmathur.youpipe.tv++import androidx.compose.foundation.BorderStroke+import androidx.compose.foundation.focusable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableLongStateOf+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.runtime.withFrameMillis+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.focus.onFocusChanged+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.tv.material3.Border+import androidx.tv.material3.ClickableSurfaceDefaults+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Surface+import androidx.tv.material3.Text+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog+import com.vayunmathur.library.tv.TvIcon+import com.vayunmathur.library.tv.TvIconButton+import com.vayunmathur.library.tv.TvListRow+import com.vayunmathur.library.tv.TvSeekBar+import com.vayunmathur.library.ui.IconClosedCaption+import com.vayunmathur.library.ui.IconPause+import com.vayunmathur.library.ui.IconPlay+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.youpipe.R+import com.vayunmathur.youpipe.platform.CastPlayback+import com.vayunmathur.youpipe.util.YouPipeViewModel++/** What the overlay's settings gear offers, with the current value of each. */+internal class TvPlayerSettings(+    val qualityLabel: String,+    val speed: Float,+    val hasChapters: Boolean,+    val hasLanguage: Boolean,+    val onQuality: () -> Unit,+    val onSpeed: () -> Unit,+    val onLanguage: () -> Unit,+    val onChapters: () -> Unit,+)++/**+ * Elapsed and total above a thin full-width bar, YouTube-style. Focusable: while it holds+ * focus the bar thickens and [TvDpadInput] turns LEFT/RIGHT into scrubbing.+ */+@Composable+internal fun TvPlayerSeekBar(ypvm: YouPipeViewModel, focusRequester: FocusRequester, modifier: Modifier = Modifier) {+    var focused by remember { mutableStateOf(false) }+    val videoState by ypvm.videoState.collectAsState()+    val categories by ypvm.sponsorBlockCategories.collectAsState()+    TvPlaybackClock { positionMs ->+        val transport by CastPlayback.transport.collectAsState()+        val duration = transport.durationMs+        val position = positionMs()+        val markers = remember(videoState.segments, videoState.sponsorSegments, categories, duration) {+            if (duration <= 0) {+                emptyList()+            } else {+                videoState.segments.map { it.time.toFloat() / duration } ++                    videoState.sponsorSegments.filter { it.category in categories }.map { it.start.toFloat() / duration }+            }+        }+        Column(+            modifier+                .fillMaxWidth()+                .focusRequester(focusRequester)+                .onFocusChanged {+                    focused = it.isFocused+                    TvDpadInput.seekFocused = it.isFocused+                }+                .focusable(),+        ) {+            Row(Modifier.fillMaxWidth()) {+                Text(formatTvElapsed(position), style = MaterialTheme.typography.titleSmall, color = Color.White)+                Box(Modifier.weight(1f))+                if (duration > 0) {+                    Text(formatTvElapsed(duration), style = MaterialTheme.typography.titleSmall, color = Color.White)+                }+            }+            TvSeekBar(+                progress = if (duration > 0) position.toFloat() / duration else 0f,+                buffered = if (duration > 0) transport.bufferedMs.toFloat() / duration else 0f,+                active = focused || TvDpadInput.scrubPreviewMs != null,+                markers = markers,+            )+        }+    }+}++/** The big round play/pause in the middle of the control row. */+@Composable+internal fun TvPlayPauseButton(modifier: Modifier = Modifier) {+    val transport by CastPlayback.transport.collectAsState()+    TvIconButton(+        onClick = {+            val player = CastPlayback.attachedPlayer ?: return@TvIconButton+            if (player.isPlaying) player.pause() else player.play()+        },+        size = 72.dp,+        icon = { Box(Modifier.size(32.dp)) { if (transport.playing) IconPause(Modifier.fillMaxSize()) else IconPlay(Modifier.fillMaxSize()) } },+        modifier = modifier,+    )+}++/** The channel avatar as a round focusable button that opens the channel. */+@Composable+internal fun TvChannelAvatarButton(url: String, onClick: () -> Unit, modifier: Modifier = Modifier) {+    Surface(+        onClick = onClick,+        modifier = modifier.size(52.dp),+        shape = ClickableSurfaceDefaults.shape(CircleShape),+        border = ClickableSurfaceDefaults.border(+            focusedBorder = Border(BorderStroke(3.dp, MaterialTheme.colorScheme.inverseSurface), shape = CircleShape),+        ),+        colors = ClickableSurfaceDefaults.colors(containerColor = MaterialTheme.colorScheme.surfaceVariant),+    ) {+        if (url.isNotEmpty()) {+            AsyncImage(+                model = url,+                contentDescription = null,+                modifier = Modifier.fillMaxSize().clip(CircleShape),+                contentScale = ContentScale.Crop,+            )+        }+    }+}++/** CC toggle-style button: tinted with the accent while captions are on. */+@Composable+internal fun TvCaptionsButton(on: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier) {+    TvIconButton(+        onClick = onClick,+        modifier = modifier,+        icon = { TvIcon { if (on) IconClosedCaption(tint = MaterialTheme.colorScheme.primary) else IconClosedCaption() } },+    )+}++/** The settings gear's menu: quality, speed, audio language, chapters - each with its value. */+@Composable+internal fun TvPlayerSettingsDialog(settings: TvPlayerSettings, onDismiss: () -> Unit) {+    fun pick(action: () -> Unit): () -> Unit = {+        onDismiss()+        action()+    }+    TvDialog(+        title = stringResource(UiR.string.settings),+        onDismissRequest = onDismiss,+        content = {+            Column {+                TvListRow(+                    headline = stringResource(R.string.label_quality),+                    supporting = settings.qualityLabel,+                    onClick = pick(settings.onQuality),+                )+                TvListRow(+                    headline = stringResource(R.string.label_speed),+                    supporting = formatTvSpeedLabel(settings.speed),+                    onClick = pick(settings.onSpeed),+                )+                if (settings.hasLanguage) {+                    TvListRow(headline = stringResource(R.string.language), onClick = pick(settings.onLanguage))+                }+                if (settings.hasChapters) {+                    TvListRow(headline = stringResource(R.string.tv_section_chapters), onClick = pick(settings.onChapters))+                }+            }+        },+        buttons = { TvButton(text = stringResource(UiR.string.close), onClick = onDismiss) },+    )+}++/**+ * Owns the one per-frame clock the player overlay needs and hands it down as a lambda, so only+ * the readers invalidate sixty times a second. Stops ticking while paused.+ */+@Composable+internal fun TvPlaybackClock(content: @Composable (positionMs: () -> Long) -> Unit) {+    val transport by CastPlayback.transport.collectAsState()+    var frameNowMs by remember { mutableLongStateOf(System.currentTimeMillis()) }+    LaunchedEffect(transport.positionMs, transport.playing) {+        frameNowMs = System.currentTimeMillis()+        if (!transport.playing) return@LaunchedEffect+        while (true) {+            withFrameMillis { frameNowMs = System.currentTimeMillis() }+        }+    }+    content { TvDpadInput.scrubPreviewMs ?: transport.positionMs }+}++/** `H:MM:SS` past an hour, `M:SS` below it. */+internal fun formatTvElapsed(positionMs: Long): String {+    val totalSeconds = (positionMs / 1_000).coerceAtLeast(0)+    val hours = totalSeconds / 3_600+    val minutes = (totalSeconds % 3_600) / 60+    val seconds = totalSeconds % 60+    return if (hours > 0) "%d:%02d:%02d".format(hours, minutes, seconds) else "%d:%02d".format(minutes, seconds)+}
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerOverlays.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerOverlays.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerOverlays.ktindex b81dc5534b..c8c93ad770 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerOverlays.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerOverlays.kt@@ -36,41 +36,9 @@ import com.vayunmathur.youpipe.ui.VideoInfo import com.vayunmathur.youpipe.ui.VideoStream import com.vayunmathur.youpipe.util.YouPipeViewModel -/** The focusable option row: chapters / quality / language / captions / speed. */-@Composable-internal fun TvPlayerOptionsRow(-    onChapters: () -> Unit,-    onQuality: () -> Unit,-    onLanguage: () -> Unit,-    onCaptions: () -> Unit,-    onSpeed: () -> Unit,-    hasChapters: Boolean,-    hasLanguage: Boolean,-    hasCaptions: Boolean,-    modifier: Modifier = Modifier,-) {-    Row(-        modifier = modifier,-        horizontalArrangement = Arrangement.spacedBy(12.dp),-    ) {-        if (hasChapters) {-            TvButton(text = stringResource(R.string.chapter), onClick = onChapters)-        }-        TvButton(text = stringResource(R.string.label_quality), onClick = onQuality)-        if (hasLanguage) {-            TvButton(text = stringResource(R.string.language), onClick = onLanguage)-        }-        if (hasCaptions) {-            TvButton(text = stringResource(R.string.label_captions), onClick = onCaptions)-        }-        TvButton(text = stringResource(R.string.label_speed), onClick = onSpeed)-    }-}- /**- * Subtitle cues, buffering spinner, transport overlay, option sheets and volume flash —- * everything drawn over the player surface. Split from [TvPlayer] (FileLength): no- * playback logic moves, only presentation.+ * Subtitle cues, buffering spinner, the YouTube-style control overlay, option sheets - everything+ * drawn over the player surface. Split from [TvPlayer] (FileLength): presentation only.  */ @Composable internal fun BoxScope.TvPlayerOverlays(@@ -101,6 +69,7 @@ internal fun BoxScope.TvPlayerOverlays(     onShowCaptions: (Boolean) -> Unit,     showSpeed: Boolean,     onShowSpeed: (Boolean) -> Unit,+    chrome: TvPlayerChrome, ) {     if (cues.isNotEmpty()) {         Column(@@ -132,29 +101,27 @@ internal fun BoxScope.TvPlayerOverlays(     }      FadeVisibility(visible = overlayVisible) {-        Box(Modifier.fillMaxSize()) {-            TvTransportOverlay(-                title = videoInfo.name,-                author = videoInfo.author,-                hasNext = transport.hasNext,-                hasPrevious = transport.hasPrevious,+        TvTransportOverlay(+            title = videoInfo.name,+            chrome = chrome,+            hasNext = transport.hasNext,+            hasPrevious = transport.hasPrevious,+            hasCaptions = subtitles.isNotEmpty(),+            captionsOn = selectedSubtitle != null,+            onCaptions = { onShowCaptions(true) },+            settings = TvPlayerSettings(+                qualityLabel = currentVideoStream.quality,                 speed = transport.speed,-                ypvm = ypvm,-                modifier = Modifier.align(Alignment.BottomCenter),-            )-            // Focusable option rows above the transport: chapters, quality, language, captions, speed.-            TvPlayerOptionsRow(-                onChapters = { onShowChapters(true) },-                onQuality = { onShowQuality(true) },-                onLanguage = { onShowLanguage(true) },-                onCaptions = { onShowCaptions(true) },-                onSpeed = { onShowSpeed(true) },                 hasChapters = segments.isNotEmpty(),                 hasLanguage = languageEntries.size > 1,-                hasCaptions = subtitles.isNotEmpty(),-                modifier = Modifier.align(Alignment.TopCenter).padding(top = 32.dp),-            )-        }+                onQuality = { onShowQuality(true) },+                onSpeed = { onShowSpeed(true) },+                onLanguage = { onShowLanguage(true) },+                onChapters = { onShowChapters(true) },+            ),+            ypvm = ypvm,+            modifier = Modifier.fillMaxSize(),+        )     }      if (showChapters) {@@ -198,23 +165,6 @@ internal fun BoxScope.TvPlayerOverlays(             onDismiss = { onShowSpeed(false) },         )     }--    val volumeFlash by TvTransportState.volumeFlash.collectAsState()-    volumeFlash?.let { level ->-        Box(-            Modifier-                .align(Alignment.TopEnd)-                .padding(32.dp)-                .background(Color.Black.copy(alpha = 0.7f))-                .padding(horizontal = 16.dp, vertical = 8.dp),-        ) {-            Text(-                text = "${(level * 100).toInt()}%",-                color = Color.White,-                style = MaterialTheme.typography.titleMedium,-            )-        }-    } } /**  * The 300ms poll loop: transport position, sponsor-block skips, periodic history writes.
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerPage.ktindex 64219ffeec..54c83a8a31 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlayerPage.kt@@ -1,27 +1,30 @@ package com.vayunmathur.youpipe.tv  import androidx.compose.runtime.Composable+import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvEmptyState import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.youpipe.R+import com.vayunmathur.youpipe.platform.CastPlayback import com.vayunmathur.youpipe.ui.VideoInfo import com.vayunmathur.youpipe.util.YouPipeViewModel import com.vayunmathur.youpipe.util.applyDownloadedStreams+import com.vayunmathur.youpipe.util.clearVideoError import com.vayunmathur.youpipe.util.loadVideo import kotlinx.coroutines.flow.first  /**- * Fullscreen playback for one video, pushed above the detail screen. BACK returns to the- * detail (the overlay dismisses first via [TvDpadInput]).- *- * Reuses the phone-equivalent load path (`loadVideo` + downloaded streams into- * `videoState`) and renders the untouched [TvPlayer] core: MediaController/PlaybackService- * setup, position loop, chapter/quality/language/caption/speed sheets. Only the transport- * overlay it draws was restyled ([TvTransportOverlay]).+ * Fullscreen playback for one video - what selecting any video on TV opens. Loads the video+ * unless `videoState` already holds it, resumes from watch history, and owns next/previous:+ * "next" plays the first related video in place, "previous" goes back the way the user came+ * (the phone's rule, since SABR needs per-video extractor state there is no real queue).  */ @Composable fun TvPlayerPage(@@ -32,33 +35,71 @@ fun TvPlayerPage(     val videoState by ypvm.videoState.collectAsState()     val downloadedFlow = remember(videoID) { ypvm.downloadedById(videoID) }     val downloadedVideo by downloadedFlow.collectAsState(initial = null)-+    val history by ypvm.historyVideos.collectAsState()     LaunchedEffect(videoID) {-        // The detail screen already loaded this video in the common push path; reload only-        // if the state belongs to something else (stale after process death).-        if (videoState.data == null) {-            val downloaded = downloadedFlow.first()-            ypvm.loadVideo(videoID, downloaded)+        if (TvLoadedVideo.id != videoID || videoState.error) {+            TvLoadedVideo.id = videoID+            ypvm.loadVideo(videoID, downloadedFlow.first())         }     }     LaunchedEffect(downloadedVideo) {         downloadedVideo?.let { ypvm.applyDownloadedStreams(it) }     } +    val related = videoState.relatedVideos+    val canGoPrevious = backStack.backStack.size > 1+    LaunchedEffect(related.isNotEmpty(), canGoPrevious) {+        CastPlayback.update { it.copy(hasNext = related.isNotEmpty(), hasPrevious = canGoPrevious) }+    }+    DisposableEffect(related, canGoPrevious) {+        val handler: (Boolean) -> Unit = { next ->+            if (next) {+                related.firstOrNull()?.let { backStack.setLast(TvRoute.VideoPlayerRoute(it.videoID)) }+            } else if (canGoPrevious) {+                backStack.pop()+            }+        }+        CastPlayback.onNavigate = handler+        onDispose { if (CastPlayback.onNavigate === handler) CastPlayback.onNavigate = null }+    }+     val data = videoState.data-    val videoStreams = videoState.videoStreams     when {-        data == null || videoStreams.isEmpty() -> TvLoading()-        else -> TvPlayer(-            ypvm = ypvm,-            videoInfo = VideoInfo(-                data.title, videoID, data.duration, data.views,-                data.uploadDate, data.thumbnailURL, data.author,-            ),-            videoStreams = videoStreams,-            audioStreams = videoState.audioStreams,-            subtitles = videoState.subtitles,-            segments = videoState.segments,+        videoState.error -> TvEmptyState(+            title = stringResource(R.string.video_load_error),+            isError = true,+            action = {+                TvButton(+                    text = stringResource(R.string.action_go_back),+                    onClick = {+                        ypvm.clearVideoError()+                        TvLoadedVideo.id = null+                        backStack.pop()+                    },+                )+            },         )+        data == null || videoState.videoStreams.isEmpty() -> TvLoading()+        else -> {+            val resumeMs = history.firstOrNull { it.id == videoID }?.progress ?: 0L+            // Finished (or nearly) videos start over rather than resuming at the credits.+            val startMs = resumeMs.takeIf { it < data.duration * MS_PER_SECOND - RESUME_TAIL_MS } ?: 0L+            TvPlayer(+                ypvm = ypvm,+                videoInfo = VideoInfo(+                    data.title, videoID, data.duration, data.views,+                    data.uploadDate, data.thumbnailURL, data.author,+                ),+                videoStreams = videoState.videoStreams,+                audioStreams = videoState.audioStreams,+                subtitles = videoState.subtitles,+                segments = videoState.segments,+                startPositionMs = startMs,+                chrome = rememberTvPlayerChrome(backStack, ypvm, videoID, data, related),+            )+        }     } }++private const val MS_PER_SECOND = 1_000L+private const val RESUME_TAIL_MS = 15_000L
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlaylistDetail.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlaylistDetail.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlaylistDetail.ktindex 86f48433da..3e1383bbea 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlaylistDetail.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvPlaylistDetail.kt@@ -3,10 +3,6 @@ package com.vayunmathur.youpipe.tv import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf@@ -17,16 +13,14 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvDialog import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvScreenHeader-import com.vayunmathur.library.tv.tvContentPadding import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconPlay import com.vayunmathur.library.ui.R as UiR@@ -36,7 +30,7 @@ import com.vayunmathur.youpipe.util.YouPipeViewModel  /**  * TV playlist detail: header (title, count, play-all, delete) + a 4-column grid of- * [TvSelectableCard]s with D-pad multiselect for removal.+ * thumbnails with D-pad multiselect for removal.  *  * The phone combines long-press selection with drag-handle reorder. Neither exists on a  * TV: CENTER opens, long-press toggles selection as a fallback, and removal is a header@@ -104,11 +98,10 @@ fun TvPlaylistDetailPage(                         TvButton(                             text = stringResource(UiR.string.play),                             onClick = {-                                backStack.add(TvRoute.Video(playlistItems.first().videoItem.videoID))+                                backStack.playVideo(playlistItems.first().videoItem.videoID)                             },                             icon = { IconPlay() },                             primary = true,-                            modifier = Modifier.focusRequester(firstFocus),                         )                     }                     if (!mandatory && playlist != null) {@@ -125,14 +118,7 @@ fun TvPlaylistDetailPage(             TvEmptyState(title = stringResource(R.string.playlist_empty))             return@Column         }-        LazyVerticalGrid(-            columns = GridCells.Fixed(TV_GRID_COLUMNS),-            state = rememberLazyGridState(),-            modifier = Modifier.fillMaxSize().padding(top = 8.dp),-            contentPadding = tvContentPadding(),-            verticalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(28.dp),-            horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(20.dp),-        ) {+        TvGrid(columns = TV_GRID_COLUMNS, modifier = Modifier.fillMaxSize().weight(1f)) {             items(playlistItems.size, key = { playlistItems[it].id }) { index ->                 val item = playlistItems[index]                 val row = rowByVideoId[item.videoItem.videoID]@@ -142,7 +128,7 @@ fun TvPlaylistDetailPage(                         item = row,                         selected = isSelected,                         inSelectionMode = isSelectionMode,-                        onOpen = { backStack.add(TvRoute.Video(item.videoItem.videoID)) },+                        onOpen = { backStack.playVideo(item.videoItem.videoID) },                         onToggleSelect = {                             if (isSelected) selectedIds.remove(item.id)                             else selectedIds.add(item.id)@@ -172,7 +158,6 @@ fun TvPlaylistDetailPage(                     onClick = { confirmDelete = false },                 )             },-            content = {},         )     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRecommendationsSettings.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRecommendationsSettings.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRecommendationsSettings.ktindex c8bc5ab809..044359b8ef 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRecommendationsSettings.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRecommendationsSettings.kt@@ -73,12 +73,13 @@ fun TvRecommendationsSettingsPage(     val firstFocus = remember { FocusRequester() }      TvInitialFocus(firstFocus)-    Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {-        TvScreenHeader(title = stringResource(R.string.label_recommendations))-        Column(-            Modifier.padding(start = 48.dp, end = 48.dp, bottom = 44.dp),-            verticalArrangement = Arrangement.spacedBy(8.dp),-        ) {+    TvSettingsBody {+        Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {+            TvScreenHeader(title = stringResource(R.string.label_recommendations))+            Column(+                Modifier.padding(start = 48.dp, end = 48.dp, bottom = 44.dp),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {             RecommendationPreset.entries.forEachIndexed { index, preset ->                 TvListRow(                     headline = presetLabel(preset),@@ -165,6 +166,7 @@ fun TvRecommendationsSettingsPage(                 text = stringResource(R.string.action_reset_algorithm),                 onClick = { ypvm.resetAlgorithm() },             )+            }         }     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRoute.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRoute.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRoute.ktindex 38efb1d800..4d5dc15ce8 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRoute.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvRoute.kt@@ -22,12 +22,13 @@ sealed interface TvRoute : NavKey {     @Serializable     data object Search : TvRoute +    /** Details for one video: description, chapters, related, comments. Opened from the player. */     @Serializable     data class Video(val videoID: Long) : TvRoute -    /** Fullscreen playback for one video. Pushed from detail/hero Play; BACK returns. */+    /** Fullscreen playback for one video - what selecting any video opens. BACK returns. */     @Serializable-    data class VideoPlayerRoute(val videoID: Long, val resume: Boolean = false) : TvRoute+    data class VideoPlayerRoute(val videoID: Long) : TvRoute      @Serializable     data class Channel(val channelID: String) : TvRoute
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSaved.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSaved.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSaved.ktindex f1d7d29831..1ab5a8511e 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSaved.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSaved.kt@@ -1,29 +1,22 @@ package com.vayunmathur.youpipe.tv -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.items-import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid+import com.vayunmathur.library.tv.TvInfoCard import com.vayunmathur.library.tv.TvInitialFocus-import com.vayunmathur.library.tv.TvRowCard import com.vayunmathur.library.tv.TvScreenHeader-import com.vayunmathur.library.tv.TvShelf-import com.vayunmathur.library.tv.tvContentPadding+import com.vayunmathur.library.tv.tvFullWidth+import com.vayunmathur.library.tv.tvGridHeader import com.vayunmathur.library.ui.IconAdd import com.vayunmathur.library.ui.IconDownload import com.vayunmathur.library.ui.IconList@@ -33,9 +26,9 @@ import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV saved library: Watch later + Downloads as row cards, then user playlists as a grid of- * [TvRowCard]s with counts. Creating a playlist is the header action; deleting/renaming- * happens on the playlist detail screen.+ * TV saved library: Downloads + Watch later as full-information cards, then user+ * playlists as a 3-column grid of [TvInfoCard]s with counts. Creating a playlist is the+ * header action; deleting/renaming happens on the playlist detail screen.  *  * The phone reorders playlists with a drag handle; a D-pad has no drag, and stacked  * per-row move buttons break the one-focus-axis rule — so reorder stays phone-only.@@ -52,6 +45,7 @@ fun TvSavedPage(     val watchLater = playlists.firstOrNull { it.mandatory }     val userPlaylists = playlists.filter { !it.mandatory }     val firstFocus = remember { FocusRequester() }+    val savedTitle = stringResource(UiR.string.saved)      TvInitialFocus(firstFocus)     Column(Modifier.fillMaxSize()) {@@ -62,54 +56,47 @@ fun TvSavedPage(                     text = stringResource(R.string.new_playlist),                     onClick = { backStack.add(TvRoute.CreatePlaylist) },                     icon = { IconAdd() },-                    modifier = Modifier.focusRequester(firstFocus),                 )             },         )-        TvShelf(title = null) {-            item(key = "pinned-downloads") {-                TvRowCard(-                    title = stringResource(R.string.title_downloads),-                    subtitle = stringResource(R.string.playlist_video_count, downloadedVideos.size),-                    leading = { IconDownload() },-                    onClick = { backStack.add(TvRoute.Downloads) },-                )+        TvGrid(columns = 3, modifier = Modifier.fillMaxSize().weight(1f)) {+            tvFullWidth(key = "pinned") {+                Column {+                    TvInfoCard(+                        title = stringResource(R.string.title_downloads),+                        onClick = { backStack.add(TvRoute.Downloads) },+                        subtitle = stringResource(R.string.playlist_video_count, downloadedVideos.size),+                        leading = { IconDownload() },+                    )+                    if (watchLater != null) {+                        TvInfoCard(+                            title = stringResource(R.string.playlist_watch_later),+                            onClick = { backStack.add(TvRoute.PlaylistDetail(watchLater.id)) },+                            subtitle = stringResource(+                                R.string.playlist_video_count,+                                counts[watchLater.id] ?: 0,+                            ),+                            leading = { IconList() },+                        )+                    }+                }             }-            if (watchLater != null) {-                item(key = "pinned-watch-later") {-                    TvRowCard(-                        title = stringResource(R.string.playlist_watch_later),-                        subtitle = stringResource(-                            R.string.playlist_video_count,-                            counts[watchLater.id] ?: 0,-                        ),+            if (userPlaylists.isEmpty()) {+                tvFullWidth(key = "empty") {+                    TvEmptyState(title = stringResource(R.string.playlist_empty))+                }+            } else {+                tvGridHeader(key = "playlists-header", title = savedTitle)+                items(userPlaylists.size, key = { userPlaylists[it].id }) { index ->+                    val playlist = userPlaylists[index]+                    TvInfoCard(+                        title = playlist.name,+                        onClick = { backStack.add(TvRoute.PlaylistDetail(playlist.id)) },+                        subtitle = stringResource(R.string.playlist_video_count, counts[playlist.id] ?: 0),                         leading = { IconList() },-                        onClick = { backStack.add(TvRoute.PlaylistDetail(watchLater.id)) },                     )                 }             }         }-        if (userPlaylists.isEmpty()) {-            TvEmptyState(title = stringResource(R.string.playlist_empty))-            return@Column-        }-        LazyVerticalGrid(-            columns = GridCells.Fixed(2),-            state = rememberLazyGridState(),-            modifier = Modifier.fillMaxSize().padding(top = 8.dp),-            contentPadding = tvContentPadding(),-            verticalArrangement = Arrangement.spacedBy(20.dp),-            horizontalArrangement = Arrangement.spacedBy(20.dp),-        ) {-            items(userPlaylists, key = { it.id }) { playlist ->-                TvRowCard(-                    title = playlist.name,-                    subtitle = stringResource(R.string.playlist_video_count, counts[playlist.id] ?: 0),-                    leading = { IconList() },-                    width = 420.dp,-                    onClick = { backStack.add(TvRoute.PlaylistDetail(playlist.id)) },-                )-            }-        }     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSearch.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSearch.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSearch.ktindex 2c2a790e07..a505c3075d 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSearch.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSearch.kt@@ -2,16 +2,14 @@ package com.vayunmathur.youpipe.tv  import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.ExperimentalLayoutApi+import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.LazyRow-import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.items-import androidx.compose.foundation.lazy.grid.rememberLazyGridState-import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.lazy.grid.GridItemSpan+import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue@@ -19,20 +17,25 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.unit.dp+import com.vayunmathur.library.image.ImageRequest+import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.tv.TvChip+import com.vayunmathur.library.tv.TvDimens import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid+import com.vayunmathur.library.tv.TvInfoCard import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvLoading-import com.vayunmathur.library.tv.TvRowCard-import com.vayunmathur.library.tv.TvScreenHeader import com.vayunmathur.library.tv.TvTextField-import com.vayunmathur.library.tv.tvContentPadding-import com.vayunmathur.library.ui.IconPerson+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.tv.tvGridHeader import com.vayunmathur.library.ui.IconSearch import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack@@ -44,9 +47,9 @@ import com.vayunmathur.youpipe.util.YouPipeViewModel  /**  * TV search: a [TvTextField] (IME only on CENTER) + suggestions/history chips + results- * grid. Videos and channels both resolve: videos open the detail, channels open the- * channel page.+ * grid. Videos open the detail; channels open the channel page.  */+@OptIn(ExperimentalLayoutApi::class) @Composable fun TvSearchPage(     backStack: NavBackStack<TvRoute>,@@ -67,7 +70,7 @@ fun TvSearchPage(         ypvm.setSearchQuery(text)         val watchID = ypvm.resolveWatchUrl()         if (watchID != null) {-            backStack.add(TvRoute.Video(watchID))+            backStack.playVideo(watchID)         } else {             ypvm.performSearch()             submitted = true@@ -76,7 +79,6 @@ fun TvSearchPage(      TvInitialFocus(fieldFocus, submitted)     Column(Modifier.fillMaxSize()) {-        TvScreenHeader(title = stringResource(UiR.string.search))         TvTextField(             value = fieldText,             onValueChange = {@@ -89,65 +91,63 @@ fun TvSearchPage(             onSubmit = { submit(fieldText) },             imeAction = ImeAction.Search,             focusRequester = fieldFocus,-            modifier = Modifier.fillMaxWidth().padding(start = 48.dp, end = 48.dp, bottom = 8.dp),+            modifier = Modifier+                .fillMaxWidth()+                .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal, top = TvDimens.SafeVertical),         )         val videoResults = remember(results) { results.filterIsInstance<VideoInfo>() }         val channelResults = remember(results) { results.filterIsInstance<ChannelInfo>() }         val rows = rememberTvVideoRows(videoResults, ypvm, historyById)+        val channelsTitle = stringResource(R.string.tv_section_channels)+        val videosTitle = stringResource(R.string.tv_section_videos)          when {             results.isNotEmpty() -> {-                if (channelResults.isNotEmpty()) {-                    LazyRow(-                        modifier = Modifier.fillMaxWidth(),-                        contentPadding = PaddingValues(-                            start = 48.dp,-                            end = 48.dp,-                            top = 8.dp,-                            bottom = 8.dp,-                        ),-                        horizontalArrangement = Arrangement.spacedBy(12.dp),-                    ) {-                        items(channelResults, key = { "c-${it.channelID}" }) { channel ->-                            TvRowCard(-                                title = channel.name,-                                subtitle = channelSubtitle(channel),-                                leading = { IconPerson() },-                                width = 340.dp,-                                onClick = { backStack.add(TvRoute.Channel(channel.channelID)) },-                            )-                        }+                TvGrid(columns = TV_GRID_COLUMNS, modifier = Modifier.fillMaxSize()) {+                    if (channelResults.isNotEmpty()) {+                        tvGridHeader(+                            key = "channels-header",+                            title = channelsTitle,+                            first = true,+                        )+                    }+                    items(+                        channelResults.size,+                        key = { "c-${channelResults[it].channelID}" },+                        span = { GridItemSpan(2) },+                    ) { index ->+                        val channel = channelResults[index]+                        TvChannelSearchCard(+                            channel = channel,+                            onClick = { backStack.add(TvRoute.Channel(channel.channelID)) },+                        )+                    }+                    if (videoResults.isNotEmpty()) {+                        tvGridHeader(+                            key = "videos-header",+                            title = videosTitle,+                            first = channelResults.isEmpty(),+                        )                     }-                }-                LazyVerticalGrid(-                    columns = GridCells.Fixed(TV_GRID_COLUMNS),-                    state = rememberLazyGridState(),-                    modifier = Modifier.fillMaxSize(),-                    contentPadding = tvContentPadding(),-                    verticalArrangement = Arrangement.spacedBy(28.dp),-                    horizontalArrangement = Arrangement.spacedBy(20.dp),-                ) {                     items(rows.size, key = { rows[it].row.videoID }) { index ->                         val item = rows[index]                         TvVideoCard(                             item = item,-                            onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },+                            onOpen = { backStack.playVideo(item.row.videoID) },                         )                     }                 }             }             submitted -> TvLoading()             suggestions.isNotEmpty() -> {-                LazyRow(-                    modifier = Modifier.fillMaxWidth(),-                    contentPadding = PaddingValues(-                        start = 48.dp,-                        end = 48.dp,-                        top = 8.dp,-                    ),-                    horizontalArrangement = Arrangement.spacedBy(12.dp),+                FlowRow(+                    modifier = Modifier+                        .fillMaxWidth()+                        .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal, top = 16.dp),+                    horizontalArrangement = Arrangement.spacedBy(8.dp),+                    verticalArrangement = Arrangement.spacedBy(8.dp),                 ) {-                    items(suggestions, key = { it }) { suggestion ->+                    suggestions.forEach { suggestion ->                         TvChip(                             label = suggestion,                             selected = false,@@ -156,14 +156,44 @@ fun TvSearchPage(                     }                 }             }-            else -> TvEmptyState(title = stringResource(UiR.string.search))+            else -> TvEmptyState(title = stringResource(R.string.tv_search_hint), icon = { IconSearch() })         }     } } -/** Subscriber-count subtitle for a channel row. */+/** One channel result: compact card with a circular avatar, name and subscriber count. */+@Composable+private fun TvChannelSearchCard(+    channel: ChannelInfo,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+) {+    val context = LocalContext.current+    TvInfoCard(+        title = channel.name,+        onClick = onClick,+        modifier = modifier,+        subtitle = channelSubtitle(channel),+        leading = {+            if (channel.avatar.isNotEmpty()) {+                AsyncImage(+                    model = ImageRequest.Builder(context)+                        .data(channel.avatar)+                        .memoryCacheKey("channel-avatar-${channel.channelID}")+                        .build(),+                    contentDescription = null,+                    modifier = Modifier.fillMaxSize().clip(CircleShape),+                    contentScale = ContentScale.Crop,+                )+            }+        },+        leadingSize = 56.dp,+    )+}++/** Subscriber-count subtitle for a channel result. */ @Composable private fun channelSubtitle(channel: ChannelInfo): String {-    val context = androidx.compose.ui.platform.LocalContext.current+    val context = LocalContext.current     return stringResource(R.string.subscribers_count, countString(context, channel.subscribers)) }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSettings.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSettings.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSettings.ktindex 38c9fc3476..43c1b1aa22 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSettings.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvSettings.kt@@ -30,7 +30,7 @@ import com.vayunmathur.youpipe.util.YouPipeViewModel.Companion.ALL_SPONSOR_CATEG  * TV settings hub: the four sections as [TvListRow]s with summaries.  *  * Mirrors the phone `SettingsPage` (sponsor summary + recommendation preset summary) with- * no app bars — the rail is the chrome.+ * no app bars — the rail is the chrome. The list is constrained to a readable max width.  */ @Composable fun TvSettingsPage(@@ -45,54 +45,56 @@ fun TvSettingsPage(     val firstFocus = remember { FocusRequester() }      TvInitialFocus(firstFocus)-    LazyColumn(-        state = rememberLazyListState(),-        modifier = Modifier.fillMaxSize(),-        contentPadding = tvContentPadding(top = 0.dp),-        verticalArrangement = Arrangement.spacedBy(8.dp),-    ) {-        item(key = "header") {-            androidx.tv.material3.Text(-                text = stringResource(UiR.string.settings),-                style = androidx.tv.material3.MaterialTheme.typography.headlineLarge,-                color = androidx.tv.material3.MaterialTheme.colorScheme.onSurface,-                modifier = Modifier.padding(top = 28.dp, bottom = 16.dp),-            )-        }-        item(key = "general") {-            TvListRow(-                headline = stringResource(R.string.settings_general_content),-                trailing = { IconChevronRight() },-                onClick = { backStack.add(TvRoute.SettingsGeneral) },-                modifier = Modifier.focusRequester(firstFocus),-            )-        }-        item(key = "sponsorblock") {-            TvListRow(-                headline = stringResource(R.string.settings_sponsorblock),-                supporting = stringResource(-                    R.string.settings_sponsorblock_summary,-                    blockedCount,-                    ALL_SPONSOR_CATEGORIES.size,-                ),-                trailing = { IconChevronRight() },-                onClick = { backStack.add(TvRoute.SettingsSponsorBlock) },-            )-        }-        item(key = "recommendations") {-            TvListRow(-                headline = stringResource(R.string.label_recommendations),-                supporting = presetSummary,-                trailing = { IconChevronRight() },-                onClick = { backStack.add(TvRoute.SettingsRecommendations) },-            )-        }-        item(key = "data") {-            TvListRow(-                headline = stringResource(R.string.settings_data),-                trailing = { IconChevronRight() },-                onClick = { backStack.add(TvRoute.SettingsData) },-            )+    TvSettingsBody {+        LazyColumn(+            state = rememberLazyListState(),+            modifier = Modifier.fillMaxSize(),+            contentPadding = tvContentPadding(top = 0.dp),+            verticalArrangement = Arrangement.spacedBy(8.dp),+        ) {+            item(key = "header") {+                androidx.tv.material3.Text(+                    text = stringResource(UiR.string.settings),+                    style = androidx.tv.material3.MaterialTheme.typography.headlineLarge,+                    color = androidx.tv.material3.MaterialTheme.colorScheme.onSurface,+                    modifier = Modifier.padding(top = 28.dp, bottom = 16.dp),+                )+            }+            item(key = "general") {+                TvListRow(+                    headline = stringResource(R.string.settings_general_content),+                    trailing = { IconChevronRight() },+                    onClick = { backStack.add(TvRoute.SettingsGeneral) },+                    modifier = Modifier.focusRequester(firstFocus),+                )+            }+            item(key = "sponsorblock") {+                TvListRow(+                    headline = stringResource(R.string.settings_sponsorblock),+                    supporting = stringResource(+                        R.string.settings_sponsorblock_summary,+                        blockedCount,+                        ALL_SPONSOR_CATEGORIES.size,+                    ),+                    trailing = { IconChevronRight() },+                    onClick = { backStack.add(TvRoute.SettingsSponsorBlock) },+                )+            }+            item(key = "recommendations") {+                TvListRow(+                    headline = stringResource(R.string.label_recommendations),+                    supporting = presetSummary,+                    trailing = { IconChevronRight() },+                    onClick = { backStack.add(TvRoute.SettingsRecommendations) },+                )+            }+            item(key = "data") {+                TvListRow(+                    headline = stringResource(R.string.settings_data),+                    trailing = { IconChevronRight() },+                    onClick = { backStack.add(TvRoute.SettingsData) },+                )+            }         }     } }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvShared.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvShared.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvShared.ktindex ca55e179d0..3cbd360d1b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvShared.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvShared.kt@@ -1,34 +1,42 @@ package com.vayunmathur.youpipe.tv  import android.text.format.DateUtils+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.lazy.grid.GridCells+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.grid.LazyGridScope-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext-import androidx.compose.ui.unit.Dp+import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.library.image.ImageRequest import com.vayunmathur.library.image.compose.AsyncImage-import com.vayunmathur.library.tv.TvIcon+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog+import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvListRow import com.vayunmathur.library.tv.TvMediaCard-import com.vayunmathur.library.tv.tvContentPadding-import com.vayunmathur.library.ui.IconClock import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.ui.VideoInfo import com.vayunmathur.youpipe.ui.videoRowState import com.vayunmathur.youpipe.util.VideoRowState import com.vayunmathur.youpipe.util.YouPipeViewModel+import com.vayunmathur.youpipe.util.blockChannel+import com.vayunmathur.youpipe.util.boostChannel+import com.vayunmathur.youpipe.util.pinChannel+import com.vayunmathur.youpipe.util.removeInterest  /**  * Shared TV presentation helpers for YouPipe: the one video-card mapping and the 4-column@@ -81,16 +89,29 @@ internal fun rememberTvVideoRows( internal fun tvDurationBadge(durationSec: Long): String? =     if (durationSec > 0) DateUtils.formatElapsedTime(durationSec) else null +/** One-line subtitle under a video card: "channel · views · age" plus the Why reason. */+internal fun tvVideoSubtitle(

Diff truncated.