Modern Apps git

← Modern-Apps.git

youpipe: redesign TV UI on library:tv

Commit
d5f9f7a87a5009f5d3125da0ef37391e4a130a34
Author
vayun-mathur <[email protected]>
When
2026-10-25 21:35 UTC (1 month ago)
Parents
02508a9

Diff

youpipe/build.gradle.kts
diff --git a/youpipe/build.gradle.kts b/youpipe/build.gradle.ktsindex 41b9d3dc41..68c23f422e 100644--- a/youpipe/build.gradle.kts+++ b/youpipe/build.gradle.kts@@ -37,6 +37,7 @@ android { }  dependencies {+    implementation(project(":library:tv"))     implementation(project(":library:image"))     implementation(project(":youpipe:extractor"))     // Puts the video on a TV through the installed Cast app: a Surface and a PCM pipe, no sockets.
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 35e0214ff3..c36c0149b8 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvAddToPlaylist.kt@@ -5,41 +5,41 @@ 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.layout.Row-import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle-import androidx.tv.material3.Button-import androidx.tv.material3.Checkbox-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Surface-import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvListRow+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.TvTextField+import com.vayunmathur.library.tv.tvContentPadding+import com.vayunmathur.library.ui.IconCheck+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  /**- * TV add-to-playlist: staged membership checkboxes as a focusable list.+ * TV add-to-playlist: staged membership as a focusable list with a confirm dialog.  *- * The phone stages membership in an `AddToListDialog` and applies on OK. Same staging here —- * each playlist row is a focusable `Surface` with a checkbox (CENTER toggles membership), and- * the OK/Cancel rows at the bottom apply or drop the stage. BACK dismisses without applying,- * via the overlay-dismiss-first rule. The "new playlist" field only opens its text entry on- * explicit focus + IME action, never autofocused.+ * The phone stages membership in an `AddToListDialog` and applies on OK. Same staging+ * here — each playlist row toggles membership on CENTER — and OK/Cancel live in the+ * header. The new-playlist field is a [TvTextField] (IME only on CENTER). BACK pops+ * without applying.  */ @Composable fun TvAddToPlaylistPage(@@ -59,17 +59,15 @@ fun TvAddToPlaylistPage(         // Same fallback as the phone dialog: the video state went away (rotation, process         // death) so there is nothing to add — back out instead of staging against nothing.         TvInitialFocus(closeFocus)-        Column(-            Modifier-                .fillMaxSize()-                .padding(48.dp),-            verticalArrangement = Arrangement.spacedBy(16.dp),-        ) {-            Text(text = stringResource(R.string.add_to_playlist), style = MaterialTheme.typography.headlineSmall)-            Button(onClick = { backStack.pop() }, modifier = Modifier.focusRequester(closeFocus)) {-                Text(stringResource(R.string.action_close))-            }-        }+        TvScreenHeader(+            title = stringResource(R.string.add_to_playlist),+            actions = {+                TvButton(+                    text = stringResource(R.string.action_close),+                    onClick = { backStack.pop() },+                )+            },+        )         return     } @@ -81,7 +79,6 @@ fun TvAddToPlaylistPage(     }     var staged by remember(membership) { mutableStateOf(membership) }     var newName by remember { mutableStateOf("") }-    var nameOpen by remember { mutableStateOf(false) }     val watchLaterLabel = stringResource(R.string.playlist_watch_later)      fun confirm() {@@ -101,83 +98,75 @@ fun TvAddToPlaylistPage(     }      TvInitialFocus(closeFocus)-    Column(-        Modifier-            .fillMaxSize()-            .padding(horizontal = 48.dp, vertical = 32.dp),-    ) {-        Text(text = stringResource(R.string.add_to_playlist), style = MaterialTheme.typography.headlineSmall)+    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(-            modifier = Modifier.weight(1f).padding(top = 16.dp),+            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-                Surface(+                TvListRow(+                    headline = if (playlist.mandatory) watchLaterLabel else playlist.name,+                    trailing = if (checked) {+                        { IconCheck() }+                    } else {+                        null+                    },+                    selected = checked,                     onClick = {                         staged = if (checked) staged - playlist.id else staged + playlist.id                     },-                    modifier = Modifier.fillMaxWidth(),-                ) {-                    Row(-                        Modifier.padding(16.dp),-                        verticalAlignment = Alignment.CenterVertically,-                    ) {-                        Checkbox(checked = checked, onCheckedChange = null)-                        Text(-                            text = if (playlist.mandatory) watchLaterLabel else playlist.name,-                            style = MaterialTheme.typography.titleMedium,-                            modifier = Modifier.padding(start = 12.dp),-                        )-                    }-                }+                )             }             item(key = "new-playlist") {-                Surface(-                    onClick = { nameOpen = true },-                    modifier = Modifier.fillMaxWidth(),-                ) {-                    Column(Modifier.padding(16.dp)) {-                        Text(text = stringResource(R.string.new_playlist), style = MaterialTheme.typography.titleMedium)-                        if (nameOpen) {-                            androidx.compose.foundation.text.BasicTextField(-                                value = newName,-                                onValueChange = { newName = it },-                                modifier = Modifier-                                    .fillMaxWidth()-                                    .padding(top = 8.dp),-                                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),-                                textStyle = MaterialTheme.typography.titleMedium.copy(-                                    color = MaterialTheme.colorScheme.onSurface,-                                ),-                            )-                            val canCreate = newName.isNotBlank() &&-                                allPlaylists.none { it.name == newName.trim() }-                            Button(-                                onClick = {-                                    ypvm.playlistOps.createPlaylistAndAddVideo(newName.trim(), video)-                                    backStack.pop()-                                },-                                enabled = canCreate,-                                modifier = Modifier.padding(top = 8.dp),-                            ) {-                                Text(stringResource(R.string.new_playlist))+                var nameOpen by remember { mutableStateOf(false) }+                if (!nameOpen) {+                    TvListRow(+                        headline = stringResource(R.string.new_playlist),+                        onClick = { nameOpen = true },+                    )+                } else {+                    val canCreate = newName.isNotBlank() &&+                        allPlaylists.none { it.name == newName.trim() }+                    TvTextField(+                        value = newName,+                        onValueChange = { newName = it },+                        placeholder = stringResource(R.string.label_playlist_name),+                        onSubmit = {+                            if (canCreate) {+                                ypvm.playlistOps.createPlaylistAndAddVideo(newName.trim(), video)+                                backStack.pop()                             }-                        }-                    }+                        },+                        modifier = Modifier.fillMaxWidth(),+                    )+                    TvButton(+                        text = stringResource(R.string.new_playlist),+                        onClick = {+                            ypvm.playlistOps.createPlaylistAndAddVideo(newName.trim(), video)+                            backStack.pop()+                        },+                        enabled = canCreate,+                        modifier = Modifier.padding(top = 8.dp),+                    )                 }             }         }-        Row(-            horizontalArrangement = Arrangement.spacedBy(12.dp),-            modifier = Modifier.padding(top = 16.dp),-        ) {-            Button(onClick = ::confirm) {-                Text(stringResource(android.R.string.ok))-            }-            Button(onClick = { backStack.pop() }, modifier = Modifier.focusRequester(closeFocus)) {-                Text(stringResource(android.R.string.cancel))-            }-        }     } }
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 a2c88040f4..34ac6ba91e 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvChannel.kt@@ -1,40 +1,42 @@ package com.vayunmathur.youpipe.tv -import androidx.compose.foundation.layout.Arrangement 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.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.rememberLazyGridState-import androidx.compose.runtime.collectAsState import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue import androidx.compose.runtime.remember-import androidx.compose.ui.focus.focusRequester-import androidx.compose.ui.focus.FocusRequester+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.res.stringResource import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Text-import com.vayunmathur.library.image.compose.AsyncImage 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.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.data.Subscription import com.vayunmathur.youpipe.R-import com.vayunmathur.youpipe.ui.VideoItem-import com.vayunmathur.youpipe.ui.videoRowState-import com.vayunmathur.youpipe.util.decodeHtml+import com.vayunmathur.youpipe.data.Subscription+import com.vayunmathur.youpipe.ui.countString import com.vayunmathur.youpipe.util.YouPipeViewModel+import com.vayunmathur.youpipe.util.decodeHtml  /**- * TV channel page: identity header + subscribe toggle + focusable video grid.+ * TV channel page: avatar header + subscribe button + video grid.  *  * Mirrors the phone `ChannelPage` binding (`loadChannel`, subscriptions for membership).  * The header and subscribe button are stacked focus targets — not a scrolling collapse —@@ -51,105 +53,85 @@ fun TvChannelPage(     val channelInfo = channelState.info     val subscriptions by ypvm.subscriptions.collectAsState()     val history by ypvm.historyVideos.collectAsState()-    val deArrowEnabled by ypvm.deArrowEnabled.collectAsState()-    val deArrowCache by ypvm.deArrowCache.collectAsState()-    val progressById = remember(history) { history.associate { it.id to it.progress } }+    val historyById = remember(history) { history.associate { it.id to it.progress } }     val context = LocalContext.current-    val headerFocus = remember { FocusRequester() }+    val subscribeFocus = remember { FocusRequester() }      LaunchedEffect(channelID) {         ypvm.loadChannel(channelID)     } -    val rows = remember(videos, deArrowEnabled, deArrowCache, progressById) {-        videos.map { video ->-            val deArrow = if (deArrowEnabled) deArrowCache[video.videoID] else null-            val watched = progressById[video.videoID] ?: 0L-            videoRowState(-                context = context,-                videoInfo = video,-                showAuthor = false,-                percentWatched = if (video.duration > 0) {-                    (watched.toDouble() / video.duration).toFloat()-                } else {-                    0f-                },-                deArrowTitle = deArrow?.title,-                deArrowThumbnailURL = deArrow?.thumbnailUrl,-            )-        }-    }+    val rows = rememberTvVideoRows(videos, ypvm, historyById, showAuthor = false) -    TvInitialFocus(headerFocus)-    Column(-        Modifier-            .fillMaxSize()-            .padding(horizontal = 48.dp, vertical = 32.dp),-    ) {+    TvInitialFocus(subscribeFocus, channelID)+    Column(Modifier.fillMaxSize()) {         channelInfo?.let { info ->-            androidx.compose.foundation.layout.Row(-                verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,-            ) {-                if (info.avatar.isNotEmpty()) {+            TvScreenHeader(+                title = info.name.decodeHtml(),+                subtitle = stringResource(+                    R.string.subscribers_count,+                    countString(context, info.subscribers),+                ),+                actions = {+                    val existing = subscriptions.firstOrNull { it.channelID == info.channelID }+                    TvButton(+                        text = stringResource(+                            if (existing == null) R.string.action_subscribe+                            else R.string.action_unsubscribe,+                        ),+                        onClick = {+                            if (existing == null) {+                                ypvm.upsertSubscription(+                                    Subscription(+                                        name = info.name,+                                        channelID = info.channelID,+                                        avatarURL = info.avatar,+                                    ),+                                )+                            } else {+                                ypvm.deleteSubscription(existing)+                            }+                        },+                        primary = existing == null,+                        modifier = Modifier.focusRequester(subscribeFocus),+                    )+                },+            )+            if (info.avatar.isNotEmpty()) {+                Row(+                    Modifier.padding(start = 48.dp, bottom = 8.dp),+                    verticalAlignment = Alignment.CenterVertically,+                ) {                     AsyncImage(                         model = ImageRequest.Builder(context)                             .data(info.avatar)                             .memoryCacheKey("channel-avatar-${info.channelID}")                             .build(),                         contentDescription = null,-                        modifier = Modifier.padding(end = 16.dp),+                        modifier = Modifier.tvCircularAvatar(),+                        contentScale = ContentScale.Crop,                     )                 }-                Column(Modifier.weight(1f)) {-                    Text(text = info.name.decodeHtml(), style = MaterialTheme.typography.headlineSmall)-                    Text(-                        text = stringResource(-                            R.string.subscribers_count,-                            com.vayunmathur.youpipe.ui.countString(context, info.subscribers),-                        ),-                        style = MaterialTheme.typography.bodyMedium,-                        color = MaterialTheme.colorScheme.onSurfaceVariant,-                    )-                }-            }-            val existing = subscriptions.firstOrNull { it.channelID == info.channelID }-            Button(-                onClick = {-                    if (existing == null) {-                        ypvm.upsertSubscription(-                            Subscription(name = info.name, channelID = info.channelID, avatarURL = info.avatar),-                        )-                    } else {-                        ypvm.deleteSubscription(existing)-                    }-                },-                modifier = Modifier-                    .fillMaxWidth()-                    .padding(vertical = 12.dp)-                    .focusRequester(headerFocus),-            ) {-                Text(-                    if (existing == null) {-                        stringResource(R.string.action_subscribe)-                    } else {-                        stringResource(R.string.action_unsubscribe)-                    },-                )             }         }-        val gridState = rememberLazyGridState()-        LazyVerticalGrid(-            columns = GridCells.Fixed(3),-            state = gridState,-            modifier = Modifier.fillMaxSize(),-            verticalArrangement = Arrangement.spacedBy(16.dp),-            horizontalArrangement = Arrangement.spacedBy(16.dp),-        ) {-            items(rows, key = { it.videoID }) { row ->-                TvVideoCard(-                    row = row,-                    onOpen = { backStack.add(TvRoute.Video(row.videoID)) },-                )+        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),+            ) {+                items(rows.size, key = { rows[it].row.videoID }) { index ->+                    val item = rows[index]+                    TvVideoCard(+                        item = item,+                        onOpen = { backStack.add(TvRoute.Video(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 daee3b1cd3..9499ff2a24 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreateCategory.kt@@ -2,45 +2,47 @@ package com.vayunmathur.youpipe.tv  import androidx.compose.foundation.layout.Arrangement 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.Row-import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.text.KeyboardOptions-import androidx.compose.runtime.collectAsState+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue-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.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button-import androidx.tv.material3.Checkbox-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Surface-import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvListRow+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.TvTextField+import com.vayunmathur.library.tv.tvContentPadding+import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R-import com.vayunmathur.youpipe.util.decodeHtml import com.vayunmathur.youpipe.util.YouPipeViewModel+import com.vayunmathur.youpipe.util.decodeHtml import kotlinx.coroutines.launch  /**  * TV create/update subscription group: name field + focusable member checklist.  *- * Same validation as the phone dialog (non-blank name, non-empty selection, no duplicate on- * create). Each subscription row is a focusable `Surface` with a checkbox; the confirm row- * applies `replaceCategory` and pops. BACK dismisses without applying.+ * Same validation as the phone dialog (non-blank name, non-empty selection, no duplicate+ * on create). Each subscription row toggles membership on CENTER; the confirm row applies+ * `replaceCategory` and pops. BACK dismisses without applying. Deleting an existing+ * category is a header action behind a [TvDialog] confirm.  */ @Composable fun TvCreateCategoryPage(@@ -59,47 +61,66 @@ fun TvCreateCategoryPage(         mutableStateOf(subscriptionsAlreadyInCategory)     }     val scope = rememberCoroutineScope()-    val confirmFocus = remember { FocusRequester() }+    val nameFocus = remember { FocusRequester() }      val canConfirm = categoryName.isNotBlank() && selectedSubscriptions.isNotEmpty() &&         (id != null || categoryName !in categoryNames) -    TvInitialFocus(confirmFocus)-    Column(-        Modifier-            .fillMaxSize()-            .padding(horizontal = 48.dp, vertical = 32.dp),-    ) {-        Text(-            text = if (id == null) {+    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)             },-            style = MaterialTheme.typography.headlineSmall,+            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,+                )+            },         )-        androidx.compose.foundation.text.BasicTextField(+        TvTextField(             value = categoryName,             onValueChange = { categoryName = it },-            modifier = Modifier-                .fillMaxWidth()-                .padding(vertical = 16.dp),-            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),-            textStyle = MaterialTheme.typography.titleMedium.copy(-                color = MaterialTheme.colorScheme.onSurface,-            ),-        )-        Text(-            text = stringResource(R.string.label_select_subscriptions),-            style = MaterialTheme.typography.titleMedium,+            placeholder = stringResource(R.string.label_category_name),+            focusRequester = nameFocus,+            modifier = Modifier.fillMaxWidth().padding(start = 48.dp, end = 48.dp, bottom = 8.dp),         )         LazyColumn(-            modifier = Modifier.weight(1f).padding(top = 8.dp),+            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-                Surface(+                TvListRow(+                    headline = subscription.name.decodeHtml(),+                    trailing = if (checked) {+                        { IconCheck() }+                    } else {+                        null+                    },+                    selected = checked,                     onClick = {                         selectedSubscriptions = if (checked) {                             selectedSubscriptions - subscription@@ -107,47 +128,8 @@ fun TvCreateCategoryPage(                             selectedSubscriptions + subscription                         }                     },-                    modifier = Modifier.fillMaxWidth(),-                ) {-                    Row(-                        Modifier.padding(16.dp),-                        verticalAlignment = Alignment.CenterVertically,-                    ) {-                        Checkbox(checked = checked, onCheckedChange = null)-                        Text(-                            text = subscription.name.decodeHtml(),-                            style = MaterialTheme.typography.titleMedium,-                            modifier = Modifier.padding(start = 12.dp),-                        )-                    }-                }-            }-        }-        Row(-            horizontalArrangement = Arrangement.spacedBy(12.dp),-            modifier = Modifier.padding(top = 16.dp),-        ) {-            Button(-                onClick = {-                    scope.launch {-                        ypvm.replaceCategory(id, categoryName, selectedSubscriptions.map { it.id })-                        backStack.pop()-                    }-                },-                enabled = canConfirm,-                modifier = Modifier.focusRequester(confirmFocus),-            ) {-                Text(-                    if (id == null) {-                        stringResource(UiR.string.create)-                    } else {-                        stringResource(R.string.action_update)-                    },                 )             }-            Button(onClick = { backStack.pop() }) {-                Text(stringResource(android.R.string.cancel))-            }         }     } }
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 62e85fa122..755dd5d502 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvCreatePlaylist.kt@@ -5,30 +5,28 @@ 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.layout.Row-import androidx.compose.foundation.text.BasicTextField-import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle-import androidx.tv.material3.Button-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.TvTextField+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV create-playlist: name field (explicit IME only) + focused create row.+ * TV create-playlist: a [TvTextField] (IME only on CENTER) + focused create row.  *  * Mirrors the phone `CreatePlaylist` validation: non-blank and no duplicate name.  */@@ -44,35 +42,41 @@ fun TvCreatePlaylistPage(     val canCreate = name.isNotBlank() && allPlaylists.none { it.name == name.trim() }      TvInitialFocus(createFocus)-    Column(-        Modifier-            .fillMaxSize()-            .padding(horizontal = 48.dp, vertical = 32.dp),-        verticalArrangement = Arrangement.spacedBy(16.dp),-    ) {-        Text(text = stringResource(R.string.title_create_playlist), style = MaterialTheme.typography.headlineSmall)-        BasicTextField(-            value = name,-            onValueChange = { name = it },-            modifier = Modifier.fillMaxWidth(),-            keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),-            textStyle = MaterialTheme.typography.titleMedium.copy(-                color = MaterialTheme.colorScheme.onSurface,-            ),-        )-        Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {-            Button(-                onClick = {-                    ypvm.playlistOps.createPlaylist(name.trim())-                    backStack.pop()+    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 },+                placeholder = stringResource(R.string.label_playlist_name),+                onSubmit = {+                    if (canCreate) {+                        ypvm.playlistOps.createPlaylist(name.trim())+                        backStack.pop()+                    }                 },-                enabled = canCreate,-                modifier = Modifier.focusRequester(createFocus),+                focusRequester = createFocus,+                modifier = Modifier.fillMaxWidth(),+            )+            androidx.compose.foundation.layout.Row(+                horizontalArrangement = Arrangement.spacedBy(12.dp),             ) {-                Text(stringResource(R.string.new_playlist))-            }-            Button(onClick = { backStack.pop() }) {-                Text(stringResource(android.R.string.cancel))+                TvButton(+                    text = stringResource(R.string.new_playlist),+                    onClick = {+                        ypvm.playlistOps.createPlaylist(name.trim())+                        backStack.pop()+                    },+                    enabled = canCreate,+                    primary = true,+                )+                TvButton(+                    text = stringResource(UiR.string.cancel),+                    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 e1bf9ebef2..6c1141ed85 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDataSettings.kt@@ -2,198 +2,127 @@ package com.vayunmathur.youpipe.tv  import androidx.compose.foundation.layout.Arrangement 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.layout.Row import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll-import androidx.compose.runtime.collectAsState import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf 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.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button import androidx.tv.material3.MaterialTheme import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog+import com.vayunmathur.library.tv.TvListRow+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R+import com.vayunmathur.youpipe.util.YouPipeViewModel import com.vayunmathur.youpipe.util.exportSubscriptions import com.vayunmathur.youpipe.util.importNewPipe import com.vayunmathur.youpipe.util.importYouTubeTakeout import com.vayunmathur.youpipe.util.restoreSubscriptions-import com.vayunmathur.youpipe.util.YouPipeViewModel  /**-- * TV data settings: clear-history (with confirm step) + import/export rows.-+ * TV data settings: clear-history (with confirm dialog) + import/export rows.  *-  * The phone launches SAF pickers via activity-result; on TV the same launchers fire — the-  * system file picker is itself D-pad traversable on Google TV. Import progress shows inline.-  */- @Composable- fun TvDataSettingsPage(-     backStack: NavBackStack<TvRoute>,-     ypvm: YouPipeViewModel,- ) {-     val isLoading by ypvm.isImporting.collectAsState()-     val progress by ypvm.importProgress.collectAsState()-     var confirmClear by remember { mutableStateOf(false) }-     val firstFocus = remember { FocusRequester() } --     val youtubeLauncher = androidx.activity.compose.rememberLauncherForActivityResult(-         androidx.activity.result.contract.ActivityResultContracts.GetContent(),-     ) { uri -> if (uri != null) ypvm.importYouTubeTakeout(uri) }-     val exportLauncher = androidx.activity.compose.rememberLauncherForActivityResult(-         androidx.activity.result.contract.ActivityResultContracts.CreateDocument("application/json"),-     ) { uri -> if (uri != null) ypvm.exportSubscriptions(uri) }-     val restoreLauncher = androidx.activity.compose.rememberLauncherForActivityResult(-         androidx.activity.result.contract.ActivityResultContracts.GetContent(),-     ) { uri -> if (uri != null) ypvm.restoreSubscriptions(uri) }-     val newPipeLauncher = androidx.activity.compose.rememberLauncherForActivityResult(-         androidx.activity.result.contract.ActivityResultContracts.GetContent(),-     ) { uri -> if (uri != null) ypvm.importNewPipe(uri) } ---    TvInitialFocus(firstFocus)--    Column(--        Modifier--            .fillMaxSize()--            .padding(horizontal = 48.dp, vertical = 32.dp)--            .verticalScroll(rememberScrollState()),--        verticalArrangement = Arrangement.spacedBy(8.dp),--    ) {--        Text(text = stringResource(R.string.settings_data), style = MaterialTheme.typography.headlineSmall)--        if (isLoading) {--            com.vayunmathur.library.ui.CircularProgressIndicator(progress = { progress })--        }--        Text(text = stringResource(R.string.title_history), style = MaterialTheme.typography.titleMedium)--        if (confirmClear) {-+    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),+        ) {+            if (isLoading) {+                CircularProgressIndicator(progress = { progress })+            }             Text(--                text = stringResource(R.string.are_you_sure_you_want_to_clear_all_watch),--                style = MaterialTheme.typography.bodyMedium,-+                text = stringResource(R.string.title_history),+                style = MaterialTheme.typography.titleMedium,             )--            Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {--                Button(--                    onClick = { ypvm.clearHistory(); confirmClear = false },--                    modifier = Modifier.focusRequester(firstFocus),--                ) {--                    Text(stringResource(UiR.string.clear))--                }--                Button(onClick = { confirmClear = false }) {--                    Text(stringResource(UiR.string.cancel))--                }--            }--        } else {--            TvSettingsRow(--                title = stringResource(R.string.clear_history),-+            TvListRow(+                headline = stringResource(R.string.clear_history),                 onClick = { confirmClear = true },-                 modifier = Modifier.focusRequester(firstFocus),-             )-+            Text(+                text = stringResource(R.string.label_backup_restore),+                style = MaterialTheme.typography.titleMedium,+            )+            TvListRow(+                headline = stringResource(R.string.label_export_youpipe),+                onClick = { exportLauncher.launch("youpipe_subscriptions.json") },+            )+            TvListRow(+                headline = stringResource(R.string.label_restore_youpipe),+                onClick = { restoreLauncher.launch("application/json") },+            )+            TvListRow(+                headline = stringResource(R.string.label_import_newpipe),+                onClick = { newPipeLauncher.launch("application/json") },+            )+            TvListRow(+                headline = stringResource(R.string.label_import_youtube),+                onClick = { youtubeLauncher.launch("application/zip") },+            )         }--        Text(text = stringResource(R.string.label_backup_restore), style = MaterialTheme.typography.titleMedium)--        TvSettingsRow(--            title = stringResource(R.string.label_export_youpipe),--            onClick = { exportLauncher.launch("youpipe_subscriptions.json") },--        )--        TvSettingsRow(--            title = stringResource(R.string.label_restore_youpipe),--            onClick = { restoreLauncher.launch("application/json") },--        )--        TvSettingsRow(--            title = stringResource(R.string.label_import_newpipe),--            onClick = { newPipeLauncher.launch("application/json") },--        )--        TvSettingsRow(--            title = stringResource(R.string.label_import_youtube),--            onClick = { youtubeLauncher.launch("application/zip") },-+    }+    if (confirmClear) {+        TvDialog(+            title = stringResource(R.string.clear_history),+            onDismissRequest = { confirmClear = false },+            body = stringResource(R.string.are_you_sure_you_want_to_clear_all_watch),+            buttons = {+                TvButton(+                    text = stringResource(UiR.string.clear),+                    onClick = {+                        ypvm.clearHistory()+                        confirmClear = false+                    },+                    primary = true,+                )+                TvButton(+                    text = stringResource(UiR.string.cancel),+                    onClick = { confirmClear = false },+                )+            },+            content = {},         )-     }- }
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloadSheet.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloadSheet.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloadSheet.ktindex 3ee1c1d378..81f6ae6af4 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloadSheet.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloadSheet.kt@@ -1,27 +1,23 @@ package com.vayunmathur.youpipe.tv  import android.text.format.Formatter-import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Surface-import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog+import com.vayunmathur.library.tv.TvListRow import com.vayunmathur.library.ui.IconCheck+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.ui.AudioStream import com.vayunmathur.youpipe.ui.VideoStream@@ -30,7 +26,8 @@ import com.vayunmathur.youpipe.ui.getVideoCodecName /**  * D-pad download picker: quality (with size + codec) then audio language, then confirm.  * Replaces the TV one-tap-best with the phone `ui/VideoDetails.kt` DownloadOptionsDialog- * choices — quality+size+codec, language, best-opus default — as focusable rows.+ * choices — quality+size+codec, language, best-opus default — as a [TvDialog] of+ * focusable rows.  */ @Composable fun TvDownloadSheet(@@ -56,69 +53,87 @@ fun TvDownloadSheet(     var selectedLanguage by remember(audioStreams) {         mutableStateOf(selectedAudioStream?.language ?: languageEntries.firstOrNull()?.first.orEmpty())     }-    TvOptionSheet(title = stringResource(R.string.download_options), onDismiss = onDismiss, modifier = modifier) {-        item(key = "resolution-label") {-            Text(-                text = stringResource(R.string.resolution),-                style = MaterialTheme.typography.titleMedium,-                modifier = Modifier.padding(top = 8.dp),+    TvDialog(+        title = stringResource(R.string.download_options),+        onDismissRequest = onDismiss,+        modifier = modifier,+        buttons = {+            TvButton(+                text = stringResource(R.string.download),+                onClick = { onConfirm(selectedVideoStream.url, selectedAudioStream?.url) },+                primary = true,+            )+            TvButton(+                text = stringResource(UiR.string.cancel),+                onClick = onDismiss,+            )+        },+        content = {+            TvDownloadOptionsList(+                videoStreams = videoStreams,+                selectedVideoStream = selectedVideoStream,+                onSelectVideo = { stream -> selectedVideoStream = stream },+                languageEntries = languageEntries,+                selectedLanguage = selectedLanguage,+                onSelectLanguage = { code ->+                    selectedLanguage = code+                    selectedAudioStream = audioStreams+                        .filter { stream -> stream.language == code }+                        .maxByOrNull { stream -> stream.bitrate }+                },+            )+        },+    )+}++/** Quality + language rows of the download dialog. Split for FileLength. */+@Composable+private fun TvDownloadOptionsList(+    videoStreams: List<VideoStream>,+    selectedVideoStream: VideoStream,+    onSelectVideo: (VideoStream) -> Unit,+    languageEntries: List<Pair<String, String>>,+    selectedLanguage: String,+    onSelectLanguage: (String) -> Unit,+) {+    val context = LocalContext.current+    Column(Modifier.fillMaxWidth()) {+        androidx.tv.material3.Text(+            text = stringResource(R.string.resolution),+            style = androidx.tv.material3.MaterialTheme.typography.titleMedium,+            modifier = Modifier.padding(vertical = 4.dp),+        )+        videoStreams.forEach { stream ->+            TvListRow(+                headline = stream.quality,+                supporting = "${getVideoCodecName(stream.codec)} - " ++                    Formatter.formatShortFileSize(context, stream.size),+                trailing = if (stream == selectedVideoStream) {+                    { IconCheck() }+                } else {+                    null+                },+                selected = stream == selectedVideoStream,+                onClick = { onSelectVideo(stream) },             )-        }-        items(videoStreams, key = { it.url }) { stream ->-            Surface(-                onClick = { selectedVideoStream = stream },-                modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),-            ) {-                Row(-                    Modifier.padding(12.dp),-                    horizontalArrangement = Arrangement.SpaceBetween,-                    verticalAlignment = Alignment.CenterVertically,-                ) {-                    Column(Modifier.weight(1f)) {-                        Text(text = stream.quality, style = MaterialTheme.typography.titleMedium)-                        Text(-                            text = "${getVideoCodecName(stream.codec)} - " +-                                Formatter.formatShortFileSize(context, stream.size),-                            style = MaterialTheme.typography.bodyMedium,-                        )-                    }-                    if (stream == selectedVideoStream) IconCheck()-                }-            }         }         if (languageEntries.size > 1) {-            item(key = "language-label") {-                Text(-                    text = stringResource(R.string.language),-                    style = MaterialTheme.typography.titleMedium,-                    modifier = Modifier.padding(top = 8.dp),-                )-            }-            items(languageEntries, key = { it.first }) { (code, display) ->-                Surface(-                    onClick = {-                        selectedLanguage = code-                        selectedAudioStream = audioStreams.filter { it.language == code }.maxByOrNull { it.bitrate }+            androidx.tv.material3.Text(+                text = stringResource(R.string.language),+                style = androidx.tv.material3.MaterialTheme.typography.titleMedium,+                modifier = Modifier.padding(top = 8.dp, bottom = 4.dp),+            )+            languageEntries.forEach { (code, display) ->+                TvListRow(+                    headline = display,+                    trailing = if (code == selectedLanguage) {+                        { IconCheck() }+                    } else {+                        null                     },-                    modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),-                ) {-                    Row(-                        Modifier.padding(12.dp),-                        horizontalArrangement = Arrangement.SpaceBetween,-                        verticalAlignment = Alignment.CenterVertically,-                    ) {-                        Text(text = display, style = MaterialTheme.typography.titleMedium)-                        if (code == selectedLanguage) IconCheck()-                    }-                }-            }-        }-        item(key = "confirm") {-            Button(-                onClick = { onConfirm(selectedVideoStream.url, selectedAudioStream?.url) },-                modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),-            ) {-                Text(stringResource(R.string.download))+                    selected = code == selectedLanguage,+                    onClick = { onSelectLanguage(code) },+                )             }         }     }
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 06c9d8b4c2..d34f50c6a7 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvDownloads.kt@@ -1,51 +1,46 @@ package com.vayunmathur.youpipe.tv  import androidx.activity.compose.BackHandler-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.layout.Row import androidx.compose.foundation.layout.size-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.rememberLazyListState-import androidx.compose.runtime.collectAsState+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 import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.focus.focusRequester-import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button-import androidx.tv.material3.Checkbox-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.image.ImageRequest+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvEmptyState+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.ui.IconClose import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R-import com.vayunmathur.youpipe.ui.videoRowState import com.vayunmathur.youpipe.util.DownloadManager import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV downloads: active downloads with cancel + completed downloads with D-pad multiselect.- *- * Mirrors the phone `DownloadedVideosPage` binding (activeDownloads + downloadedVideosByRecency)- * as one focusable list — no expanded-width grid switch, a TV reports one window size.- * Selection is checkboxes (same pattern as history); BACK clears first.+ * 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.  */ @Composable fun TvDownloadsPage(@@ -55,6 +50,7 @@ fun TvDownloadsPage(     val downloadedVideos by ypvm.downloadedVideos.collectAsState()     val activeDownloads by DownloadManager.activeDownloads.collectAsState()     val downloads by ypvm.downloadedVideosByRecency.collectAsState()+    val historyById = remember(downloadedVideos) { emptyMap<Long, Long>() }     val context = LocalContext.current     val firstFocus = remember { FocusRequester() } @@ -66,29 +62,24 @@ fun TvDownloadsPage(         selectedActiveIds = emptySet()     } +    val rows = rememberTvVideoRows(+        videos = remember(downloads) { downloads.map { it.videoItem } },+        ypvm = ypvm,+        historyProgressMsById = historyById,+    )+     TvInitialFocus(firstFocus)-    val listState = rememberLazyListState()-    LazyColumn(-        state = listState,-        modifier = Modifier-            .fillMaxSize()-            .padding(horizontal = 48.dp, vertical = 32.dp),-        verticalArrangement = Arrangement.spacedBy(8.dp),-    ) {-        item(key = "downloads-title") {-            Text(-                text = if (isSelectionMode) {-                    stringResource(R.string.selected_count, selectedIds.size + selectedActiveIds.size)-                } else {-                    stringResource(R.string.title_downloads)-                },-                style = MaterialTheme.typography.headlineSmall,-            )-        }-        if (isSelectionMode) {-            item(key = "downloads-actions") {-                Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {-                    Button(+    Column(Modifier.fillMaxSize()) {+        TvScreenHeader(+            title = if (isSelectionMode) {+                stringResource(R.string.selected_count, (selectedIds.size + selectedActiveIds.size).toString())+            } else {+                stringResource(R.string.title_downloads)+            },+            actions = {+                if (isSelectionMode) {+                    TvButton(+                        text = stringResource(UiR.string.delete),                         onClick = {                             selectedIds.forEach { id ->                                 downloadedVideos.find { it.id == id }?.let { ypvm.deleteDownloadedVideo(it) }@@ -99,109 +90,93 @@ fun TvDownloadsPage(                             selectedIds = emptySet()                             selectedActiveIds = emptySet()                         },-                    ) {-                        IconDelete()-                    }-                    Button(+                        icon = { IconDelete() },+                    )+                    TvButton(+                        text = stringResource(UiR.string.cancel),                         onClick = {                             selectedIds = emptySet()                             selectedActiveIds = emptySet()                         },-                    ) {-                        IconClose()-                    }+                        icon = { IconClose() },+                    )                 }-            }-        }-        items(activeDownloads.toList(), key = { (videoID, _) -> "active-$videoID" }) { (videoID, status) ->-            val isSelected = videoID in selectedActiveIds-            Surface(-                onClick = {-                    if (isSelectionMode) {-                        selectedActiveIds = if (isSelected) selectedActiveIds - videoID else selectedActiveIds + videoID-                    }-                },-                modifier = Modifier.fillMaxWidth(),-            ) {-                Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {-                    if (isSelectionMode) {-                        Checkbox(-                            checked = isSelected,-                            onCheckedChange = {+            },+        )+        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 ->+                    val (videoID, status) = activeList[index]+                    val isSelected = videoID in selectedActiveIds+                    TvRowCard(+                        title = status.videoInfo.name,+                        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                                 }-                            },-                        )-                    }-                    if (status.videoInfo.thumbnailURL.isNotEmpty()) {-                        AsyncImage(-                            model = ImageRequest.Builder(context)-                                .data(status.videoInfo.thumbnailURL)-                                .memoryCacheKey("dl-thumb-$videoID")-                                .build(),-                            contentDescription = null,-                            modifier = Modifier.padding(end = 12.dp),-                        )-                    }-                    Column(Modifier.weight(1f)) {-                        Text(text = status.videoInfo.name, style = MaterialTheme.typography.titleMedium)-                        Text(-                            text = "${(status.progress * 100).toInt()}%",-                            style = MaterialTheme.typography.bodySmall,-                            color = MaterialTheme.colorScheme.onSurfaceVariant,-                        )-                    }-                    CircularProgressIndicator(-                        progress = { status.progress.toFloat() },-                        modifier = Modifier.size(24.dp),+                            }+                        },+                        onLongClick = {+                            selectedActiveIds = if (isSelected) {+                                selectedActiveIds - videoID+                            } else {+                                selectedActiveIds + videoID+                            }+                        },                     )-                    if (!isSelectionMode) {-                        Button(onClick = { DownloadManager.cancelDownload(context, videoID) }) {-                            IconClose()-                        }-                    }                 }             }         }-        items(downloads, key = { it.id }) { downloadItem ->-            val isSelected = downloadItem.id in selectedIds-            TvVideoCard(-                row = videoRowState(-                    context = context,-                    videoInfo = downloadItem.videoItem,-                    showAuthor = true,-                ),-                onOpen = {-                    if (isSelectionMode) {-                        selectedIds = if (isSelected) selectedIds - downloadItem.id else selectedIds + downloadItem.id+        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 {-                        backStack.add(TvRoute.Video(downloadItem.id))-                    }-                },-                modifier = if (activeDownloads.isEmpty() && downloads.indexOf(downloadItem) == 0) {-                    Modifier.focusRequester(firstFocus)-                } else {-                    Modifier-                },-                trailingContent = {-                    if (isSelectionMode) {-                        Checkbox(-                            checked = isSelected,-                            onCheckedChange = {-                                selectedIds = if (isSelected) {-                                    selectedIds - downloadItem.id-                                } else {-                                    selectedIds + downloadItem.id-                                }-                            },-                            modifier = Modifier.padding(top = 8.dp),-                        )-                    }-                },-            )+                        Modifier+                    },+                )+            }         }     } }
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 ffb80ec7f9..f7653c0cf7 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvGeneralSettings.kt@@ -5,216 +5,126 @@ 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.layout.Row import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll-import androidx.compose.runtime.collectAsState import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue 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.focus.FocusRequester 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.tv.material3.MaterialTheme-import androidx.tv.material3.Surface import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvListRow+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.TvSwitchRow+import com.vayunmathur.library.ui.IconCheck import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.util.YouPipeViewModel  /**-  * TV general settings: open-to default, DeArrow, keep-controls, notification bar, language.-  *-- * Same DataStore bindings as the phone `GeneralSettingsPage`; dropdowns become D-pad option-- * lists (one focusable row per choice) because a TV has no dropdown menu convention.-+ * 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.  */- @Composable- fun TvGeneralSettingsPage(-     backStack: NavBackStack<TvRoute>,-     ypvm: YouPipeViewModel,- ) {-     val deArrowEnabled by ypvm.deArrowEnabled.collectAsState()-     val youtubeLanguage by ypvm.youtubeLanguage.collectAsState()-     val defaultPage by ypvm.defaultPage.collectAsState()-     val keepControlsVisible by ypvm.keepPlayerControlsVisible.collectAsState()-     val notificationStyleProgress by ypvm.notificationStyleProgressBar.collectAsState()-     val firstFocus = remember { FocusRequester() } --     // TV pins the transport overlay visible when the accessibility keep-visible is on —-     // same flag the phone player reads, no TV-specific path.--    androidx.compose.runtime.LaunchedEffect(keepControlsVisible) {-+    LaunchedEffect(keepControlsVisible) {         TvTransportState.pinned = keepControlsVisible-         if (keepControlsVisible) TvTransportState.reveal()-     } --     TvInitialFocus(firstFocus)-     Column(--        Modifier--            .fillMaxSize()--            .padding(horizontal = 48.dp, vertical = 32.dp)--            .verticalScroll(rememberScrollState()),--        verticalArrangement = Arrangement.spacedBy(8.dp),-+        Modifier.fillMaxSize().verticalScroll(rememberScrollState()),     ) {--        Text(text = stringResource(R.string.settings_general_content), style = MaterialTheme.typography.headlineSmall)--        Text(text = stringResource(R.string.label_default_page), style = MaterialTheme.typography.titleMedium)--        com.vayunmathur.youpipe.DEFAULT_PAGE_OPTIONS.forEach { (key, labelRes) ->--            TvOptionRow(--                label = stringResource(labelRes),--                selected = defaultPage == key,--                onSelect = { ypvm.setDefaultPage(key) },-+        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,             )--        }--        TvSwitchRow(--            title = stringResource(R.string.label_dearrow),--            summary = stringResource(R.string.label_dearrow_description),--            checked = deArrowEnabled,--            onCheckedChange = { ypvm.setDeArrowEnabled(it) },--        )--        TvSwitchRow(--            title = stringResource(R.string.label_keep_controls_visible),--            summary = stringResource(R.string.label_keep_controls_visible_description),--            checked = keepControlsVisible,--            onCheckedChange = { ypvm.setKeepPlayerControlsVisible(it) },--        )--        TvSwitchRow(--            title = stringResource(R.string.label_notification_style_progress),--            summary = 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)--        TvOptionRow(--            label = stringResource(R.string.label_system_default),--            selected = youtubeLanguage.isBlank(),--            onSelect = { ypvm.setYouTubeLanguage("") },--        )--        YouPipeViewModel.Companion.YOUTUBE_LANGUAGES.forEach { (code, name) ->--            TvOptionRow(--                label = name,--                selected = youtubeLanguage == code,--                onSelect = { ypvm.setYouTubeLanguage(code) },-+            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) },             )--        }--    }--}----/** One selectable option row with a checked marker. Shared with recommendations (presets). */-@Composable-internal fun TvOptionRow(--    label: String,--    selected: Boolean,--    onSelect: () -> Unit,--    modifier: Modifier = Modifier,--) {--    Surface(onClick = onSelect, modifier = modifier.fillMaxWidth()) {--        Row(--            Modifier.padding(horizontal = 16.dp, vertical = 12.dp),--            verticalAlignment = Alignment.CenterVertically,--        ) {--            androidx.tv.material3.Checkbox(checked = selected, onCheckedChange = null)-             Text(--                text = label,-+                text = stringResource(R.string.label_youtube_language),                 style = MaterialTheme.typography.titleMedium,--                modifier = Modifier.padding(start = 12.dp),-             )-+            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) {+                        { 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 68b20486d7..f9e2d2d307 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHistory.kt@@ -1,47 +1,43 @@ package com.vayunmathur.youpipe.tv  import androidx.activity.compose.BackHandler-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.layout.Row import androidx.compose.foundation.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.items import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.rememberLazyGridState-import androidx.compose.runtime.collectAsState import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-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.Modifier-import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button-import androidx.tv.material3.Checkbox-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog+import com.vayunmathur.library.tv.TvEmptyState+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 import com.vayunmathur.youpipe.R-import com.vayunmathur.youpipe.ui.videoRowState import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV history: focusable grid with D-pad multiselect.+ * TV history: a 4-column grid of [TvVideoCard]s 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 — so selection is a checkbox on each focused card- * (RIGHT onto the box, CENTER toggles), and delete is a focused action row that appears only- * while the selection is non-empty. BACK clears the selection first, matching the phone's- * `BackHandler` and the overlay-dismiss-first rule.+ * 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.  */ @Composable fun TvHistoryPage(@@ -49,112 +45,98 @@ fun TvHistoryPage(     ypvm: YouPipeViewModel, ) {     val history by ypvm.historyVideosByRecency.collectAsState()-    val deArrowEnabled by ypvm.deArrowEnabled.collectAsState()-    val deArrowCache by ypvm.deArrowCache.collectAsState()-    val context = LocalContext.current-    val firstFocus = remember { FocusRequester() }+    val historyById = remember(history) { history.associate { it.id to it.progress } }+    val videos = remember(history) { history.map { it.videoItem } }+    val rows = rememberTvVideoRows(videos, ypvm, historyById)      var selectedIds by remember { mutableStateOf(emptySet<Long>()) }+    var confirmClear by remember { mutableStateOf(false) }     val inSelectionMode = selectedIds.isNotEmpty()     BackHandler(enabled = inSelectionMode) { selectedIds = emptySet() } -    val rows = remember(history, deArrowEnabled, deArrowCache) {-        history.map { item ->-            val video = item.videoItem-            val deArrow = if (deArrowEnabled) deArrowCache[video.videoID] else null-            item.id to videoRowState(-                context = context,-                videoInfo = video,-                showAuthor = true,-                percentWatched = if (video.duration > 0) {-                    (item.progress.toDouble() / video.duration).toFloat()-                } else {-                    0f-                },-                deArrowTitle = deArrow?.title,-                deArrowThumbnailURL = deArrow?.thumbnailUrl,-            )-        }-    }-+    val firstFocus = remember { FocusRequester() }     TvInitialFocus(firstFocus)-    val gridState = rememberLazyGridState()-    Column(-        Modifier-            .fillMaxSize()-            .padding(horizontal = 48.dp, vertical = 32.dp),-    ) {-        Text(text = stringResource(R.string.title_history), style = MaterialTheme.typography.headlineSmall)-        if (inSelectionMode) {-            Row(-                verticalAlignment = Alignment.CenterVertically,-                horizontalArrangement = Arrangement.spacedBy(12.dp),-                modifier = Modifier.padding(vertical = 8.dp),-            ) {-                Text(-                    text = stringResource(R.string.selected_count, selectedIds.size),-                    style = MaterialTheme.typography.titleMedium,-                )-                Button(-                    onClick = {-                        ypvm.deleteHistoryVideos(selectedIds.toList())-                        selectedIds = emptySet()-                    },-                ) {-                    IconDelete()-                }-                Button(onClick = { selectedIds = emptySet() }) {-                    Text(stringResource(R.string.action_close))+    Column(Modifier.fillMaxSize()) {+        TvScreenHeader(+            title = if (inSelectionMode) {+                stringResource(R.string.selected_count, selectedIds.size.toString())+            } else {+                stringResource(R.string.title_history)+            },+            actions = {+                if (inSelectionMode) {+                    TvButton(+                        text = stringResource(UiR.string.delete),+                        onClick = {+                            ypvm.deleteHistoryVideos(selectedIds.toList())+                            selectedIds = emptySet()+                        },+                        icon = { IconDelete() },+                    )+                    TvButton(+                        text = stringResource(UiR.string.cancel),+                        onClick = { selectedIds = emptySet() },+                    )+                } else if (rows.isNotEmpty()) {+                    TvButton(+                        text = stringResource(R.string.clear_history),+                        onClick = { confirmClear = true },+                        icon = { IconDelete() },+                    )                 }-            }+            },+        )+        if (rows.isEmpty()) {+            TvEmptyState(title = stringResource(R.string.empty_recommendations))+            return@Column         }         LazyVerticalGrid(-            columns = GridCells.Fixed(3),-            state = gridState,-            modifier = Modifier.fillMaxSize().padding(top = 8.dp),-            verticalArrangement = Arrangement.spacedBy(16.dp),-            horizontalArrangement = Arrangement.spacedBy(16.dp),+            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),         ) {-            items(rows, key = { it.first }) { (id, row) ->-                val isSelected = id in selectedIds-                Column {-                    TvVideoCard(-                        row = row,-                        onOpen = {-                            if (inSelectionMode) {-                                selectedIds = if (isSelected) selectedIds - id else selectedIds + id-                            } else {-                                backStack.add(TvRoute.Video(row.videoID))-                            }-                        },-                        modifier = if (rows.indexOfFirst { it.first == id } == 0) {-                            Modifier.focusRequester(firstFocus)+            items(rows.size, key = { rows[it].row.videoID }) { index ->+                val item = rows[index]+                val isSelected = item.row.videoID in selectedIds+                TvSelectableCard(+                    item = item,+                    selected = isSelected,+                    inSelectionMode = inSelectionMode,+                    onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },+                    onToggleSelect = {+                        selectedIds = if (isSelected) {+                            selectedIds - item.row.videoID                         } else {-                            Modifier-                        },-                        trailingContent = {-                            // The selection checkbox: a second focus target on the card, so a-                            // focused card offers open (CENTER) and select (RIGHT then CENTER).-                            Row(-                                verticalAlignment = Alignment.CenterVertically,-                                modifier = Modifier.padding(top = 8.dp),-                            ) {-                                Checkbox(-                                    checked = isSelected,-                                    onCheckedChange = {-                                        selectedIds = if (isSelected) selectedIds - id else selectedIds + id-                                    },-                                )-                                Text(-                                    text = stringResource(R.string.selected_count, selectedIds.size),-                                    style = MaterialTheme.typography.bodySmall,-                                    modifier = Modifier.padding(start = 8.dp),-                                )-                            }-                        },-                    )-                }+                            selectedIds + item.row.videoID+                        }+                    },+                    modifier = if (index == 0) Modifier.focusRequester(firstFocus) else Modifier,+                )             }         }     }+    if (confirmClear) {+        TvDialog(+            title = stringResource(R.string.clear_history),+            onDismissRequest = { confirmClear = false },+            body = stringResource(R.string.are_you_sure_you_want_to_clear_all_watch),+            buttons = {+                TvButton(+                    text = stringResource(UiR.string.clear),+                    onClick = {+                        ypvm.clearHistory()+                        confirmClear = false+                    },+                    primary = true,+                )+                TvButton(+                    text = stringResource(UiR.string.cancel),+                    onClick = { confirmClear = false },+                )+            },+        )+    } }
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 29b0cf138d..576581e018 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvHomeFeed.kt@@ -1,48 +1,56 @@ package com.vayunmathur.youpipe.tv -import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Row+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.lazy.grid.GridCells-import androidx.compose.foundation.lazy.grid.items-import androidx.compose.foundation.lazy.grid.LazyVerticalGrid-import androidx.compose.foundation.lazy.grid.rememberLazyGridState-import androidx.compose.runtime.collectAsState+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf 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.Modifier+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 androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Surface-import androidx.tv.material3.Text+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.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.util.NavBackStack import com.vayunmathur.youpipe.R-import com.vayunmathur.youpipe.ui.countString-import com.vayunmathur.youpipe.ui.videoRowState-import com.vayunmathur.youpipe.util.VideoRowState+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-import com.vayunmathur.youpipe.util.SearchResultRow-import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * TV home: the recommendation feed as a focusable grid, with a search entry row on top.+ * TV home: an immersive hero for the focused video above shelves of 16:9 cards.  *- * Binder mirrors the phone `SearchPage`'s mapping (recommendations + history progress +- * DeArrow) into plain rows — but there is no search overlay and no autofocus: search is a- * separate [TvRoute]-less inline panel opened by explicit focus + CENTER, so the TV IME never- * pops uninvited. Overflow actions (not-interested, pin, block) are per-row D-pad options- * reached with RIGHT on the focused card.+ * 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.  */ @Composable fun TvHomeFeedPage(@@ -52,147 +60,246 @@ fun TvHomeFeedPage(     val recommendations by ypvm.recommendations.collectAsState()     val recommendationsLoading by ypvm.recommendationsLoading.collectAsState()     val history by ypvm.historyVideos.collectAsState()-    val deArrowEnabled by ypvm.deArrowEnabled.collectAsState()-    val deArrowCache by ypvm.deArrowCache.collectAsState()-    val progressById = remember(history) { history.associate { it.id to it.progress } }-    val context = LocalContext.current -    LaunchedEffect(Unit) {-        ypvm.loadRecommendations()-    }+    LaunchedEffect(Unit) { ypvm.loadRecommendations() } -    val rows = remember(recommendations, deArrowEnabled, deArrowCache, progressById) {-        recommendations.map { ranked ->-            val video = ranked.video-            val deArrow = if (deArrowEnabled) deArrowCache[video.videoID] else null-            val watched = progressById[video.videoID] ?: 0L-            videoRowState(-                context = context,-                videoInfo = video,-                showAuthor = true,-                reason = ranked.reason,-                percentWatched = if (video.duration > 0) {-                    (watched.toDouble() / video.duration).toFloat()-                } else {-                    0f-                },-                deArrowTitle = deArrow?.title,-                deArrowThumbnailURL = deArrow?.thumbnailUrl,-            )-        }+    val historyById = remember(history) { history.associate { it.id to it.progress } }+    val videos = remember(recommendations) { recommendations.map { it.video } }+    val reasons = remember(recommendations) {+        recommendations.associate { it.video.videoID to it.reason }     }+    val rows = rememberTvVideoRows(videos, ypvm, historyById, reasonsById = reasons) -    val gridState = rememberLazyGridState()-    val searchFocus = remember { FocusRequester() }-    TvListScreen(-        title = stringResource(R.string.label_recommendations),-        emptyMessage = if (!recommendationsLoading) {-            stringResource(R.string.empty_recommendations)-        } else {-            null+    val continueRows = rememberTvVideoRows(+        videos = remember(history) {+            history.sortedByDescending { it.timestamp }.take(TV_CONTINUE_COUNT).map { it.videoItem }         },-        itemCount = rows.size,-    ) {-        LazyVerticalGrid(-            columns = GridCells.Fixed(3),-            state = gridState,-            modifier = Modifier-                .fillMaxSize()-                .padding(top = 16.dp),-            verticalArrangement = Arrangement.spacedBy(16.dp),-            horizontalArrangement = Arrangement.spacedBy(16.dp),-        ) {-            item(key = "tv-search-entry") {-                TvSearchEntryRow(-                    onOpenSearch = { backStack.add(TvRoute.Search) },-                    modifier = Modifier.focusRequester(searchFocus),+        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() }++    if (rows.isEmpty() && !recommendationsLoading) {+        TvEmptyState(+            title = stringResource(R.string.empty_recommendations),+            action = {+                TvButton(+                    text = stringResource(com.vayunmathur.library.ui.R.string.retry),+                    onClick = { ypvm.loadRecommendations() },                 )+            },+        )+        return+    }+    if (rows.isEmpty()) {+        TvLoading()+        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,+                    )+                }+            }+        }+        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() },+                            )+                        },+                    )+                }             }-            items(rows, key = { it.videoID }) { row ->-                TvVideoCard(-                    row = row,-                    onOpen = { backStack.add(TvRoute.Video(row.videoID)) },-                    trailingContent = {-                        TvTrainingActionsRow(-                            row = row,-                            ypvm = ypvm,+            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 },+                    )+                }             }         }     }-    TvInitialFocus(searchFocus)++    optionsFor?.let { item ->+        TvVideoOptionsDialog(+            item = item,+            onDismiss = { optionsFor = null },+            onOpen = { backStack.add(TvRoute.Video(item.row.videoID)) },+            ypvm = ypvm,+        )+    } }  /**- * Per-card training actions: not-interested / more-like / pin / block, same four the phone- * `SearchPage` offers as overflow actions. Rendered as a focusable row inside the card so- * RIGHT from the focused card lands on the first action, keeping one focus axis.+ * 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-private fun TvTrainingActionsRow(-    row: VideoRowState,+internal fun TvVideoOptionsDialog(+    item: TvVideoRow,+    onDismiss: () -> Unit,+    onOpen: () -> Unit,     ypvm: YouPipeViewModel,-    modifier: Modifier = Modifier, ) {-    Row(-        modifier = modifier.padding(top = 8.dp),-        horizontalArrangement = Arrangement.spacedBy(8.dp),-    ) {-        Surface(onClick = { ypvm.removeInterest(channelKey = row.channelKey) }) {-            Text(-                text = stringResource(R.string.action_not_interested),-                style = MaterialTheme.typography.bodyMedium,-                modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),-            )-        }-        Surface(onClick = { ypvm.boostChannel(row.channelKey) }) {-            Text(-                text = stringResource(R.string.action_more_like_this),-                style = MaterialTheme.typography.bodyMedium,-                modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),+    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,             )-        }-        Surface(onClick = { ypvm.pinChannel(row.channelKey) }) {-            Text(-                text = stringResource(R.string.action_pin_channel),-                style = MaterialTheme.typography.bodyMedium,-                modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),-            )-        }-        Surface(onClick = { ypvm.blockChannel(row.channelKey) }) {-            Text(-                text = stringResource(R.string.action_block_channel),-                style = MaterialTheme.typography.bodyMedium,-                modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),-            )-        }-    }+        },+        content = {+            TvOptionsList(item, onDismiss, ypvm)+        },+    ) } -/**- * The search entry row: a focusable card that opens the search panel.- *- * Separate from the feed grid items so the IME only ever opens from an explicit CENTER press —- * never from composition, scroll, or focus passing through.- */+/** The four training rows of the video options dialog. Split for FileLength. */ @Composable-private fun TvSearchEntryRow(-    onOpenSearch: () -> Unit,-    modifier: Modifier = Modifier,+private fun TvOptionsList(+    item: TvVideoRow,+    onDismiss: () -> Unit,+    ypvm: YouPipeViewModel, ) {-    androidx.tv.material3.Surface(onClick = onOpenSearch, modifier = modifier) {-        androidx.compose.foundation.layout.Row(-            Modifier.padding(16.dp),-            verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,-        ) {-            com.vayunmathur.library.ui.IconSearch()-            androidx.tv.material3.Text(-                text = stringResource(com.vayunmathur.library.ui.R.string.search),-                style = androidx.tv.material3.MaterialTheme.typography.titleMedium,-                modifier = Modifier.padding(start = 12.dp),-            )-        }+    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
youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvLanguageSheet.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvLanguageSheet.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvLanguageSheet.ktdeleted file mode 100644index 945ea897ff..0000000000--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvLanguageSheet.kt+++ /dev/null@@ -1,48 +0,0 @@-package com.vayunmathur.youpipe.tv--import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.lazy.items-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.Surface-import androidx.tv.material3.Text-import com.vayunmathur.library.ui.IconCheck-import com.vayunmathur.youpipe.R--/**- * D-pad audio-language list: one focusable row per language, display name with code- * fallback. Replaces the phone dropdown in `ui/VideoPlayerTopControls.kt`.- *- * Entries mirror the phone's `languageEntries` (code to displayName-or-code), and the- * caller's best-opus-per-language rule is untouched — this sheet only picks the code.- */-@Composable-fun TvLanguageSheet(-    entries: List<Pair<String, String>>,-    selected: String,-    onSelect: (String) -> Unit,-    onDismiss: () -> Unit,-    modifier: Modifier = Modifier,-) {-    TvOptionSheet(title = stringResource(R.string.language), onDismiss = onDismiss, modifier = modifier) {-        items(entries, key = { it.first }) { (code, display) ->-            Surface(onClick = { onSelect(code) }, modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {-                Row(-                    Modifier.padding(12.dp),-                    horizontalArrangement = Arrangement.SpaceBetween,-                    verticalAlignment = Alignment.CenterVertically,-                ) {-                    Text(text = display, style = MaterialTheme.typography.titleMedium)-                    if (code == selected) IconCheck()-                }-            }-        }-    }-}
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 ff5adbc1b5..96694bd0e5 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvMainActivity.kt@@ -2,12 +2,23 @@ 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.tv.material3.darkColorScheme+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@@ -17,7 +28,8 @@ import com.vayunmathur.youpipe.util.YouPipeViewModelFactory  * stays exactly as it is — this activity hosts the D-pad browse + player UI.  *  * Landscape-locked and non-edge-to-edge per the manifest; the activity owns the [TvDpadInput]- * key map so scrub/volume/BACK work consistently across browse and player.+ * key map so scrub/volume/BACK work consistently across browse and player. The theme is the+ * shared always-dark [MaTvTheme] in YouPipe red — never a phone dynamic scheme.  */ class TvMainActivity : MaActivity() {     override val edgeToEdge: Boolean = false@@ -59,9 +71,8 @@ class TvMainActivity : MaActivity() {      @Composable     override fun AppTheme(content: @Composable () -> Unit) {-        // Always dark, not dynamic: a TV has no wallpaper to derive a scheme from.-        // Paints nothing itself; screens set their own background.-        MaterialTheme(colorScheme = darkColorScheme(), content = content)+        // Always dark in YouPipe red; screens set their own backgrounds over it.+        MaTvTheme(accent = TvAccent.Red, content = content)     }      @Composable@@ -69,3 +80,18 @@ 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 a8fdfec893..cec3de2ecd 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvManageInterests.kt@@ -5,339 +5,205 @@ 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.layout.Row-import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.runtime.collectAsState+import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember-import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Surface import androidx.tv.material3.Text+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvListRow+import com.vayunmathur.library.tv.tvContentPadding import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.youpipe.R+import com.vayunmathur.youpipe.util.YouPipeViewModel import com.vayunmathur.youpipe.util.clearChannelPreference import com.vayunmathur.youpipe.util.decodeHtml import com.vayunmathur.youpipe.util.pinChannel import com.vayunmathur.youpipe.util.removeInterest import com.vayunmathur.youpipe.util.unmuteKeyword-import com.vayunmathur.youpipe.util.YouPipeViewModel  /**-- * TV interests: channels/topics/blocked/muted as focusable rows with pin/remove actions.-+ * TV interests: channels/topics/blocked/muted as [TvListRow]s with pin/remove trailing+ * actions on a second focus pass.  *-- * Same `interestProfile`/`channelPreferences`/`keywordPreferences` bindings as the phone;-- * trailing buttons become stacked focus targets under each row (D-pad DOWN reaches them).-+ * Same `interestProfile`/`channelPreferences`/`keywordPreferences` bindings as the phone.+ * Each row is one focus target; its actions row sits directly under it so DOWN reaches+ * them with no nesting.  */- @Composable- fun TvManageInterestsPage(-     backStack: NavBackStack<TvRoute>,-     ypvm: YouPipeViewModel,- ) {-     val profile by ypvm.interestProfile.collectAsState()-     val channelPrefs by ypvm.channelPreferences.collectAsState()-     val keywordPrefs by ypvm.keywordPreferences.collectAsState()-     val firstFocus = remember { FocusRequester() } --     val blockedKeys = channelPrefs.filter { it.blocked }.map { it.channelKey }.toSet()-     val pinnedKeys = channelPrefs.filter { it.pinned }.map { it.channelKey }.toSet()-     val topChannels = remember(profile, blockedKeys) {-         profile.authorWeights.entries-             .filter { it.key.isNotBlank() && it.key !in blockedKeys }-             .sortedByDescending { it.value }-             .take(30)-             .map { it.key }-     }-     val topKeywords = remember(profile) {-         profile.keywordWeights.entries-             .sortedByDescending { it.value }-             .take(30)-             .map { it.key }-     }-     val blockedChannels = remember(channelPrefs) {-         channelPrefs.filter { it.blocked }.map { it.channelKey }-     }-     val mutedKeywords = remember(keywordPrefs) {-         keywordPrefs.filter { it.muted }.map { it.keyword }-     } --     TvInitialFocus(firstFocus)-     LazyColumn(--        Modifier--            .fillMaxSize()--            .padding(horizontal = 48.dp, vertical = 32.dp),-+        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), style = MaterialTheme.typography.headlineSmall)-+            Text(+                text = stringResource(R.string.title_manage_interests),+                style = MaterialTheme.typography.headlineLarge,+                color = MaterialTheme.colorScheme.onSurface,+            )+        }+        item(key = "ch-header") {+            TvInterestSectionHeader(stringResource(R.string.label_your_channels))         }--        item(key = "ch-header") { TvSectionHeader(stringResource(R.string.label_your_channels)) }-         if (topChannels.isEmpty()) {--            item(key = "ch-empty") { TvEmptyRow(stringResource(R.string.label_no_channels)) }-+            item(key = "ch-empty") {+                TvInterestEmpty(stringResource(R.string.label_no_channels))+            }         }-         items(topChannels, key = { "ch-$it" }) { channelKey ->-             val pinned = channelKey in pinnedKeys-             TvInterestRow(-                 label = channelKey.decodeHtml(),-                 badge = if (pinned) stringResource(R.string.label_pinned) else null,-                 primaryAction = if (pinned) {-                     stringResource(R.string.action_unpin)-                 } else {-                     stringResource(R.string.action_pin)-                 },-                 onPrimary = {-                     if (pinned) ypvm.clearChannelPreference(channelKey) else ypvm.pinChannel(channelKey)-                 },-                 secondaryAction = stringResource(UiR.string.remove),-                 onSecondary = { ypvm.removeInterest(channelKey = channelKey) },-             )-         }--        item(key = "kw-header") { TvSectionHeader(stringResource(R.string.label_your_topics)) }-+        item(key = "kw-header") {+            TvInterestSectionHeader(stringResource(R.string.label_your_topics))+        }         if (topKeywords.isEmpty()) {--            item(key = "kw-empty") { TvEmptyRow(stringResource(R.string.label_no_topics)) }-+            item(key = "kw-empty") {+                TvInterestEmpty(stringResource(R.string.label_no_topics))+            }         }-         items(topKeywords, key = { "kw-$it" }) { keyword ->-             TvInterestRow(-                 label = keyword,-                 primaryAction = stringResource(UiR.string.remove),-                 onPrimary = { ypvm.removeInterest(keyword = keyword) },-             )-         }--        item(key = "bl-header") { TvSectionHeader(stringResource(R.string.label_blocked_channels)) }-+        item(key = "bl-header") {+            TvInterestSectionHeader(stringResource(R.string.label_blocked_channels))+        }         if (blockedChannels.isEmpty()) {--            item(key = "bl-empty") { TvEmptyRow(stringResource(R.string.label_no_blocked_channels)) }-+            item(key = "bl-empty") {+                TvInterestEmpty(stringResource(R.string.label_no_blocked_channels))+            }         }-         items(blockedChannels, key = { "bl-$it" }) { channelKey ->-             TvInterestRow(-                 label = channelKey.decodeHtml(),-                 primaryAction = stringResource(R.string.action_unblock),-                 onPrimary = { ypvm.clearChannelPreference(channelKey) },-             )-         }--        item(key = "mk-header") { TvSectionHeader(stringResource(R.string.label_muted_keywords)) }-+        item(key = "mk-header") {+            TvInterestSectionHeader(stringResource(R.string.label_muted_keywords))+        }         if (mutedKeywords.isEmpty()) {--            item(key = "mk-empty") { TvEmptyRow(stringResource(R.string.label_no_muted_keywords)) }-+            item(key = "mk-empty") {+                TvInterestEmpty(stringResource(R.string.label_no_muted_keywords))+            }         }-         items(mutedKeywords, key = { "mk-$it" }) { keyword ->-             TvInterestRow(-                 label = keyword,-                 primaryAction = stringResource(R.string.action_unmute),-                 onPrimary = { ypvm.unmuteKeyword(keyword) },-             )-         }-     }- } -- @Composable--private fun TvSectionHeader(text: String) {-+private fun TvInterestSectionHeader(text: String) {     Text(-         text = text,--        style = MaterialTheme.typography.titleSmall,-+        style = MaterialTheme.typography.titleLarge,         color = MaterialTheme.colorScheme.primary,-+        modifier = Modifier.padding(top = 12.dp),     )- } -- @Composable--private fun TvEmptyRow(text: String) {-+private fun TvInterestEmpty(text: String) {     Text(-         text = text,-         style = MaterialTheme.typography.bodyMedium,-         color = MaterialTheme.colorScheme.onSurfaceVariant,-     )- } -- /**-- * One interest row: label + badge + stacked action buttons, each a focus target.-- * Actions stack under the label (not beside it) so DOWN always reaches them.-+ * One interest row: the row itself fires the primary action; a secondary action (when+ * present) is a [TvButton] on the line below so DOWN always reaches it with no nesting.  */- @Composable- private fun TvInterestRow(-     label: String,-     primaryAction: String,-     onPrimary: () -> Unit,-     modifier: Modifier = Modifier,-     badge: String? = null,-     secondaryAction: String? = null,-     onSecondary: (() -> Unit)? = null,- ) {--    Surface(onClick = onPrimary, modifier = modifier.fillMaxWidth()) {--        Column(Modifier.padding(16.dp)) {--            Text(text = label, style = MaterialTheme.typography.titleMedium)--            if (badge != null) {--                Text(--                    text = badge,--                    style = MaterialTheme.typography.bodySmall,--                    color = MaterialTheme.colorScheme.primary,--                )--            }--            Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(top = 8.dp)) {--                Button(onClick = onPrimary) { Text(primaryAction) }--                if (secondaryAction != null && onSecondary != null) {--                    Button(onClick = onSecondary) { Text(secondaryAction) }--                }--            }-+    Column(modifier.fillMaxWidth()) {+        TvListRow(+            headline = label,+            supporting = badge,+            onClick = onPrimary,+        )+        if (secondaryAction != null && onSecondary != null) {+            TvButton(+                text = secondaryAction,+                onClick = onSecondary,+                modifier = Modifier.padding(top = 4.dp),+            )         }-     }- }
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 f26824ce1f..cb1c3958bc 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/tv/TvNavigation.kt@@ -1,19 +1,21 @@ package com.vayunmathur.youpipe.tv -import androidx.activity.compose.BackHandler-import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember+import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue-import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Tab-import androidx.tv.material3.TabRow+import com.vayunmathur.library.tv.TvAppFrame+import com.vayunmathur.library.tv.TvDestination+import com.vayunmathur.library.tv.TvIcon+import com.vayunmathur.library.ui.IconHistory+import com.vayunmathur.library.ui.IconHome+import com.vayunmathur.library.ui.IconPhotoLibrary+import com.vayunmathur.library.ui.IconSearch+import com.vayunmathur.library.ui.IconSettings+import com.vayunmathur.library.ui.IconSubscriptions import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack@@ -28,21 +30,22 @@ import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.util.YouPipeViewModel  /**- * The TV navigation host: [rememberNavBackStack] + [MainNavigation] over [TvRoute], replacing- * the phone's 5-tab swipe pager.+ * The TV navigation host: [rememberNavBackStack] + [MainNavigation] over [TvRoute], inside a+ * [TvAppFrame] icon rail.  *- * No `HorizontalPager` swipe — a TV has no touch — and no shared-element morphs: the phone's- * title keys assume single-origin compositions the tab pager already strains, and TV screens- * compose independently. Tabs are a focusable [TabRow] strip; D-pad LEFT/RIGHT moves between- * tabs, DOWN drops into content. Each tab keeps its own screen so focus restores per tab.+ * The rail (Search, Home, Subscriptions, History, Saved, Settings) owns the top-level+ * destinations — focus moves select, CENTER jumps into content, BACK from content returns to+ * the rail. Detail routes (video, channel, feed, playlist, settings sub-pages, dialogs-as-pages)+ * push above the frame; popping them returns to the rail screen underneath.  */ @Composable fun TvNavigation(ypvm: YouPipeViewModel, initialBackStack: List<TvRoute> = listOf(TvRoute.Main())) {     val backStack = rememberNavBackStack(initialBackStack)     MainNavigation(backStack) {-        entry<TvRoute.Main> { TvMainTabs(backStack, ypvm, it.initialTab) }+        entry<TvRoute.Main> { TvRailHost(backStack, ypvm, it.initialTab) }         entry<TvRoute.Search> { TvSearchPage(backStack, ypvm) }         entry<TvRoute.Video> { TvVideoPage(backStack, ypvm, it.videoID) }+        entry<TvRoute.VideoPlayerRoute> { TvPlayerPage(backStack, ypvm, it.videoID) }         entry<TvRoute.Channel> { TvChannelPage(backStack, ypvm, it.channelID) }         entry<TvRoute.SubscriptionFeed> { TvSubscriptionFeedPage(backStack, ypvm, it.category) }         entry<TvRoute.CreateSubscriptionCategory> { TvCreateCategoryPage(backStack, ypvm, it.id) }@@ -60,69 +63,64 @@ fun TvNavigation(ypvm: YouPipeViewModel, initialBackStack: List<TvRoute> = listO  /**  * Map a persisted default-page key to the TV initial backstack, mirroring the phone- * [com.vayunmathur.youpipe.defaultBackStack] mapping. Tab indices match [TvMainTabs]:- * the same five tabs the phone offers minus swipe. `all_subscriptions` seeds the- * Subscriptions root beneath the feed so BACK returns to the list instead of exiting.+ * [com.vayunmathur.youpipe.defaultBackStack] mapping. Rail indices match [TvRailHost]:+ * `all_subscriptions` seeds the Subscriptions root beneath the feed so BACK returns to the+ * list instead of exiting.  */ fun tvDefaultBackStack(key: String?): List<TvRoute> = when (key) {-    DEFAULT_PAGE_SUBSCRIPTIONS -> listOf(TvRoute.Main(TV_TAB_SUBSCRIPTIONS))+    DEFAULT_PAGE_SUBSCRIPTIONS -> listOf(TvRoute.Main(TV_RAIL_SUBSCRIPTIONS))     DEFAULT_PAGE_ALL_SUBSCRIPTIONS ->-        listOf(TvRoute.Main(TV_TAB_SUBSCRIPTIONS), TvRoute.SubscriptionFeed(null))-    DEFAULT_PAGE_HISTORY -> listOf(TvRoute.Main(TV_TAB_HISTORY))+        listOf(TvRoute.Main(TV_RAIL_SUBSCRIPTIONS), TvRoute.SubscriptionFeed(null))+    DEFAULT_PAGE_HISTORY -> listOf(TvRoute.Main(TV_RAIL_HISTORY))     // Both the legacy "downloads" key and the new "saved" key open the Saved hub.-    DEFAULT_PAGE_DOWNLOADS, DEFAULT_PAGE_SAVED -> listOf(TvRoute.Main(TV_TAB_SAVED))-    DEFAULT_PAGE_SETTINGS -> listOf(TvRoute.Main(TV_TAB_SETTINGS))-    else -> listOf(TvRoute.Main(TV_TAB_HOME)) // home / unset / unknown+    DEFAULT_PAGE_DOWNLOADS, DEFAULT_PAGE_SAVED -> listOf(TvRoute.Main(TV_RAIL_SAVED))+    DEFAULT_PAGE_SETTINGS -> listOf(TvRoute.Main(TV_RAIL_SETTINGS))+    else -> listOf(TvRoute.Main(TV_RAIL_HOME)) // home / unset / unknown }  /**- * The five TV tabs as a D-pad strip: Home, Subscriptions, History, Saved, Settings.- *- * Unlike the phone's `TabbedPagerScaffold`, tabs are destinations only — selecting one swaps- * the content below without any swipe gesture. Per-tab focus restores because each tab's- * screen owns its own list state.

Diff truncated.