Modern Apps git

← Modern-Apps.git

appstore: redesign TV UI on library:tv

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

Diff

appstore/build.gradle.kts
diff --git a/appstore/build.gradle.kts b/appstore/build.gradle.ktsindex 4e8fd0e9e3..65b4aec85b 100644--- a/appstore/build.gradle.kts+++ b/appstore/build.gradle.kts@@ -62,6 +62,7 @@ dependencies {     implementation(project(":library:work"))     implementation(libs.androidx.datastore.preferences)     implementation(project(":library:image"))+    implementation(project(":library:tv"))     // APK source-stamp verification. The stamp is a second signing identity that     // survives Play App Signing re-signing, so it can be pinned per package where the     // APK signing key (held by Google) cannot be.
appstore/src/main/java/com/vayunmathur/appstore/tv/TvBrowse.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvBrowse.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvBrowse.ktdeleted file mode 100644index 694dcbcfe1..0000000000--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvBrowse.kt+++ /dev/null@@ -1,228 +0,0 @@-package com.vayunmathur.appstore.tv--import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.LazyRow-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.runtime.Composable-import androidx.compose.runtime.collectAsState-import androidx.compose.runtime.getValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.draw.clip-import androidx.compose.ui.layout.ContentScale-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.text.style.TextOverflow-import androidx.compose.ui.unit.dp-import androidx.tv.material3.Button-import androidx.tv.material3.Card-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Text-import com.vayunmathur.appstore.R-import com.vayunmathur.appstore.data.UnifiedApp-import com.vayunmathur.appstore.data.installer.InstallStage-import com.vayunmathur.library.image.compose.AsyncImage--/**- * The TV browse: one row per source, TV-compatible listings only.- *- * The rows come from the same repositories the phone UI reads, which already filter- * to TV-compatible apps — nothing here filters again. Each tile is a tv-material- * [Card] so the D-pad focus ring is handled by the design system, not by hand.- */-@Composable-fun TvStoreHome(-    viewModel: TvStoreViewModel,-    onAppClick: (UnifiedApp) -> Unit,-    modifier: Modifier = Modifier,-) {-    val state by viewModel.home.collectAsState()-    TvBrowseScreen(state = state, onAppClick = onAppClick, modifier = modifier)-}--/**- * Stateless browse grid, so it can be rendered in a preview.- *- * // RAW SCAFFOLD EXCEPTION: androidx.tv has no AppScaffold equivalent, and the TV- * ten-foot rule (see cast/tv ReceiverContent) is that a title bar above a browse- * grid is furniture — the rows are the screen.- */-@Composable-internal fun TvBrowseScreen(-    state: TvHomeUiState,-    onAppClick: (UnifiedApp) -> Unit = {},-    modifier: Modifier = Modifier,-) {-    Column(-        modifier = modifier-            .fillMaxSize()-            .background(MaterialTheme.colorScheme.background)-            .padding(horizontal = 48.dp, vertical = 32.dp),-        verticalArrangement = Arrangement.spacedBy(24.dp),-    ) {-        Text(-            text = stringResource(R.string.tv_browse_title),-            style = MaterialTheme.typography.headlineLarge,-            color = MaterialTheme.colorScheme.onSurface,-        )-        if (state.isLoading && state.sections.isEmpty()) {-            Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {-                Text(-                    text = stringResource(R.string.sync_in_progress),-                    style = MaterialTheme.typography.titleMedium,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                )-            }-            return@Column-        }-        if (state.sections.isEmpty()) {-            Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {-                Text(-                    text = stringResource(R.string.home_empty_message),-                    style = MaterialTheme.typography.titleMedium,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                    textAlign = TextAlign.Center,-                )-            }-            return@Column-        }-        LazyColumn(-            modifier = Modifier.fillMaxSize(),-            verticalArrangement = Arrangement.spacedBy(24.dp),-            contentPadding = PaddingValues(bottom = 24.dp),-        ) {-            items(state.sections, key = { it.id }) { section ->-                TvSectionRow(-                    section = section,-                    installedPackages = state.installedPackages,-                    stages = state.stages,-                    onAppClick = onAppClick,-                )-            }-        }-    }-}--@Composable-private fun TvSectionRow(-    section: TvSection,-    installedPackages: Set<String>,-    stages: Map<String, InstallStage>,-    onAppClick: (UnifiedApp) -> Unit,-) {-    Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {-        Text(-            text = section.title,-            style = MaterialTheme.typography.titleLarge,-            color = MaterialTheme.colorScheme.onSurface,-        )-        LazyRow(-            modifier = Modifier.fillMaxWidth(),-            horizontalArrangement = Arrangement.spacedBy(16.dp),-            contentPadding = PaddingValues(horizontal = 4.dp),-        ) {-            items(section.apps, key = { it.packageName }) { app ->-                TvAppTile(-                    app = app,-                    isInstalled = app.packageName in installedPackages,-                    stage = stages[app.packageName],-                    onClick = { onAppClick(app) },-                )-            }-        }-    }-}--@Composable-private fun TvAppTile(-    app: UnifiedApp,-    isInstalled: Boolean,-    stage: InstallStage?,-    onClick: () -> Unit,-) {-    // Ten-foot density: 200–250dp cards with a larger icon and a titleMedium/bodyMedium-    // floor, so tiles read from the couch instead of phone-scale.-    Card(onClick = onClick, modifier = Modifier.width(220.dp)) {-        Column(-            modifier = Modifier.padding(16.dp),-            horizontalAlignment = Alignment.CenterHorizontally,-            verticalArrangement = Arrangement.spacedBy(8.dp),-        ) {-            TvAppIcon(app = app)-            Text(-                text = app.name,-                style = MaterialTheme.typography.titleMedium,-                color = MaterialTheme.colorScheme.onSurface,-                textAlign = TextAlign.Center,-                maxLines = 2,-                overflow = TextOverflow.Ellipsis,-                modifier = Modifier.height(48.dp),-            )-            val status = when {-                stage != null -> stage.tvLabel()-                isInstalled -> stringResource(R.string.installed)-                else -> null-            }-            if (status != null) {-                Text(-                    text = status,-                    style = MaterialTheme.typography.bodyMedium,-                    color = if (stage is InstallStage.Failed) {-                        MaterialTheme.colorScheme.error-                    } else {-                        MaterialTheme.colorScheme.onSurfaceVariant-                    },-                    maxLines = 1,-                    overflow = TextOverflow.Ellipsis,-                )-            }-        }-    }-}--@Composable-private fun TvAppIcon(app: UnifiedApp) {-    val box = Modifier-        .size(96.dp)-        .clip(RoundedCornerShape(20.dp))-    if (app.iconUrl != null) {-        AsyncImage(-            model = app.iconUrl,-            contentDescription = null,-            modifier = box,-            contentScale = ContentScale.Crop,-        )-    } else {-        Box(-            box.background(MaterialTheme.colorScheme.surfaceVariant),-            contentAlignment = Alignment.Center,-        ) {-            Text(-                text = app.name.take(1).uppercase(),-                style = MaterialTheme.typography.headlineSmall,-                color = MaterialTheme.colorScheme.onSurfaceVariant,-            )-        }-    }-}--@Composable-private fun InstallStage.tvLabel(): String = when (this) {-    InstallStage.Preparing -> stringResource(R.string.stage_preparing)-    is InstallStage.Downloading -> stringResource(R.string.stage_downloading, (fraction * 100).toInt())-    InstallStage.Verifying -> stringResource(R.string.stage_verifying)-    InstallStage.Installing -> stringResource(R.string.stage_installing)-    is InstallStage.Failed -> stringResource(R.string.stage_failed, reason)-}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvDetail.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvDetail.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvDetail.ktdeleted file mode 100644index fe3ee89b01..0000000000--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvDetail.kt+++ /dev/null@@ -1,547 +0,0 @@-package com.vayunmathur.appstore.tv--import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.aspectRatio-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.heightIn-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.LazyRow-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.runtime.Composable-import androidx.compose.runtime.collectAsState-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableFloatStateOf-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.draw.clip-import androidx.compose.ui.layout.ContentScale-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.font.FontWeight-import androidx.compose.ui.text.style.TextOverflow-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.appstore.R-import com.vayunmathur.appstore.data.UnifiedApp-import com.vayunmathur.appstore.data.installer.InstallStage-import com.vayunmathur.appstore.data.security.VerificationResult-import com.vayunmathur.appstore.ui.formatCount-import com.vayunmathur.appstore.ui.formatSize-import com.vayunmathur.library.image.compose.AsyncImage-import com.vayunmathur.library.image.compose.AsyncImageState-import com.vayunmathur.library.ui.IconDelete-import com.vayunmathur.library.ui.IconTv--/**- * One app's TV page: what it is, what it looks like, and the install button.- *- * The install and update buttons call the same [TvStoreViewModel.install] the browse- * rows use — which runs the ordinary [InstallCoordinator] pipeline verbatim, including- * the TV-compat gate. There is no TV-specific install path.- *- * TV compatibility is stated explicitly rather than implied by presence: an app that- * reached this screen passed the catalogue filter, and the line says why (a leanback- * entry the source published) or that the source said nothing either way.- *- * Order mirrors the phone's detail page — screenshots, the install button, the- * description, then the facts, then provenance — at ten-foot density: a- * focus-scrolling [LazyColumn], 56–64dp buttons, 12–16dp fact gaps, and `bodyLarge`- * body text. Share/browser/Play links and `market://` deep links are phone-only and- * stay off this screen.- */-@Composable-fun TvAppDetail(-    viewModel: TvStoreViewModel,-    modifier: Modifier = Modifier,-    onBack: () -> Unit = {},-) {-    val state by viewModel.detail.collectAsState()-    TvDetailScreen(-        state = state,-        onInstall = { app -> viewModel.install(app) },-        onOpen = { pkg -> viewModel.openApp(pkg) },-        onUninstall = { pkg -> viewModel.uninstallApp(pkg) },-        onDismissFailure = { pkg -> viewModel.dismissInstallFailure(pkg) },-        onBack = onBack,-        modifier = modifier,-    )-}--/**- * Stateless detail, so it can be rendered in a preview.- *- * // RAW SCAFFOLD EXCEPTION: androidx.tv has no AppScaffold equivalent; the detail is- * a single focus-scrolling column with a back button, not a scaffolded phone screen.- */-@Composable-internal fun TvDetailScreen(-    state: TvDetailUiState,-    modifier: Modifier = Modifier,-    onInstall: (UnifiedApp) -> Unit = {},-    onOpen: (String) -> Unit = {},-    onUninstall: (String) -> Unit = {},-    onDismissFailure: (String) -> Unit = {},-    onBack: () -> Unit = {},-) {-    val app = state.app ?: return-    val stage = state.stage-    val busy = stage != null && stage !is InstallStage.Failed-    // @Composable string resolutions hoisted: the LazyColumn item lambdas below are not-    // @Composable scopes for non-local calls like toMessage() — only their trailing-    // content lambdas are. Everything resolved here, plain values used below.-    val verificationMessage = state.verification.toMessage()-    val reproducibleLabel = if (app.reproducible) stringResource(R.string.chip_reproducible) else null-    val adsLabel = if (app.containsAds) stringResource(R.string.chip_contains_ads) else null-    val flags = buildList {-        reproducibleLabel?.let { add(it) }-        adsLabel?.let { add(it) }-        addAll(app.antiFeatures)-    }-    val shots = app.tvScreenshots.ifEmpty { app.screenshots }-    // A LazyColumn, not a scrollable Column: D-pad focus moves item to item, and the-    // list scrolls the focused block into view. A Column would scroll the pixels while-    // focus stays wherever it was.-    LazyColumn(-        modifier = modifier-            .fillMaxSize()-            .background(MaterialTheme.colorScheme.background)-            .padding(horizontal = 48.dp, vertical = 32.dp),-        verticalArrangement = Arrangement.spacedBy(16.dp),-        contentPadding = PaddingValues(bottom = 24.dp),-    ) {-        item("back") {-            Button(onClick = onBack, modifier = Modifier.heightIn(min = 56.dp)) {-                Text(stringResource(R.string.tv_detail_back), style = MaterialTheme.typography.bodyLarge)-            }-        }-        item("title") {-            Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {-                Text(-                    text = app.name,-                    style = MaterialTheme.typography.displaySmall,-                    color = MaterialTheme.colorScheme.onSurface,-                )-                if (app.summary.isNotBlank()) {-                    Text(-                        text = app.summary,-                        style = MaterialTheme.typography.titleMedium,-                        color = MaterialTheme.colorScheme.onSurfaceVariant,-                    )-                }-                if (state.isLoadingDetails) {-                    Text(-                        text = stringResource(R.string.sync_in_progress),-                        style = MaterialTheme.typography.bodyLarge,-                        color = MaterialTheme.colorScheme.onSurfaceVariant,-                    )-                }-            }-        }-        item("compat") { TvCompatLine(app = app) }-        item("actions") {-            Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {-                when {-                    busy -> Button(-                        onClick = {},-                        enabled = false,-                        modifier = Modifier-                            .weight(1f)-                            .heightIn(min = 56.dp),-                    ) {-                        Text(stage.tvStageLabel(), style = MaterialTheme.typography.bodyLarge)-                    }-                    state.hasUpdate -> {-                        Button(-                            onClick = { onInstall(app) },-                            modifier = Modifier-                                .weight(1f)-                                .heightIn(min = 56.dp),-                        ) {-                            Text(-                                stringResource(R.string.action_update),-                                style = MaterialTheme.typography.bodyLarge,-                            )-                        }-                        Button(-                            onClick = { onOpen(app.packageName) },-                            modifier = Modifier.heightIn(min = 56.dp),-                        ) {-                            Text(-                                stringResource(com.vayunmathur.library.ui.R.string.open),-                                style = MaterialTheme.typography.bodyLarge,-                            )-                        }-                    }-                    state.isInstalled -> {-                        Button(-                            onClick = { onOpen(app.packageName) },-                            modifier = Modifier-                                .weight(1f)-                                .heightIn(min = 56.dp),-                        ) {-                            Text(-                                stringResource(com.vayunmathur.library.ui.R.string.open),-                                style = MaterialTheme.typography.bodyLarge,-                            )-                        }-                        Button(-                            onClick = { onUninstall(app.packageName) },-                            modifier = Modifier.heightIn(min = 56.dp),-                        ) {-                            // IconXxx from library/ui — never Icon()/painterResource() in app modules.-                            IconDelete()-                        }-                    }-                    else -> Button(-                        onClick = { onInstall(app) },-                        modifier = Modifier-                            .weight(1f)-                            .heightIn(min = 56.dp),-                    ) {-                        Text(-                            stringResource(R.string.action_install),-                            style = MaterialTheme.typography.bodyLarge,-                        )-                    }-                }-            }-        }-        if (stage is InstallStage.Failed) {-            item("failure") {-                Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {-                    Text(-                        text = stringResource(R.string.stage_failed, stage.reason),-                        style = MaterialTheme.typography.bodyLarge,-                        color = MaterialTheme.colorScheme.error,-                    )-                    // Retry is dismiss + install: clearing the stage re-arms the install-                    // button, which reports the outcome once via AppMessages.-                    Button(-                        onClick = {-                            onDismissFailure(app.packageName)-                            onInstall(app)-                        },-                        modifier = Modifier.heightIn(min = 56.dp),-                    ) {-                        Text(-                            stringResource(R.string.action_check_again),-                            style = MaterialTheme.typography.bodyLarge,-                        )-                    }-                }-            }-        }-        if (verificationMessage != null) {-            item("verification") {-                Text(-                    text = verificationMessage,-                    style = MaterialTheme.typography.bodyLarge,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                )-            }-        }-        // TV screenshots where the source publishes a separate set — phone-aspect shots-        // jump between ratios when mixed. Falls back to the phone set, mirroring the-        // phone's strip order (screenshots, not hero-first: the hero is phone-framed).-        // (Resolved at the top of this screen — see shots.)-        if (shots.isNotEmpty()) {-            item("screenshots") {-                TvScreenshotStrip(urls = shots)-            }-        }-        item("facts") { TvDetailFactRow(app = app) }-        if (app.description.isNotBlank()) {-            item("about") {-                TvDetailAbout(app = app)-            }-        }-        if (app.whatsNew?.isNotBlank() == true) {-            item("whatsnew") {-                Column(-                    modifier = Modifier.fillMaxWidth(),-                    verticalArrangement = Arrangement.spacedBy(8.dp),-                ) {-                    Text(-                        text = stringResource(R.string.detail_whats_new),-                        style = MaterialTheme.typography.titleLarge,-                        color = MaterialTheme.colorScheme.onSurface,-                        fontWeight = FontWeight.SemiBold,-                    )-                    app.updatedOn?.let {-                        Text(-                            text = it,-                            style = MaterialTheme.typography.bodyLarge,-                            color = MaterialTheme.colorScheme.onSurfaceVariant,-                        )-                    }-                    Text(-                        text = app.whatsNew,-                        style = MaterialTheme.typography.bodyLarge,-                        color = MaterialTheme.colorScheme.onSurfaceVariant,-                    )-                }-            }-        }-        // Anti-features and reproducibility, simplified: the phone's chip row verbatim-        // would be a second focus axis; a plain list at bodyLarge reads at ten feet.-        // (Labels resolved at the top of this screen — see flags.)-        if (flags.isNotEmpty()) {-            item("flags") {-                Column(-                    modifier = Modifier.fillMaxWidth(),-                    verticalArrangement = Arrangement.spacedBy(8.dp),-                ) {-                    flags.forEach { flag ->-                        Text(-                            text = flag,-                            style = MaterialTheme.typography.bodyLarge,-                            color = MaterialTheme.colorScheme.onSurfaceVariant,-                        )-                    }-                }-            }-        }-        if (app.permissions.isNotEmpty()) {-            item("permissions") {-                Column(-                    modifier = Modifier.fillMaxWidth(),-                    verticalArrangement = Arrangement.spacedBy(8.dp),-                ) {-                    Text(-                        text = stringResource(R.string.detail_permissions),-                        style = MaterialTheme.typography.titleLarge,-                        color = MaterialTheme.colorScheme.onSurface,-                        fontWeight = FontWeight.SemiBold,-                    )-                    Text(-                        text = app.permissions.joinToString("\n") { it.substringAfterLast('.') },-                        style = MaterialTheme.typography.bodyLarge,-                        color = MaterialTheme.colorScheme.onSurfaceVariant,-                    )-                }-            }-        }-        item("details") { TvDetailFacts(app = app) }-    }-}--/**- * The TV-compat statement: why this app is offered on TV.- *- * Three cases, all factual: the source published a leanback signal; the source- * published phone-only hardware but the APK still installed (cannot happen through- * the filter — this line then explains the discrepancy); or the source said nothing- * and the install gate verified the bytes instead.- */-@Composable-private fun TvCompatLine(app: UnifiedApp) {-    Row(verticalAlignment = Alignment.CenterVertically) {-        IconTv(tint = MaterialTheme.colorScheme.primary)-        Spacer(Modifier.width(8.dp))-        Text(-            text = stringResource(-                if (app.tvCompatible == true) R.string.tv_compat_declared-                else R.string.tv_compat_unverified-            ),-            style = MaterialTheme.typography.bodyMedium,-            color = MaterialTheme.colorScheme.onSurfaceVariant,-        )-    }-}--/** TV screenshots at a fixed height so mixed aspect ratios still scroll as one strip. */-@Composable-private fun TvScreenshotStrip(urls: List<String>) {-    LazyRow(-        modifier = Modifier.fillMaxWidth(),-        horizontalArrangement = Arrangement.spacedBy(16.dp),-    ) {-        items(urls, key = { it }) { url ->-            // The width has to be stated: AsyncImage draws its bitmap with matchParentSize,-            // which contributes nothing to the measure pass, so an image given only a-            // height resolves to zero wide. Start at 16:9 and switch to the real ratio-            // once the bitmap has been decoded.-            var ratio by remember(url) { mutableFloatStateOf(LANDSCAPE_SCREENSHOT_RATIO) }-            AsyncImage(-                model = url,-                contentDescription = null,-                modifier = Modifier-                    .height(220.dp)-                    .aspectRatio(ratio)-                    .clip(RoundedCornerShape(12.dp))-                    .background(MaterialTheme.colorScheme.surfaceVariant),-                contentScale = ContentScale.Fit,-                onState = { state ->-                    val size = (state as? AsyncImageState.Success)?.painter?.intrinsicSize-                    if (size != null && size.width > 0f && size.height > 0f) {-                        ratio = size.width / size.height-                    }-                },-            )-        }-    }-}--/** 16:9, the shape a TV screenshot is until its own is known. */-private const val LANDSCAPE_SCREENSHOT_RATIO = 16f / 9f--/** Rating, installs, size and age rating, in whatever subset the source published. */-@Composable-private fun TvDetailFactRow(app: UnifiedApp) {-    val cells = buildList<Pair<String, String>> {-        app.rating?.let {-            add(-                stringResource(R.string.fact_rating) to-                    String.format(java.util.Locale.US, "%.1f★", it)-            )-        }-        if (app.installs > 0) add(stringResource(R.string.fact_installs) to formatCount(app.installs))-        if (app.sizeBytes > 0) add(stringResource(R.string.fact_size) to formatSize(app.sizeBytes))-        app.contentRating?.let { add(stringResource(R.string.fact_rated) to it) }-        app.versionName?.let { add(stringResource(R.string.fact_version) to it) }-    }-    if (cells.isEmpty()) return-    Row(-        modifier = Modifier.fillMaxWidth(),-        horizontalArrangement = Arrangement.SpaceEvenly,-    ) {-        cells.take(4).forEachIndexed { index, (label, value) ->-            if (index > 0) {-                Spacer(-                    Modifier-                        .width(1.dp)-                        .height(32.dp)-                        .background(MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.3f)),-                )-            }-            TvStatCell(label = label, value = value, modifier = Modifier.weight(1f))-        }-    }-}--/** A labelled value in the facts row, at a ten-foot floor. */-@Composable-private fun TvStatCell(label: String, value: String, modifier: Modifier = Modifier) {-    Column(-        modifier = modifier,-        horizontalAlignment = Alignment.CenterHorizontally,-    ) {-        Text(-            text = value,-            style = MaterialTheme.typography.bodyLarge,-            fontWeight = FontWeight.SemiBold,-            color = MaterialTheme.colorScheme.onSurface,-            maxLines = 1,-            overflow = TextOverflow.Ellipsis,-        )-        Text(-            text = label,-            style = MaterialTheme.typography.bodyMedium,-            color = MaterialTheme.colorScheme.onSurfaceVariant,-            maxLines = 1,-            overflow = TextOverflow.Ellipsis,-        )-    }-}--@Composable-private fun TvDetailAbout(app: UnifiedApp) {-    var expanded by remember(app.packageName) { mutableStateOf(false) }-    Column(-        modifier = Modifier.fillMaxWidth(),-        verticalArrangement = Arrangement.spacedBy(12.dp),-    ) {-        Text(-            text = stringResource(R.string.tv_detail_about),-            style = MaterialTheme.typography.titleLarge,-            color = MaterialTheme.colorScheme.onSurface,-            fontWeight = FontWeight.SemiBold,-        )-        Text(-            text = app.description,-            style = MaterialTheme.typography.bodyLarge,-            color = MaterialTheme.colorScheme.onSurfaceVariant,-            maxLines = if (expanded) Int.MAX_VALUE else 5,-            overflow = TextOverflow.Ellipsis,-        )-        Surface(onClick = { expanded = !expanded }) {-            Text(-                text = stringResource(-                    if (expanded) R.string.action_show_less else R.string.action_read_more-                ),-                style = MaterialTheme.typography.bodyLarge,-                color = MaterialTheme.colorScheme.primary,-                modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),-            )-        }-    }-}--@Composable-private fun TvDetailFacts(app: UnifiedApp) {-    Column(-        modifier = Modifier.fillMaxWidth(),-        verticalArrangement = Arrangement.spacedBy(12.dp),-    ) {-        app.versionName?.let { TvFact(stringResource(R.string.fact_version), it) }-        app.author?.let { TvFact(stringResource(R.string.tv_detail_author), it) }-        app.license?.let { TvFact(stringResource(R.string.detail_license), it) }-        app.targetSdk?.let { TvFact(stringResource(R.string.detail_target_sdk), it.toString()) }-        if (app.ratingCount > 0) {-            TvFact(stringResource(R.string.detail_rating_count), formatCount(app.ratingCount))-        }-        TvFact(stringResource(R.string.detail_package), app.packageName)-    }-}--@Composable-private fun TvFact(label: String, value: String) {-    Column(Modifier.fillMaxWidth()) {-        Text(-            text = label,-            style = MaterialTheme.typography.bodyMedium,-            color = MaterialTheme.colorScheme.onSurfaceVariant,-        )-        Text(-            text = value,-            style = MaterialTheme.typography.bodyLarge,-            color = MaterialTheme.colorScheme.onSurface,-        )-    }-}--@Composable-private fun VerificationResult?.toMessage(): String? = when (this) {-    is VerificationResult.Rejected ->-        stringResource(R.string.detail_install_blocked, reason)-    is VerificationResult.Verified ->-        stringResource(R.string.detail_checked_on_install, detail)-    is VerificationResult.Unverified ->-        stringResource(R.string.detail_installed_unverified, reason)-    null -> null-}--@Composable-private fun InstallStage.tvStageLabel(): String = when (this) {-    InstallStage.Preparing -> stringResource(R.string.stage_preparing)-    is InstallStage.Downloading -> stringResource(R.string.stage_downloading, (fraction * 100).toInt())-    InstallStage.Verifying -> stringResource(R.string.stage_verifying)-    InstallStage.Installing -> stringResource(R.string.stage_installing)-    is InstallStage.Failed -> stringResource(R.string.stage_failed, reason)-}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.ktindex c3589e497a..85a31b98a8 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.kt@@ -1,25 +1,37 @@ package com.vayunmathur.appstore.tv -import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState 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.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.lifecycle.viewmodel.compose.viewModel import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Tab-import androidx.tv.material3.TabRow import androidx.tv.material3.Text-import androidx.tv.material3.darkColorScheme-import androidx.lifecycle.viewmodel.compose.viewModel import com.vayunmathur.appstore.R import com.vayunmathur.appstore.data.AppStoreDatabaseRepository import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.UpdateCheckWorker+import com.vayunmathur.library.tv.MaTvTheme+import com.vayunmathur.library.tv.TvAccent+import com.vayunmathur.library.tv.TvAppFrame+import com.vayunmathur.library.tv.TvDestination+import com.vayunmathur.library.tv.TvIcon+import com.vayunmathur.library.ui.IconDownload+import com.vayunmathur.library.ui.IconHome+import com.vayunmathur.library.ui.IconPackage+import com.vayunmathur.library.ui.IconSearch+import com.vayunmathur.library.ui.IconStore import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack@@ -28,20 +40,20 @@ import com.vayunmathur.library.util.rememberNavBackStack import kotlinx.serialization.Serializable  /**- * TV-only destinations: browse/search/updates tabs plus one pushed detail.+ * TV-only destinations: the rail tabs plus one pushed detail.  *- * A separate sealed interface from the phone [com.vayunmathur.appstore.Route], following- * youpipe's `TvRoute`, so a TV destination can never leak into the phone back stack or- * vice versa. Search and updates are tabs here rather than pushed routes: on a D-pad the- * tab strip is the entry point, and each tab keeps its own screen so focus restores per tab.+ * A separate sealed interface from the phone `Route`, following youpipe's `TvRoute`, so+ * a TV destination can never leak into the phone back stack or vice versa. Home, search,+ * updates and library are rail destinations — selecting one swaps the content, and each+ * keeps its own screen so focus restores per destination.  */ @Serializable sealed interface TvStoreRoute : NavKey {-    /** The tab strip: browse, search, updates. No swipe, D-pad only. */+    /** The rail: home, search, updates, library. D-pad only, no swipe. */     @Serializable     data object Main : TvStoreRoute -    /** One app's page, pushed over the tabs. */+    /** One app's page, pushed over the rail. */     @Serializable     data class Detail(val packageName: String) : TvStoreRoute }@@ -50,10 +62,9 @@ sealed interface TvStoreRoute : NavKey {  * The TV entry: opened from TV launcher rows (LEANBACK_LAUNCHER). The phone MainActivity  * stays exactly as it is — this activity hosts the D-pad store UI.  *- * Browse, search, updates, and detail are nav-graph destinations, not activity states: the- * tab strip owns browse/search/updates, and detail pushes over it. The ViewModel is the- * phone repositories reused verbatim, so installs go through the ordinary pipeline- * including the TV-compat gate.+ * Browse, search, updates, library and detail are nav-graph destinations. The ViewModel+ * is the phone repositories reused verbatim, so installs go through the ordinary+ * pipeline including the TV-compat gate.  */ class TvMainActivity : MaActivity() {     override val edgeToEdge: Boolean = false@@ -67,9 +78,9 @@ 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 with the store's teal accent: a TV has no wallpaper to derive a+        // scheme from, and the accent marks this TV app at a glance.+        MaTvTheme(accent = TvAccent.Teal, content = content)     }      @Composable@@ -84,19 +95,19 @@ class TvMainActivity : MaActivity() { /**  * The TV navigation host: [rememberNavBackStack] + [MainNavigation] over [TvStoreRoute].  *- * The detail destination reads the selection the tab already set via+ * The detail destination reads the selection the rail already set via  * [TvStoreViewModel.selectApp] — popping clears it, so BACK from detail always lands on- * the tab that opened it with no stale selection behind it.+ * the destination that opened it with no stale selection behind it.  */ @Composable private fun TvStoreNavigation(viewModel: TvStoreViewModel) {     val backStack = rememberNavBackStack<TvStoreRoute>(TvStoreRoute.Main)     MainNavigation(backStack) {         entry<TvStoreRoute.Main> {-            TvStoreTabs(backStack = backStack, viewModel = viewModel)+            TvStoreRail(backStack = backStack, viewModel = viewModel)         }         entry<TvStoreRoute.Detail> {-            TvAppDetail(+            TvStoreDetail(                 viewModel = viewModel,                 onBack = {                     backStack.pop()@@ -107,61 +118,85 @@ private fun TvStoreNavigation(viewModel: TvStoreViewModel) {     } } +/** Rail destination indices, matching the destinations list order below. */+private const val TV_DEST_HOME = 0+private const val TV_DEST_SEARCH = 1+private const val TV_DEST_UPDATES = 2+private const val TV_DEST_LIBRARY = 3+ /**- * The three TV tabs as a D-pad strip: Browse, Search, Updates.- *- * 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.+ * The store shell: a [TvAppFrame] rail (Home, Search, Updates with count, Library) with+ * the store brand, and the selected destination's screen beside it.  */ @Composable-private fun TvStoreTabs(+private fun TvStoreRail(     backStack: NavBackStack<TvStoreRoute>,     viewModel: TvStoreViewModel, ) {-    var tab by remember { mutableIntStateOf(TV_TAB_BROWSE) }+    val updates by viewModel.updatesUi.collectAsState()+    val updateCount = updates.updates.size+    // @Composable string resolutions hoisted: the destination list below is plain data.+    val homeLabel = stringResource(R.string.nav_home)+    val searchLabel = stringResource(R.string.nav_search)+    val updatesLabel = if (updateCount > 0) {+        stringResource(R.string.tv_updates_with_count, updateCount)+    } else {+        stringResource(R.string.nav_updates)+    }+    val libraryLabel = stringResource(R.string.nav_library)+    val destinations = remember(homeLabel, searchLabel, updatesLabel, libraryLabel) {+        listOf(+            TvDestination(homeLabel) { IconHome() },+            TvDestination(searchLabel) { IconSearch() },+            TvDestination(updatesLabel) { IconDownload() },+            TvDestination(libraryLabel) { IconPackage() },+        )+    }+    var selectedIndex by rememberSaveable { mutableIntStateOf(0) }      fun openDetail(app: UnifiedApp) {         viewModel.selectApp(app)         backStack.add(TvStoreRoute.Detail(app.packageName))     } -    Column(-        Modifier-            .fillMaxSize()-            .background(MaterialTheme.colorScheme.background),+    TvAppFrame(+        destinations = destinations,+        selected = selectedIndex,+        onSelect = { selectedIndex = it },+        brand = { TvStoreBrand() },+        backReturnsToRail = backStack.backStack.size <= 1,     ) {-        TabRow(selectedTabIndex = tab) {-            Tab(-                selected = tab == TV_TAB_BROWSE,-                onFocus = { tab = TV_TAB_BROWSE },-                onClick = { tab = TV_TAB_BROWSE },-            ) {-                Text(stringResource(R.string.nav_home))-            }-            Tab(-                selected = tab == TV_TAB_SEARCH,-                onFocus = { tab = TV_TAB_SEARCH },-                onClick = { tab = TV_TAB_SEARCH },-            ) {-                Text(stringResource(R.string.nav_search))-            }-            Tab(-                selected = tab == TV_TAB_UPDATES,-                onFocus = { tab = TV_TAB_UPDATES },-                onClick = { tab = TV_TAB_UPDATES },-            ) {-                Text(stringResource(R.string.nav_updates))-            }-        }-        when (tab) {-            TV_TAB_SEARCH -> TvStoreSearch(viewModel = viewModel, onAppClick = ::openDetail)-            TV_TAB_UPDATES -> TvStoreUpdates(viewModel = viewModel, onAppClick = ::openDetail)+        when (selectedIndex) {+            TV_DEST_SEARCH -> TvStoreSearch(+                viewModel = viewModel,+                onAppClick = ::openDetail,+                // The keyboard opens only on an explicit CENTER press on the field;+                // arriving via the rail never starts editing.+                startEditing = false,+            )+            TV_DEST_UPDATES -> TvStoreUpdates(viewModel = viewModel, onAppClick = ::openDetail)+            TV_DEST_LIBRARY -> TvStoreLibrary(viewModel = viewModel, onAppClick = ::openDetail)             else -> TvStoreHome(viewModel = viewModel, onAppClick = ::openDetail)         }     } } -private const val TV_TAB_BROWSE = 0-private const val TV_TAB_SEARCH = 1-private const val TV_TAB_UPDATES = 2+/** Brand slot: store icon + "App Store" text, shown when the rail expands. */+@Composable+private fun TvStoreBrand(modifier: Modifier = Modifier) {+    Row(modifier, verticalAlignment = Alignment.CenterVertically) {+        Box(+            Modifier.size(40.dp),+            contentAlignment = Alignment.Center,+        ) {+            TvIcon { IconStore() }+        }+        Text(+            text = stringResource(R.string.app_name),+            style = MaterialTheme.typography.titleMedium,+            color = MaterialTheme.colorScheme.onSurface,+            maxLines = 1,+            modifier = Modifier.padding(start = 12.dp),+        )+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvSearch.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvSearch.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvSearch.ktdeleted file mode 100644index e97e90f396..0000000000--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvSearch.kt+++ /dev/null@@ -1,332 +0,0 @@-package com.vayunmathur.appstore.tv--import android.text.format.DateUtils-import androidx.compose.foundation.background-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.LazyRow-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.text.BasicTextField-import androidx.compose.foundation.text.KeyboardActions-import androidx.compose.foundation.text.KeyboardOptions-import androidx.compose.runtime.Composable-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.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.focus.focusRequester-import androidx.compose.ui.platform.LocalFocusManager-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.input.ImeAction-import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.text.style.TextOverflow-import androidx.compose.ui.unit.dp-import androidx.tv.material3.Card-import androidx.tv.material3.MaterialTheme-import androidx.tv.material3.Surface-import androidx.tv.material3.Tab-import androidx.tv.material3.TabRow-import androidx.tv.material3.Text-import com.vayunmathur.appstore.R-import com.vayunmathur.appstore.data.UnifiedApp-import com.vayunmathur.appstore.data.installer.InstallStage-import com.vayunmathur.appstore.util.SourceFilter-import com.vayunmathur.library.ui.IconDownload-import kotlinx.coroutines.delay--/**- * The TV search hub: query field, source-filter chips, and the local-then-Play merged results.- *- * Follows youpipe's `TvSearchPage` D-pad pattern: an entry row holds initial focus and a- * CENTER press moves focus into the field (opening the TV IME); the IME's search action- * submits. Results arrive in two waves — the on-disk catalogues answer first, Play's reply- * merges in a moment later — so the progress line sits above a list that already has- * content. A Play refusal (e.g. 429) is said above the list, never a silent gap.- */-@Composable-fun TvStoreSearch(-    viewModel: TvStoreViewModel,-    modifier: Modifier = Modifier,-    onAppClick: (UnifiedApp) -> Unit = {},-) {-    val state by viewModel.search.collectAsState()-    TvSearchScreen(-        state = state,-        onQueryChange = viewModel::setSearch,-        onFilterChange = viewModel::setSearchFilter,-        onAppClick = onAppClick,-        modifier = modifier,-    )-}--/**- * Stateless search hub, so it can be rendered in a preview.- *- * // RAW SCAFFOLD EXCEPTION: androidx.tv has no AppScaffold equivalent; the hub is a- * titled column with a D-pad list, not a scaffolded phone screen.- */-@Composable-internal fun TvSearchScreen(-    state: TvSearchUiState,-    modifier: Modifier = Modifier,-    onQueryChange: (String) -> Unit = {},-    onFilterChange: (SourceFilter) -> Unit = {},-    onAppClick: (UnifiedApp) -> Unit = {},-) {-    var fieldText by remember(state.query) { mutableStateOf(state.query) }-    var fieldOpen by remember { mutableStateOf(false) }-    val entryFocus = remember { FocusRequester() }-    val fieldFocus = remember { FocusRequester() }-    val focusManager = LocalFocusManager.current--    fun submit() {-        onQueryChange(fieldText)-        fieldOpen = false-        focusManager.clearFocus()-    }--    TvSearchInitialFocus(entryFocus)-    Column(-        modifier = modifier-            .fillMaxSize()-            .background(MaterialTheme.colorScheme.background)-            .padding(horizontal = 48.dp, vertical = 32.dp),-        verticalArrangement = Arrangement.spacedBy(16.dp),-    ) {-        Text(-            text = stringResource(R.string.nav_search),-            style = MaterialTheme.typography.headlineLarge,-            color = MaterialTheme.colorScheme.onSurface,-        )-        // The entry row: focused by default, CENTER opens the field, never the IME directly.-        Surface(-            onClick = { fieldOpen = true },-            modifier = Modifier-                .fillMaxWidth()-                .focusRequester(entryFocus),-        ) {-            Text(-                text = fieldText.ifBlank { stringResource(R.string.search_placeholder) },-                style = MaterialTheme.typography.titleMedium,-                color = if (fieldText.isBlank()) {-                    MaterialTheme.colorScheme.onSurfaceVariant-                } else {-                    MaterialTheme.colorScheme.onSurface-                },-                modifier = Modifier.padding(16.dp),-            )-        }--        if (fieldOpen) {-            // The actual text field: only composed after the explicit open, so the IME can-            // only ever appear as the result of a CENTER press. IME search action submits.-            BasicTextField(-                value = fieldText,-                onValueChange = {-                    fieldText = it-                    onQueryChange(it)-                },-                modifier = Modifier-                    .fillMaxWidth()-                    .focusRequester(fieldFocus),-                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),-                keyboardActions = KeyboardActions(onSearch = { submit() }),-                textStyle = MaterialTheme.typography.titleMedium.copy(-                    color = MaterialTheme.colorScheme.onSurface,-                ),-            )-            LaunchedEffect(fieldFocus) {-                fieldFocus.requestFocus()-            }-        }--        TvSourceFilterRow(filter = state.filter, onFilterChange = onFilterChange)--        if (state.isSearching && state.results.isNotEmpty()) {-            Text(-                text = stringResource(R.string.updates_checking),-                style = MaterialTheme.typography.bodyMedium,-                color = MaterialTheme.colorScheme.onSurfaceVariant,-            )-        }--        // Play's half refused (429): say so above the results rather than silently-        // showing a list that is missing half its sources.-        val playError = state.playError.takeIf { it.isNotBlank() }-        if (playError != null) {-            Text(-                text = playError,-                style = MaterialTheme.typography.bodyMedium,-                color = MaterialTheme.colorScheme.error,-            )-        }--        when {-            state.query.isBlank() -> Box(-                Modifier.fillMaxSize(),-                contentAlignment = Alignment.Center,-            ) {-                Text(-                    text = stringResource(R.string.search_prompt_message),-                    style = MaterialTheme.typography.titleMedium,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                    textAlign = TextAlign.Center,-                )-            }--            state.results.isEmpty() && (state.isSearching || !state.hasSearched) -> Box(-                Modifier.fillMaxSize(),-                contentAlignment = Alignment.Center,-            ) {-                Text(-                    text = stringResource(R.string.sync_in_progress),-                    style = MaterialTheme.typography.titleMedium,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                )-            }--            state.results.isEmpty() -> Box(-                Modifier.fillMaxSize(),-                contentAlignment = Alignment.Center,-            ) {-                Text(-                    text = stringResource(R.string.search_no_results_title, state.query),-                    style = MaterialTheme.typography.titleMedium,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                    textAlign = TextAlign.Center,-                )-            }--            else -> LazyColumn(-                modifier = Modifier.fillMaxSize(),-                verticalArrangement = Arrangement.spacedBy(12.dp),-                contentPadding = PaddingValues(bottom = 24.dp),-            ) {-                items(state.results, key = { it.packageName }) { app ->-                    TvSearchRow(-                        app = app,-                        isInstalled = app.packageName in state.installedPackages,-                        stage = state.stages[app.packageName],-                        onClick = { onAppClick(app) },-                    )-                }-            }-        }-    }-}--/** Source-filter chips as a focusable D-pad row. */-@Composable-private fun TvSourceFilterRow(-    filter: SourceFilter,-    onFilterChange: (SourceFilter) -> Unit,-) {-    // A TabRow is the tv-material D-pad answer to a chip row: LEFT/RIGHT moves between-    // filters, DOWN drops into the results. No swipe, no pointer.-    TabRow(selectedTabIndex = SourceFilter.entries.indexOf(filter)) {-        for (entry in SourceFilter.entries) {-            Tab(-                selected = filter == entry,-                onFocus = { onFilterChange(entry) },-                onClick = { onFilterChange(entry) },-            ) {-                Text(stringResource(entry.tvLabelRes()))-            }-        }-    }-}--private fun SourceFilter.tvLabelRes(): Int = when (this) {-    SourceFilter.ALL -> R.string.filter_all-    SourceFilter.MODERN_APPS -> R.string.source_chip_modern_apps-    SourceFilter.PROPRIETARY -> R.string.source_chip_proprietary-    SourceFilter.FDROID -> R.string.source_chip_fdroid-    SourceFilter.PLAYSTORE -> R.string.source_chip_play-    SourceFilter.ACCRESCENT -> R.string.source_chip_accrescent-}--/** One search hit: name, summary, source, and install/update status. */-@Composable-private fun TvSearchRow(-    app: UnifiedApp,-    isInstalled: Boolean,-    stage: InstallStage?,-    onClick: () -> Unit,-) {-    Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {-        Column(-            modifier = Modifier.padding(16.dp),-            verticalArrangement = Arrangement.spacedBy(4.dp),-        ) {-            Text(-                text = app.name,-                style = MaterialTheme.typography.titleMedium,-                color = MaterialTheme.colorScheme.onSurface,-                maxLines = 1,-                overflow = TextOverflow.Ellipsis,-            )-            if (app.summary.isNotBlank()) {-                Text(-                    text = app.summary,-                    style = MaterialTheme.typography.bodyMedium,-                    color = MaterialTheme.colorScheme.onSurfaceVariant,-                    maxLines = 2,-                    overflow = TextOverflow.Ellipsis,-                )-            }-            val status = when {-                stage != null -> stage.tvSearchLabel()-                isInstalled -> stringResource(R.string.installed)-                else -> null-            }-            if (status != null) {-                Text(-                    text = status,-                    style = MaterialTheme.typography.bodyMedium,-                    color = if (stage is InstallStage.Failed) {-                        MaterialTheme.colorScheme.error-                    } else {-                        MaterialTheme.colorScheme.onSurfaceVariant-                    },-                    maxLines = 1,-                    overflow = TextOverflow.Ellipsis,-                )-            }-        }-    }-}--@Composable-private fun InstallStage.tvSearchLabel(): String = when (this) {-    InstallStage.Preparing -> stringResource(R.string.stage_preparing)-    is InstallStage.Downloading -> stringResource(R.string.stage_downloading, (fraction * 100).toInt())-    InstallStage.Verifying -> stringResource(R.string.stage_verifying)-    InstallStage.Installing -> stringResource(R.string.stage_installing)-    is InstallStage.Failed -> stringResource(R.string.stage_failed, reason)-}--/** Request focus once composed, so the D-pad has somewhere to start on this hub. */-@Composable-private fun TvSearchInitialFocus(requester: FocusRequester) {-    LaunchedEffect(requester) {-        // One frame late: requesting during composition races the focus system on first-        // layout and silently drops, leaving the D-pad dead until the user presses something.-        delay(FRAME_DELAY_MS)-        runCatching { requester.requestFocus() }-    }-}--private const val FRAME_DELAY_MS = 16L
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetail.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetail.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetail.ktnew file mode 100644index 0000000000..ab8ef54b29--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetail.kt@@ -0,0 +1,276 @@+package com.vayunmathur.appstore.tv++import androidx.activity.compose.BackHandler+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text as TvText+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.installer.InstallStage+import com.vayunmathur.appstore.ui.formatSize+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.tv.TvBackdrop+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvHeroText+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvProgressStrip+import com.vayunmathur.library.tv.TvShelf+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconBack+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconPackage+import com.vayunmathur.library.ui.R as UiR++/**+ * One app's immersive TV page: backdrop, hero with install actions and the security+ * panel, screenshots, description, facts. Same install pipeline as everywhere else —+ * [TvStoreViewModel.install] runs the ordinary coordinator verbatim, including the+ * TV-compat gate.+ *+ * Order mirrors the phone's detail page — hero, screenshots, description, facts — with+ * the trust card promoted next to the actions: signature verification is the product,+ * and on TV it sits beside the Install button rather than below the fold.+ */+@Composable+fun TvStoreDetail(+    viewModel: TvStoreViewModel,+    onBack: () -> Unit,+    modifier: Modifier = Modifier,+) {+    val state by viewModel.detail.collectAsState()+    BackHandler(onBack = onBack)+    TvStoreDetailScreen(+        state = state,+        onInstall = viewModel::install,+        onOpen = viewModel::openApp,+        onUninstall = viewModel::uninstallApp,+        onDismissFailure = viewModel::dismissInstallFailure,+        onBack = onBack,+        modifier = modifier,+    )+}++@Composable+internal fun TvStoreDetailScreen(+    state: TvDetailUiState,+    modifier: Modifier = Modifier,+    onInstall: (UnifiedApp) -> Unit = {},+    onOpen: (String) -> Unit = {},+    onUninstall: (String) -> Unit = {},+    onDismissFailure: (String) -> Unit = {},+    onBack: () -> Unit = {},+) {+    val app = state.app+    val primaryFocus = remember(app?.packageName) { FocusRequester() }+    if (app == null) {+        TvEmptyState(+            title = stringResource(R.string.home_empty_title),+            icon = { IconPackage() },+            action = { TvButton(text = stringResource(R.string.tv_detail_back), onClick = onBack) },+            modifier = modifier,+        )+        return+    }+    val stage = state.stage+    val busy = stage != null && stage !is InstallStage.Failed+    val shots = app.tvScreenshots.ifEmpty { app.screenshots }+    Box(modifier.fillMaxSize()) {+        TvBackdrop(key = app.packageName) {+            val art = app.featureGraphic ?: shots.firstOrNull()+            if (art != null) {+                AsyncImage(+                    model = art,+                    contentDescription = null,+                    modifier = Modifier.fillMaxSize(),+                    contentScale = ContentScale.Crop,+                )+            } else {+                TvStoreHeroFallback(app = app)+            }+        }+        LazyColumn(+            Modifier.fillMaxSize(),+            verticalArrangement = Arrangement.spacedBy(8.dp),+        ) {+            item("back") {+                TvButton(+                    text = stringResource(R.string.tv_detail_back),+                    onClick = onBack,+                    icon = { IconBack() },+                    modifier = Modifier.padding(+                        start = tvContentStart(),+                        top = 40.dp,+                        bottom = 8.dp,+                    ),+                )+            }+            item("hero") {+                TvStoreDetailHero(+                    app = app,+                    state = state,+                    stage = stage,+                    busy = busy,+                    focusRequester = primaryFocus,+                    onInstall = { onInstall(app) },+                    onOpen = { onOpen(app.packageName) },+                    onUninstall = { onUninstall(app.packageName) },+                    onDismissFailure = { onDismissFailure(app.packageName) },+                    modifier = Modifier.padding(bottom = 24.dp),+                )+            }+            if (busy && stage is InstallStage.Downloading) {+                item("progress") {+                    TvProgressStrip(+                        progress = stage.fraction.coerceIn(0f, 1f),+                        modifier = Modifier.padding(+                            start = tvContentStart(),+                            end = 48.dp,+                            bottom = 8.dp,+                        ),+                    )+                }+            }+            if (stage is InstallStage.Failed) {+                item("failure") {+                    TvStoreDetailFailure(+                        reason = stage.reason,+                        onRetry = {+                            onDismissFailure(app.packageName)+                            onInstall(app)+                        },+                    )+                }+            }+            if (shots.isNotEmpty()) {+                item("screenshots") {+                    TvStoreScreenshotShelf(urls = shots)+                }+            }+            item("body") {+                TvStoreDetailBody(app = app)+            }+            item("bottom") { Spacer(Modifier.height(48.dp)) }+        }+        TvInitialFocus(primaryFocus, app.packageName)+    }+}++/** Hero block: name, developer, source, version/size meta, tier chip, actions + trust card. */+@Composable+private fun TvStoreDetailHero(+    app: UnifiedApp,+    state: TvDetailUiState,+    stage: InstallStage?,+    busy: Boolean,+    focusRequester: FocusRequester,+    onInstall: (UnifiedApp) -> Unit,+    onOpen: (String) -> Unit,+    onUninstall: (String) -> Unit,+    onDismissFailure: (String) -> Unit,+    modifier: Modifier = Modifier,+) {+    val meta = buildList {+        app.versionName?.let { add(it) }+        if (app.sizeBytes > 0) add(formatSize(app.sizeBytes))+        app.categories.firstOrNull()?.let { add(it) }+    }+    Row(+        modifier.padding(start = tvContentStart(), end = 48.dp),+        horizontalArrangement = Arrangement.spacedBy(32.dp),+    ) {+        Column(Modifier.weight(1f)) {+            TvHeroText(+                title = app.name,+                eyebrow = app.tvSourceLabel(),+                meta = meta.ifEmpty { listOf(app.author.orEmpty()) },+                description = when {+                    state.isLoadingDetails -> stringResource(R.string.sync_in_progress)+                    app.summary.isNotBlank() -> app.summary+                    else -> null+                },+                chips = {+                    TvTierBadge(text = app.tvTierLabel())+                    if (app.reproducible) TvTierBadge(text = stringResource(R.string.chip_reproducible))+                    if (app.containsAds) TvTierBadge(text = stringResource(R.string.chip_contains_ads))+                },+                actions = {+                    TvStorePrimaryAction(+                        isInstalled = state.isInstalled,+                        hasUpdate = state.hasUpdate,+                        stage = stage,+                        busy = busy,+                        focusRequester = focusRequester,+                        onInstall = { onInstall(app) },+                        onOpen = { onOpen(app.packageName) },+                    )+                    TvStoreSecondaryActions(+                        isInstalled = state.isInstalled,+                        hasUpdate = state.hasUpdate,+                        busy = busy,+                        onOpen = { onOpen(app.packageName) },+                        onUninstall = { onUninstall(app.packageName) },+                    )+                    if (stage is InstallStage.Failed) {+                        TvButton(+                            text = stringResource(R.string.action_dismiss),+                            onClick = { onDismissFailure(app.packageName) },+                        )+                    }+                },+            )+            if (state.isInstalled && state.installedInfo?.versionName != null && !state.hasUpdate) {+                TvText(+                    text = stringResource(R.string.installed_2, state.installedInfo.versionName),+                    style = MaterialTheme.typography.bodyMedium,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                    modifier = Modifier.padding(top = 8.dp),+                )+            }+            TvStoreVerificationLine(state = state, modifier = Modifier.padding(top = 8.dp))+        }+        TvStoreTrustPanel(app = app, modifier = Modifier.weight(0.85f))+    }+}++/** Open/Uninstall next to the primary action; the primary already covers Open when idle. */+@Composable+private fun TvStoreSecondaryActions(+    isInstalled: Boolean,+    hasUpdate: Boolean,+    busy: Boolean,+    onOpen: () -> Unit,+    onUninstall: () -> Unit,+) {+    if (busy || !isInstalled) return+    if (hasUpdate) {+        // Primary is Update; Open sits beside it like the phone's Update + Open pair.+        TvButton(+            text = stringResource(UiR.string.open),+            onClick = onOpen,+        )+    } else {+        TvButton(+            text = stringResource(R.string.uninstall),+            onClick = onUninstall,+            icon = { IconDelete() },+        )+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetailSections.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetailSections.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetailSections.ktnew file mode 100644index 0000000000..7af6aa7313--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetailSections.kt@@ -0,0 +1,346 @@+package com.vayunmathur.appstore.tv++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.aspectRatio+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableFloatStateOf+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.draw.clip+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.security.TrustProfile+import com.vayunmathur.appstore.data.security.VerificationResult+import com.vayunmathur.appstore.ui.formatCount+import com.vayunmathur.appstore.ui.formatSize+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.image.compose.AsyncImageState+import com.vayunmathur.library.tv.TvAspect+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvMediaCard+import com.vayunmathur.library.tv.TvShelf+import com.vayunmathur.library.tv.tvContentStart++/**+ * Detail-page sections: the security panel, verification line, screenshots, description+ * and facts. Split from [TvStoreDetail] to keep both files under the 350-line limit.+ *+ * The security content comes straight from the phone's model — [TrustProfile] per-source+ * practices and checks plus the last [VerificationResult] — because signature+ * verification is the product and it stays prominent on TV.+ */+@Composable+internal fun TvStoreTrustPanel(app: UnifiedApp, modifier: Modifier = Modifier) {+    val profile = TrustProfile.of(app.source)+    val scheme = MaterialTheme.colorScheme+    Column(+        modifier+            .clip(MaterialTheme.shapes.medium)+            .background(scheme.surface.copy(alpha = 0.85f))+            .padding(20.dp),+        verticalArrangement = Arrangement.spacedBy(10.dp),+    ) {+        Text(+            text = stringResource(R.string.trust_page_title),+            style = MaterialTheme.typography.titleMedium,+            fontWeight = FontWeight.SemiBold,+            color = scheme.onSurface,+        )+        Text(+            text = stringResource(profile.title),+            style = MaterialTheme.typography.titleSmall,+            color = scheme.primary,+        )+        Text(+            text = stringResource(profile.summary),+            style = MaterialTheme.typography.bodyMedium,+            color = scheme.onSurfaceVariant,+        )+        Text(+            text = stringResource(R.string.trust_heading_we_check),+            style = MaterialTheme.typography.labelLarge,+            color = scheme.primary,+        )+        profile.ourChecks.forEach { check ->+            Text(+                text = stringResource(R.string.trust_bullet, stringResource(check)),+                style = MaterialTheme.typography.bodyMedium,+                color = scheme.onSurface.copy(alpha = 0.9f),+            )+        }+        Text(+            text = stringResource(R.string.trust_heading_weaker),+            style = MaterialTheme.typography.labelLarge,+            color = scheme.primary,+        )+        Text(+            text = stringResource(profile.limits),+            style = MaterialTheme.typography.bodyMedium,+            color = scheme.onSurfaceVariant,+        )+    }+}++/** What the last install proved, in the verifier's own words — or the not-yet-checked line. */+@Composable+internal fun TvStoreVerificationLine(state: TvDetailUiState, modifier: Modifier = Modifier) {+    val message = state.verification.toTvMessage()+    if (message == null) {+        // No install attempt yet: the neutral card line, mirroring the phone's trust card.+        Text(+            text = stringResource(R.string.detail_tap_for_trust),+            style = MaterialTheme.typography.bodyMedium,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+            modifier = modifier,+        )+        return+    }+    Text(+        text = message,+        style = MaterialTheme.typography.bodyMedium,+        color = if (state.verification is VerificationResult.Rejected ||+            state.verification is VerificationResult.Unverified+        ) {+            MaterialTheme.colorScheme.error+        } else {+            MaterialTheme.colorScheme.onSurfaceVariant+        },+        modifier = modifier,+    )+}++@Composable+private fun VerificationResult?.toTvMessage(): String? = when (this) {+    is VerificationResult.Rejected ->+        stringResource(R.string.detail_install_blocked, reason)+    is VerificationResult.Verified ->+        stringResource(R.string.detail_checked_on_install, detail)+    is VerificationResult.Unverified ->+        stringResource(R.string.detail_installed_unverified, reason)+    null -> null+}++/** Failed install block with a retry that re-arms the install button. */+@Composable+internal fun TvStoreDetailFailure(reason: String, onRetry: () -> Unit, modifier: Modifier = Modifier) {+    Column(+        modifier.padding(start = tvContentStart(), end = 48.dp),+        verticalArrangement = Arrangement.spacedBy(10.dp),+    ) {+        Text(+            text = stringResource(R.string.stage_failed, reason),+            style = MaterialTheme.typography.bodyLarge,+            color = MaterialTheme.colorScheme.error,+        )+        // Retry is dismiss + install: clearing the stage re-arms the install button,+        // which reports the outcome once via AppMessages.+        TvButton(text = stringResource(R.string.action_check_again), onClick = onRetry)+    }+}++/** TV screenshots where the source publishes a set; landscape cards in a shelf. */+@Composable+internal fun TvStoreScreenshotShelf(urls: List<String>, modifier: Modifier = Modifier) {+    TvShelf(title = stringResource(R.string.tv_detail_screenshots), modifier = modifier) {+        items(urls, key = { it }) { url ->+            // The width has to be stated: AsyncImage draws its bitmap with matchParentSize,+            // which contributes nothing to the measure pass, so an image given only a+            // height resolves to zero wide. Start at 16:9 and switch to the real ratio+            // once the bitmap has been decoded.+            var ratio by remember(url) { mutableFloatStateOf(TvAspect.Landscape) }+            TvMediaCard(+                onClick = {},+                width = 320.dp,+                aspectRatio = ratio,+                image = {+                    AsyncImage(+                        model = url,+                        contentDescription = null,+                        modifier = Modifier.fillMaxWidth().aspectRatio(ratio),+                        contentScale = ContentScale.Fit,+                        onState = { state ->+                            val size = (state as? AsyncImageState.Success)?.painter?.intrinsicSize+                            if (size != null && size.width > 0f && size.height > 0f) {+                                ratio = size.width / size.height+                            }+                        },+                    )+                },+            )+        }+    }+}++/** Description, what's new, compat line, facts, permissions. */+@Composable+internal fun TvStoreDetailBody(app: UnifiedApp, modifier: Modifier = Modifier) {+    Column(+        modifier+            .fillMaxWidth()+            .padding(start = tvContentStart(), end = 48.dp, top = 16.dp),+        verticalArrangement = Arrangement.spacedBy(20.dp),+    ) {+        // TV-compat statement: the app passed the catalogue filter; the line says why.+        TvCompatRow(app = app)+        if (app.description.isNotBlank()) {+            TvStoreDetailBlock(title = stringResource(R.string.tv_detail_about)) {+                var expanded by remember(app.packageName) { mutableStateOf(false) }+                Text(+                    text = app.description,+                    style = MaterialTheme.typography.bodyLarge,+                    color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.9f),+                    maxLines = if (expanded) Int.MAX_VALUE else 5,+                    overflow = TextOverflow.Ellipsis,+                )+                TvButton(+                    text = stringResource(+                        if (expanded) R.string.action_show_less else R.string.action_read_more,+                    ),+                    onClick = { expanded = !expanded },+                    modifier = Modifier.padding(top = 8.dp),+                )+            }+        }+        if (app.whatsNew?.isNotBlank() == true) {+            TvStoreDetailBlock(title = stringResource(R.string.detail_whats_new)) {+                app.updatedOn?.let {+                    Text(+                        text = it,+                        style = MaterialTheme.typography.bodyMedium,+                        color = MaterialTheme.colorScheme.onSurfaceVariant,+                    )+                }+                Text(+                    text = app.whatsNew,+                    style = MaterialTheme.typography.bodyLarge,+                    color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.9f),+                )+            }+        }+        TvStoreDetailFacts(app = app)+        if (app.antiFeatures.isNotEmpty() || app.permissions.isNotEmpty()) {+            TvStoreDetailBlock(title = stringResource(R.string.detail_permissions)) {+                // Anti-features are the honest part of F-Droid listings; flagged, not hidden.+                val lines = app.antiFeatures ++                    app.permissions.map { it.substringAfterLast('.') }+                Text(+                    text = lines.joinToString("\n"),+                    style = MaterialTheme.typography.bodyLarge,+                    color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.9f),+                )+            }+        }+        TvStoreVersionRow(app = app)+    }+}++@Composable+private fun TvStoreDetailBlock(title: String, content: @Composable () -> Unit) {+    Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {+        Text(+            text = title,+            style = MaterialTheme.typography.titleLarge,+            fontWeight = FontWeight.SemiBold,+            color = MaterialTheme.colorScheme.onSurface,+        )+        content()+    }+}++/** Rating, installs, size and content rating, in whatever subset the source published. */+@Composable+private fun TvStoreDetailFacts(app: UnifiedApp) {+    val cells = buildList<Pair<String, String>> {+        app.rating?.let {+            add(stringResource(R.string.fact_rating) to String.format(java.util.Locale.US, "%.1f★", it))+        }+        if (app.installs > 0) add(stringResource(R.string.fact_installs) to formatCount(app.installs))+        if (app.sizeBytes > 0) add(stringResource(R.string.fact_size) to formatSize(app.sizeBytes))+        app.contentRating?.let { add(stringResource(R.string.fact_rated) to it) }+        app.versionName?.let { add(stringResource(R.string.fact_version) to it) }+    }+    if (cells.isEmpty()) return+    Row(+        modifier = Modifier.fillMaxWidth(0.6f),+        horizontalArrangement = Arrangement.SpaceEvenly,+    ) {+        cells.take(4).forEachIndexed { index, (label, value) ->+            if (index > 0) {+                Box(+                    Modifier+                        .padding(horizontal = 16.dp, vertical = 6.dp)+                        .width(1.dp)+                        .height(32.dp)+                        .background(MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.3f)),+                )+            }+            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.weight(1f)) {+                Text(+                    text = value,+                    style = MaterialTheme.typography.bodyLarge,+                    fontWeight = FontWeight.SemiBold,+                    color = MaterialTheme.colorScheme.onSurface,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                )+                Text(+                    text = label,+                    style = MaterialTheme.typography.bodyMedium,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                    maxLines = 1,+                    overflow = TextOverflow.Ellipsis,+                )+            }+        }+    }+}++/** Package, developer, license, target SDK — deliberately last, like the phone. */+@Composable+private fun TvStoreVersionRow(app: UnifiedApp) {+    Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {+        app.author?.let { TvStoreFact(stringResource(R.string.tv_detail_author), it) }+        app.license?.let { TvStoreFact(stringResource(R.string.detail_license), it) }+        app.targetSdk?.let { TvStoreFact(stringResource(R.string.detail_target_sdk), it.toString()) }+        if (app.ratingCount > 0) {+            TvStoreFact(stringResource(R.string.detail_rating_count), formatCount(app.ratingCount))+        }+        TvStoreFact(stringResource(R.string.detail_package), app.packageName)+    }+}++@Composable+private fun TvStoreFact(label: String, value: String) {+    Column(Modifier.fillMaxWidth(0.6f)) {+        Text(+            text = label,+            style = MaterialTheme.typography.bodyMedium,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+        )+        Text(+            text = value,+            style = MaterialTheme.typography.bodyLarge,+            color = MaterialTheme.colorScheme.onSurface,+        )+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreHome.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreHome.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreHome.ktnew file mode 100644index 0000000000..ec54991fcd--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreHome.kt@@ -0,0 +1,290 @@+package com.vayunmathur.appstore.tv++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+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.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.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text as TvText+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.installer.InstallStage+import com.vayunmathur.appstore.ui.formatSize+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.tv.TvBackdrop+import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvHeroText+import com.vayunmathur.library.tv.TvInitialFocus+import com.vayunmathur.library.tv.TvLoading+import com.vayunmathur.library.tv.TvShelf+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconDownload+import com.vayunmathur.library.ui.IconPackage+import com.vayunmathur.library.ui.R as UiR++/**+ * The store front on TV: a featured hero keyed by the focused app, then one shelf per+ * source/section. Rows come from the TV-filtered catalogue the ViewModel already builds;+ * the only TV derivation here is which app the hero shows.+ *+ * The hero shows the first app of the first non-empty shelf and follows focus: moving+ * across any tile swaps the backdrop, name and actions to the focused app. The hero's+ * primary button keeps initial focus so CENTER installs straight away.+ */+@Composable+fun TvStoreHome(+    viewModel: TvStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit,+    modifier: Modifier = Modifier,+) {+    val state by viewModel.home.collectAsState()+    TvStoreHomeScreen(+        state = state,+        onInstall = viewModel::install,+        onOpen = viewModel::openApp,+        onAppClick = onAppClick,+        modifier = modifier,+    )+}++@Composable+internal fun TvStoreHomeScreen(+    state: TvHomeUiState,+    modifier: Modifier = Modifier,+    onInstall: (UnifiedApp) -> Unit = {},+    onOpen: (String) -> Unit = {},+    onAppClick: (UnifiedApp) -> Unit = {},+) {+    val primaryFocus = remember { FocusRequester() }+    var heroApp by remember { mutableStateOf<UnifiedApp?>(null) }+    val sections = state.sections+    val shownHero = heroApp?.takeIf { hero -> sections.any { s -> s.apps.any { it.packageName == hero.packageName } } }+        ?: sections.firstOrNull()?.apps?.firstOrNull()+    // Claim the hero as soon as sections arrive, so the first frame has a backdrop.+    LaunchedEffect(shownHero?.packageName) {+        if (heroApp == null && shownHero != null) heroApp = shownHero+    }++    when {+        state.isLoading && sections.isEmpty() -> TvLoading(label = stringResource(R.string.sync_in_progress))+        sections.isEmpty() -> TvEmptyState(+            title = stringResource(R.string.home_empty_title),+            body = stringResource(R.string.home_empty_message),+            icon = { IconPackage() },+        )+        else -> Box(modifier.fillMaxSize()) {+            TvBackdrop(key = shownHero?.packageName) { _ ->+                val art = shownHero?.tvScreenshots?.firstOrNull()+                    ?: shownHero?.screenshots?.firstOrNull()+                    ?: shownHero?.featureGraphic+                if (art != null) {+                    AsyncImage(+                        model = art,+                        contentDescription = null,+                        modifier = Modifier.fillMaxSize(),+                        contentScale = ContentScale.Crop,+                    )+                } else if (shownHero != null) {+                    TvStoreHeroFallback(app = shownHero)+                }+            }+            LazyColumn(+                Modifier.fillMaxSize(),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {+                if (shownHero != null) {+                    item("hero") {+                        TvStoreHero(+                            app = shownHero,+                            state = state,+                            focusRequester = primaryFocus,+                            onInstall = onInstall,+                            onOpen = onOpen,+                            onDetails = { onAppClick(shownHero) },+                            modifier = Modifier.padding(top = 56.dp, bottom = 32.dp),+                        )+                    }+                }+                if (state.statusMessage.isNotBlank()) {+                    item("status") {+                        TvStoreStatusLine(+                            message = state.statusMessage,+                            isLoading = state.isLoading,+                        )+                    }+                }+                items(sections, key = { it.id }) { section ->+                    TvStoreSectionShelf(+                        section = section,+                        state = state,+                        onAppClick = onAppClick,+                        onHeroFocus = { heroApp = it },+                    )+                }+                item("bottom") { Spacer(Modifier.height(48.dp)) }+            }+            // Unkeyed: runs once. Keying on the hero would yank focus back to the hero+            // button every time focus moves across tiles and the hero follows.+            TvInitialFocus(primaryFocus)+        }+    }+}++/** Featured hero: backdrop art, name, source eyebrow, tier chip, primary action + Details. */+@Composable+private fun TvStoreHero(+    app: UnifiedApp,+    state: TvHomeUiState,+    focusRequester: FocusRequester,+    onInstall: (UnifiedApp) -> Unit,+    onOpen: (String) -> Unit,+    onDetails: () -> Unit,+    modifier: Modifier = Modifier,+) {+    val stage = state.stages[app.packageName]+    val busy = stage != null && stage !is InstallStage.Failed+    val installedVersion = state.installedVersions[app.packageName]+    val isInstalled = installedVersion != null+    val hasUpdate = isInstalled && app.versionCode > (installedVersion ?: 0L)+    val meta = buildList {+        app.versionName?.let { add(it) }+        if (app.sizeBytes > 0) add(formatSize(app.sizeBytes))+        app.categories.firstOrNull()?.let { add(it) }+    }+    Column(modifier.padding(start = tvContentStart())) {+        TvHeroText(+            title = app.name,+            eyebrow = app.tvSourceLabel(),+            meta = meta,+            description = app.summary.ifBlank { app.description }.ifBlank { null },+            chips = { TvTierBadge(text = app.tvTierLabel()) },+            actions = {+                TvStorePrimaryAction(+                    isInstalled = isInstalled,+                    hasUpdate = hasUpdate,+                    stage = stage,+                    busy = busy,+                    focusRequester = focusRequester,+                    onInstall = { onInstall(app) },+                    onOpen = { onOpen(app.packageName) },+                )+                TvButton(+                    text = stringResource(R.string.tv_detail_open),+                    onClick = onDetails,+                )+            },+        )+    }+}++/** One primary (accent) action per screen: Install / Update / Open / the live stage. */+@Composable+internal fun TvStorePrimaryAction(+    isInstalled: Boolean,+    hasUpdate: Boolean,+    stage: InstallStage?,+    busy: Boolean,+    modifier: Modifier = Modifier,+    focusRequester: FocusRequester? = null,+    onInstall: () -> Unit = {},+    onOpen: () -> Unit = {},+) {+    val withFocus = if (focusRequester != null) {+        Modifier.focusRequester(focusRequester)+    } else {+        Modifier+    }+    when {+        busy -> TvButton(+            text = stage!!.tvStageLabel(),+            onClick = {},+            enabled = false,+            modifier = modifier.then(withFocus),+        )+        hasUpdate || !isInstalled -> TvButton(+            text = stringResource(+                if (hasUpdate || isInstalled) R.string.action_update else R.string.action_install,+            ),+            onClick = onInstall,+            primary = true,+            icon = { IconDownload() },+            modifier = modifier.then(withFocus),+        )+        else -> TvButton(+            text = stringResource(UiR.string.open),+            onClick = onOpen,+            primary = true,+            modifier = modifier.then(withFocus),+        )+    }+}++/** One titled shelf of app tiles; focusing a tile moves the hero to it. */+@Composable+private fun TvStoreSectionShelf(+    section: TvSection,+    state: TvHomeUiState,+    onAppClick: (UnifiedApp) -> Unit,+    onHeroFocus: (UnifiedApp) -> Unit,+    modifier: Modifier = Modifier,+) {+    TvShelf(title = section.title, modifier = modifier) {+        items(section.apps, key = { it.packageName }) { app ->+            val installed = app.packageName in state.installedPackages+            val installedVersion = state.installedVersions[app.packageName]+            val hasUpdate = installedVersion != null && app.versionCode > installedVersion+            TvStoreAppTile(+                app = app,+                onClick = { onAppClick(app) },+                badge = tvTileBadge(installed, hasUpdate),+                progress = state.stages[app.packageName]?.downloadFraction(),+                onFocus = { onHeroFocus(app) },+            )+        }+    }+}++/** Transient status line under the hero, e.g. what the sync is currently fetching. */+@Composable+private fun TvStoreStatusLine(message: String, isLoading: Boolean, modifier: Modifier = Modifier) {+    Column(+        modifier+            .padding(+                start = tvContentStart(),+                end = 48.dp,+                top = 4.dp,+                bottom = 12.dp,+            ),+        horizontalAlignment = Alignment.Start,+    ) {+        TvText(+            text = if (message.isBlank() && isLoading) {+                stringResource(R.string.sync_in_progress)+            } else {+                message+            },+            style = MaterialTheme.typography.bodyMedium,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+        )+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibrary.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibrary.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibrary.ktnew file mode 100644index 0000000000..5bcc01c2af--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibrary.kt@@ -0,0 +1,113 @@+package com.vayunmathur.appstore.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.LazyVerticalGrid+import androidx.compose.foundation.lazy.grid.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.util.SourceFilter+import com.vayunmathur.library.tv.TvChip+import com.vayunmathur.library.tv.TvDimens+import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.tvContentPadding+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconPackage++/**+ * Every installed app the store can attribute to a source, grouped by source chip.+ *+ * The header and chips sit above the grid in a Column — focus moves UP from the first+ * row straight into them — and the one [LazyVerticalGrid] owns scrolling with+ * [tvContentPadding]. Uninstall lives only on an app's own page: a delete action next+ * to every tile in a long grid is too easy to land on with a D-pad. Appearing on this+ * destination refreshes the device's installed set, so an install that landed while+ * browsing shows up.+ */+@Composable+fun TvStoreLibrary(+    viewModel: TvStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit,+    modifier: Modifier = Modifier,+) {+    val state by viewModel.library.collectAsState()+    LaunchedEffect(Unit) { viewModel.refreshInstalled() }+    TvStoreLibraryScreen(+        state = state,+        onFilterChange = viewModel::setLibraryFilter,+        onAppClick = onAppClick,+        modifier = modifier,+    )+}++@Composable+internal fun TvStoreLibraryScreen(+    state: TvLibraryUiState,+    modifier: Modifier = Modifier,+    onFilterChange: (SourceFilter) -> Unit = {},+    onAppClick: (UnifiedApp) -> Unit = {},+) {+    Column(modifier.fillMaxSize()) {+        TvScreenHeader(title = stringResource(R.string.nav_library))+        Row(+            Modifier+                .fillMaxWidth()+                .padding(+                    start = tvContentStart(),+                    end = TvDimens.SafeHorizontal,+                    bottom = 12.dp,+                ),+            horizontalArrangement = Arrangement.spacedBy(10.dp),+        ) {+            for (entry in SourceFilter.entries) {+                val count = state.counts[entry] ?: 0+                TvChip(+                    label = stringResource(+                        R.string.filter_with_count,+                        stringResource(entry.tvLabelRes()),+                        count,+                    ),+                    selected = state.filter == entry,+                    onClick = { onFilterChange(entry) },+                )+            }+        }+        if (state.apps.isEmpty()) {+            TvEmptyState(+                title = stringResource(R.string.library_empty_title),+                body = stringResource(R.string.library_empty_message),+                icon = { IconPackage() },+            )+        } else {+            LazyVerticalGrid(+                columns = GridCells.Fixed(2),+                modifier = Modifier.fillMaxSize(),+                contentPadding = tvContentPadding(bottom = 48.dp),+                horizontalArrangement = Arrangement.spacedBy(20.dp),+                verticalArrangement = Arrangement.spacedBy(16.dp),+            ) {+                items(state.apps, key = { it.packageName }) { app ->+                    TvStoreAppRow(+                        app = app,+                        onClick = { onAppClick(app) },+                        supporting = app.versionName,+                        badge = stringResource(R.string.installed),+                    )+                }+            }+        }+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSearch.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSearch.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSearch.ktnew file mode 100644index 0000000000..fd69cb9135--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSearch.kt@@ -0,0 +1,177 @@+package com.vayunmathur.appstore.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.LazyVerticalGrid+import androidx.compose.foundation.lazy.grid.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.ImeAction+import androidx.compose.ui.unit.dp+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.util.SourceFilter+import com.vayunmathur.library.tv.TvChip+import com.vayunmathur.library.tv.TvDimens+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.TvTextField+import com.vayunmathur.library.tv.tvContentPadding+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconPackage+import com.vayunmathur.library.ui.IconSearch++/**+ * The TV search hub: a D-pad text field, source-filter chips, and the local-then-remote+ * merged results as a grid of row cards.+ *+ * The header, field and chips sit above the results grid in a Column — focus moves UP+ * from the first result row straight into them — and the one [LazyVerticalGrid] owns+ * results scrolling with [tvContentPadding]. The keyboard opens only on an explicit+ * CENTER press on the field ([TvTextField]); selecting the Search rail destination does+ * not start editing. Results arrive in two waves — the on-disk catalogues answer first,+ * the network merges in — so a searching line sits over content rather than over a+ * spinner. A Play refusal (e.g. 429) is said above the results, never a silent gap.+ */+@Composable+fun TvStoreSearch(+    viewModel: TvStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit,+    /** True when the user navigated here explicitly: start with the field editing. */+    startEditing: Boolean = false,+    modifier: Modifier = Modifier,+) {+    val state by viewModel.search.collectAsState()+    TvStoreSearchScreen(+        state = state,+        startEditing = startEditing,+        onQueryChange = viewModel::setSearch,+        onFilterChange = viewModel::setSearchFilter,+        onAppClick = onAppClick,+        modifier = modifier,+    )+}++@Composable+internal fun TvStoreSearchScreen(+    state: TvSearchUiState,+    modifier: Modifier = Modifier,+    startEditing: Boolean = false,+    onQueryChange: (String) -> Unit = {},+    onFilterChange: (SourceFilter) -> Unit = {},+    onAppClick: (UnifiedApp) -> Unit = {},+) {+    val fieldFocus = remember(state.query) { FocusRequester() }+    // Play's half refused (429): say so above the results rather than silently+    // showing a list that is missing half its sources.+    val playError = state.playError.takeIf { it.isNotBlank() }+    Column(modifier.fillMaxSize()) {+        TvScreenHeader(+            title = stringResource(R.string.nav_search),+            subtitle = if (state.isSearching && state.hasSearched) {+                stringResource(R.string.tv_searching)+            } else {+                null+            },+        )+        TvTextField(+            value = state.query,+            onValueChange = onQueryChange,+            placeholder = stringResource(R.string.search_placeholder),+            leading = { IconSearch() },+            imeAction = ImeAction.Search,+            focusRequester = fieldFocus,+            startEditing = startEditing && state.query.isBlank(),+            modifier = Modifier+                .fillMaxWidth()+                .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal, bottom = 8.dp),+        )+        TvInitialFocus(fieldFocus)+        TvStoreSourceFilters(+            filter = state.filter,+            onFilterChange = onFilterChange,+            modifier = Modifier.padding(bottom = 12.dp),+        )+        if (playError != null) {+            TvStoreNoticeLine(text = playError, isError = true)+        }+        when {+            state.query.isBlank() -> TvEmptyState(+                title = stringResource(R.string.search_prompt_title),+                body = stringResource(R.string.tv_search_prompt_tv),+                icon = { IconSearch() },+            )+            state.results.isEmpty() && (state.isSearching || !state.hasSearched) ->+                TvLoading(label = stringResource(R.string.sync_in_progress))+            state.results.isEmpty() -> TvEmptyState(+                title = stringResource(R.string.search_no_results_title, state.query),+                body = stringResource(R.string.search_no_results_message),+                icon = { IconPackage() },+            )+            else -> LazyVerticalGrid(+                columns = GridCells.Fixed(2),+                modifier = Modifier.fillMaxSize(),+                contentPadding = tvContentPadding(bottom = 48.dp),+                horizontalArrangement = Arrangement.spacedBy(20.dp),+                verticalArrangement = Arrangement.spacedBy(16.dp),+            ) {+                items(state.results, key = { it.packageName }) { app ->+                    val summary = app.summary.ifBlank { app.author.orEmpty() }+                    TvStoreAppRow(+                        app = app,+                        onClick = { onAppClick(app) },+                        supporting = summary,+                        badge = when {+                            app.packageName in state.installedPackages -> stringResource(R.string.installed)+                            else -> null+                        },+                    )+                }+            }+        }+    }+}++/** Source-filter chips as a focusable D-pad row; LEFT/RIGHT moves, DOWN drops to results. */+@Composable+private fun TvStoreSourceFilters(+    filter: SourceFilter,+    onFilterChange: (SourceFilter) -> Unit,+    modifier: Modifier = Modifier,+) {+    Row(+        modifier+            .fillMaxWidth()+            .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal),+        horizontalArrangement = Arrangement.spacedBy(10.dp),+    ) {+        for (entry in SourceFilter.entries) {+            TvChip(+                label = stringResource(entry.tvLabelRes()),+                selected = filter == entry,+                onClick = { onFilterChange(entry) },+            )+        }+    }+}++internal fun SourceFilter.tvLabelRes(): Int = when (this) {+    SourceFilter.ALL -> R.string.filter_all+    SourceFilter.MODERN_APPS -> R.string.source_chip_modern_apps+    SourceFilter.PROPRIETARY -> R.string.source_chip_proprietary+    SourceFilter.FDROID -> R.string.source_chip_fdroid+    SourceFilter.PLAYSTORE -> R.string.source_chip_play+    SourceFilter.ACCRESCENT -> R.string.source_chip_accrescent+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreTiles.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreTiles.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreTiles.ktnew file mode 100644index 0000000000..11c9164259--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreTiles.kt@@ -0,0 +1,235 @@+package com.vayunmathur.appstore.tv++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxScope+import androidx.compose.foundation.layout.BoxWithConstraints+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Brush+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text as TvText+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.installer.InstallStage+import com.vayunmathur.appstore.data.security.TrustProfile+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.tv.TvAspect+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconTv+import com.vayunmathur.library.tv.TvBadge+import com.vayunmathur.library.tv.TvMediaCard+import com.vayunmathur.library.tv.TvRowCard++/**+ * The one app tile for every TV shelf: square icon art centred on a subtle surface,+ * name plus source underneath, an Installed/Update badge and a download progress strip.+ *+ * One tile everywhere so a shelf, the library grid and search all read the same from+ * the couch. The row-card sibling is [TvStoreAppRow].+ */+@Composable+fun TvStoreAppTile(+    app: UnifiedApp,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+    width: Dp = 200.dp,+    badge: String? = null,+    progress: Float? = null,+    onFocus: (() -> Unit)? = null,+) {+    TvMediaCard(+        onClick = onClick,+        modifier = modifier,+        width = width,+        aspectRatio = TvAspect.Square,+        title = app.name,+        subtitle = app.tvSourceLabel(),+        badge = badge,+        progress = progress,+        onFocus = onFocus,+        image = {+            Box(+                Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surface),+                contentAlignment = Alignment.Center,+            ) {+                TvStoreAppArt(app = app, size = width / 2)+            }+        },+    )+}++/**+ * One app as a horizontal row card: icon, name, source-plus-tier, summary. Fills whatever+ * width the caller gives it — a list column or one grid cell — because [TvRowCard] takes+ * a fixed width and a row that only fills 380dp of an 800dp cell reads as broken.+ */+@Composable+internal fun TvStoreAppRow(+    app: UnifiedApp,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+    supporting: String? = null,+    badge: String? = null,+    trailing: (@Composable () -> Unit)? = null,+    onFocus: (() -> Unit)? = null,+) {+    val subtitle = buildString {+        append(app.tvSourceLabel())+        append("  ·  ")+        append(stringResource(TrustProfile.of(app.source).title))+        if (badge != null) {+            append("  ·  ")+            append(badge)+        }+    }+    BoxWithConstraints(modifier.fillMaxWidth()) {+        TvRowCard(+            title = app.name,+            onClick = onClick,+            width = maxWidth,+            subtitle = subtitle,+            supporting = supporting?.takeIf { it.isNotBlank() },+            leading = { TvStoreAppArt(app = app, size = 56.dp) },+            leadingSize = 64.dp,+            trailing = trailing,+            onFocus = onFocus,+        )+    }+}++/** Icon art with the phone's fallback chain minus PackageManager: URL, else an initial. */+@Composable+internal fun BoxScope.TvStoreAppArt(app: UnifiedApp, size: Dp) {+    val shape = MaterialTheme.shapes.medium+    if (app.iconUrl != null) {+        AsyncImage(+            model = app.iconUrl,+            contentDescription = null,+            modifier = Modifier.size(size).clip(shape),+            contentScale = ContentScale.Crop,+        )+    } else {+        Box(+            Modifier.size(size).clip(shape).background(MaterialTheme.colorScheme.surfaceVariant),+            contentAlignment = Alignment.Center,+        ) {+            TvText(+                text = app.name.take(1).uppercase(),+                style = MaterialTheme.typography.headlineMedium,+                color = MaterialTheme.colorScheme.onSurfaceVariant,+            )+        }+    }+}++/**+ * Hero/backdrop fallback when the listing publishes no image: the accent tinted down into+ * the background with the app's art large on top, so the hero is never a black hole.+ */+@Composable+internal fun BoxScope.TvStoreHeroFallback(app: UnifiedApp) {+    val scheme = MaterialTheme.colorScheme+    Box(+        Modifier.fillMaxSize().background(+            Brush.linearGradient(+                0f to scheme.primaryContainer,+                0.6f to scheme.surface,+                1f to scheme.background,+            ),+        ),+        contentAlignment = Alignment.Center,+    ) {+        TvStoreAppArt(app = app, size = 144.dp)+    }+}++/** Where the app came from. Purely factual — the sources are not ranked. */+@Composable+internal fun UnifiedApp.tvSourceLabel(): String = stringResource(+    when (source) {+        AppSource.MODERN_APPS -> R.string.source_chip_modern_apps+        AppSource.FDROID -> R.string.source_chip_fdroid+        AppSource.PLAYSTORE -> R.string.source_chip_play+        AppSource.ACCRESCENT -> R.string.source_chip_accrescent+        AppSource.PROPRIETARY -> R.string.source_chip_proprietary+    },+)++/** Short security-tier chip text: the source's trust profile title. */+@Composable+internal fun UnifiedApp.tvTierLabel(): String =+    stringResource(TrustProfile.of(source).title)++/** The install stage as a one-line label, mirroring the phone's stageLabel. */+@Composable+internal fun InstallStage.tvStageLabel(): String = when (this) {+    InstallStage.Preparing -> stringResource(R.string.stage_preparing)+    is InstallStage.Downloading -> stringResource(R.string.stage_downloading, (fraction * 100).toInt())+    InstallStage.Verifying -> stringResource(R.string.stage_verifying)+    InstallStage.Installing -> stringResource(R.string.stage_installing)+    is InstallStage.Failed -> stringResource(R.string.stage_failed, reason)+}++/** 0..1 download fraction for card progress strips, null for indeterminate stages. */+internal fun InstallStage.downloadFraction(): Float? =+    (this as? InstallStage.Downloading)?.fraction?.coerceIn(0f, 1f)++/** Shelf-tile badge: an available update outranks the installed mark. */+@Composable+internal fun tvTileBadge(isInstalled: Boolean, hasUpdate: Boolean): String? = when {+    hasUpdate -> stringResource(R.string.action_update)+    isInstalled -> stringResource(R.string.installed)+    else -> null+}++/** Small pill for the tier chip row on heroes and detail pages. */+@Composable+internal fun TvTierBadge(text: String, modifier: Modifier = Modifier) {+    TvBadge(text = text, modifier = modifier)+}++/** Single-line notice under a screen header: Play errors, rate limits. Red when an error. */+@Composable+internal fun TvStoreNoticeLine(text: String, isError: Boolean, modifier: Modifier = Modifier) {+    val scheme = MaterialTheme.colorScheme+    TvText(+        text = text,+        style = MaterialTheme.typography.bodyMedium,+        color = if (isError) scheme.error else scheme.onSurfaceVariant,+        modifier = modifier.padding(start = tvContentStart(), end = 48.dp, bottom = 8.dp),+    )+}++/** TV-compat statement: the app passed the catalogue filter; the line says why. */+@Composable+internal fun TvCompatRow(app: UnifiedApp, modifier: Modifier = Modifier) {+    Row(+        modifier = modifier,+        verticalAlignment = Alignment.CenterVertically,+    ) {+        IconTv(tint = MaterialTheme.colorScheme.primary)+        Spacer(Modifier.size(8.dp))+        TvText(+            text = stringResource(+                if (app.tvCompatible == true) R.string.tv_compat_declared+                else R.string.tv_compat_unverified,+            ),+            style = MaterialTheme.typography.bodyMedium,+            color = MaterialTheme.colorScheme.onSurfaceVariant,+        )+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUiState.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUiState.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUiState.ktnew file mode 100644index 0000000000..ad5a346e51--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUiState.kt@@ -0,0 +1,84 @@+package com.vayunmathur.appstore.tv++import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.InstalledInfo+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.installer.InstallStage+import com.vayunmathur.appstore.data.security.VerificationResult+import com.vayunmathur.appstore.util.SourceFilter++/** One titled row on the TV browse screen. */+data class TvSection(+    val id: String,+    val title: String,+    val apps: List<UnifiedApp>,+)++/** Everything the TV browse screen draws. */+data class TvHomeUiState(+    val sections: List<TvSection> = emptyList(),+    val isLoading: Boolean = false,+    val statusMessage: String = "",+    val installedPackages: Set<String> = emptySet(),+    /** Installed version code per package, so the hero can offer Update vs Open. */+    val installedVersions: Map<String, Long> = emptyMap(),+    val stages: Map<String, InstallStage> = emptyMap(),+)++/** Everything the TV library (installed apps) screen draws. */+data class TvLibraryUiState(+    val apps: List<UnifiedApp> = emptyList(),+    val filter: SourceFilter = SourceFilter.ALL,+    val counts: Map<SourceFilter, Int> = emptyMap(),+)++internal data class TvLibraryInputs(+    val filter: SourceFilter = SourceFilter.ALL,+    val playPackages: Set<String> = emptySet(),+    val accrescentPackages: Set<String> = emptySet(),+    val enabled: Set<AppSource> = emptySet(),+)++/** Everything the TV detail screen draws. */+data class TvDetailUiState(+    val app: UnifiedApp? = null,+    val installedInfo: InstalledInfo? = null,+    val stage: InstallStage? = null,+    val verification: VerificationResult? = null,+    /** True while richer Play/Accrescent details are being fetched over the network. */+    val isLoadingDetails: Boolean = false,+) {+    val isInstalled: Boolean get() = installedInfo != null++    val hasUpdate: Boolean+        get() = installedInfo != null && (app?.versionCode ?: 0L) > installedInfo.versionCode+}++/** Everything the TV search hub draws. Same shape as the phone's `SearchUiState`. */+data class TvSearchUiState(+    val query: String = "",+    val results: List<UnifiedApp> = emptyList(),+    val filter: SourceFilter = SourceFilter.ALL,+    val isSearching: Boolean = false,+    /** True once a search has run for [query], so "no results" can be told from "not yet". */+    val hasSearched: Boolean = false,+    /**+     * Play's half failed (e.g. rate-limited) while the offline half answered. Blank when+     * Play answered or was never asked, so the list alone is the whole story.+     */+    val playError: String = "",+    val installedPackages: Set<String> = emptySet(),+    val stages: Map<String, InstallStage> = emptyMap(),+)++/** Everything the TV updates hub draws. Same shape as the phone's `UpdatesUiState`. */+data class TvUpdatesUiState(+    val updates: List<UnifiedApp> = emptyList(),+    /** Currently-installed info per package, so the row can show old → new versions. */+    val installedInfos: Map<String, InstalledInfo> = emptyMap(),+    val stages: Map<String, InstallStage> = emptyMap(),+    val isChecking: Boolean = false,+    /** ms since epoch of the last completed check, 0 if never. */+    val lastCheckedAt: Long = 0L,+    val statusMessage: String = "",+)
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUpdates.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUpdates.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUpdates.ktnew file mode 100644index 0000000000..b566992e30--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUpdates.kt@@ -0,0 +1,218 @@+package com.vayunmathur.appstore.tv++import android.text.format.DateUtils+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Modifier+import androidx.compose.ui.focus.FocusRequester+import androidx.compose.ui.focus.focusRequester+import androidx.compose.ui.res.pluralStringResource+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.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.installer.InstallStage+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.TvScreenHeader+import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconCheck+import com.vayunmathur.library.ui.IconDownload+import com.vayunmathur.library.ui.IconRefresh++/**+ * The TV updates hub: pending updates with old → new version deltas, per-app update+ * buttons with live progress, and an "Update all" primary action in the header.+ *+ * Mirrors the phone's UpdatesPage: opening the destination is the request, so the first+ * visit kicks off a check. No pull-to-refresh — a TV has no touch — so a check button+ * sits next to Update all. Failures of an update-all run surface once via AppMessages+ * (see [TvStoreViewModel.updateAll]), not per row.+ */+@Composable+fun TvStoreUpdates(+    viewModel: TvStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit,+    modifier: Modifier = Modifier,+) {+    val state by viewModel.updatesUi.collectAsState()+    // Opening the tab is the request: the phone made the user tap "Sync F-Droid" then+    // "Check Play" by hand, which nobody remembers to do.+    LaunchedEffect(Unit) {+        if (state.lastCheckedAt == 0L) viewModel.checkForUpdates()+    }+    TvStoreUpdatesScreen(+        state = state,+        onCheckForUpdates = viewModel::checkForUpdates,+        onUpdateAll = viewModel::updateAll,+        onInstall = viewModel::install,+        onAppClick = onAppClick,+        modifier = modifier,+    )+}++@Composable+internal fun TvStoreUpdatesScreen(+    state: TvUpdatesUiState,+    modifier: Modifier = Modifier,+    onCheckForUpdates: () -> Unit = {},+    onUpdateAll: () -> Unit = {},+    onInstall: (UnifiedApp) -> Unit = {},+    onAppClick: (UnifiedApp) -> Unit = {},+) {+    val primaryFocus = remember { FocusRequester() }+    val anyInstalling = state.stages.values.any { it !is InstallStage.Failed }+    // @Composable string resolution hoisted: LazyColumn trailing lambdas are not+    // @Composable scopes for non-local calls — plain values are used below.+    val status = state.statusMessage.takeIf { it.isNotBlank() }+        ?: state.lastCheckedAt.takeIf { it > 0 }?.let {+            stringResource(+                R.string.updates_last_checked,+                DateUtils.getRelativeTimeSpanString(+                    it,+                    System.currentTimeMillis(),+                    DateUtils.MINUTE_IN_MILLIS,+                ),+            )+        }+    val countLabel = pluralStringResource(R.plurals.updates_count, state.updates.size, state.updates.size)+    // Unkeyed: runs once per visit. Keying on the count would yank focus back to+    // "Update all" every time a check completes or an update installs and drops off.+    TvInitialFocus(primaryFocus)+    LazyColumn(+        modifier = modifier.fillMaxSize(),+        contentPadding = PaddingValues(bottom = 48.dp),+        verticalArrangement = Arrangement.spacedBy(4.dp),+    ) {+        item("header") {+            TvScreenHeader(+                title = stringResource(R.string.nav_updates),+                subtitle = status,+                actions = {+                    if (state.updates.isNotEmpty()) {+                        TvButton(+                            text = stringResource(R.string.update_all, state.updates.size),+                            onClick = onUpdateAll,+                            primary = true,+                            enabled = !anyInstalling,+                            icon = { IconDownload() },+                            modifier = Modifier.focusRequester(primaryFocus),+                        )+                    }+                    TvButton(+                        text = if (state.isChecking) {+                            stringResource(R.string.updates_checking)+                        } else {+                            stringResource(R.string.action_check_again)+                        },+                        onClick = onCheckForUpdates,+                        enabled = !state.isChecking,+                        icon = { IconRefresh() },+                    )+                },+            )+        }+        if (state.updates.isEmpty() && !state.isChecking) {+            item("empty") {+                TvEmptyState(+                    title = stringResource(R.string.all_apps_up_to_date),+                    body = stringResource(R.string.updates_empty_message),+                    icon = { IconCheck() },+                )+            }+        } else {+            item("count") {+                Text(+                    text = if (state.isChecking && state.updates.isEmpty()) {+                        stringResource(R.string.updates_checking)+                    } else {+                        countLabel+                    },+                    style = MaterialTheme.typography.titleMedium,+                    color = MaterialTheme.colorScheme.onSurface,+                    modifier = Modifier.padding(+                        start = tvContentStart(),+                        end = 48.dp,+                        bottom = 8.dp,+                    ),+                )+            }+            items(state.updates, key = { it.packageName }) { app ->+                val installed = state.installedInfos[app.packageName]+                val old = installed?.let { info ->+                    info.versionName?.let { "$it (${info.versionCode})" }+                        ?: info.versionCode.toString()+                }+                val new = app.versionName?.let { "$it (${app.versionCode})" }+                    ?: app.versionCode.toString()+                val versionLabel = old?.let { stringResource(R.string.version_update, it, new) }+                TvStoreUpdateRow(+                    app = app,+                    versionLabel = versionLabel,+                    stage = state.stages[app.packageName],+                    onUpdate = { onInstall(app) },+                    onClick = { onAppClick(app) },+                    modifier = Modifier.padding(start = tvContentStart(), end = 48.dp, bottom = 12.dp),+                )+            }+        }+    }+}++/** One pending update: icon, name, old → new delta, progress, and an update action. */+@Composable+private fun TvStoreUpdateRow(+    app: UnifiedApp,+    versionLabel: String?,+    stage: InstallStage?,+    onUpdate: () -> Unit,+    onClick: () -> Unit,+    modifier: Modifier = Modifier,+) {+    val busy = stage != null && stage !is InstallStage.Failed+    Column(modifier.fillMaxWidth()) {+        TvStoreAppRow(+            app = app,+            onClick = onClick,+            supporting = versionLabel,+            badge = if (stage is InstallStage.Failed) {+                stringResource(R.string.stage_failed, stage.reason)+            } else {+                null+            },+            trailing = {+                TvButton(+                    text = if (busy) {+                        stage.tvStageLabel()+                    } else {+                        stringResource(R.string.action_update)+                    },+                    onClick = onUpdate,+                    primary = !busy,+                    enabled = !busy,+                )+            },+        )+        if (stage is InstallStage.Downloading) {+            TvProgressStrip(+                progress = stage.fraction.coerceIn(0f, 1f),+                modifier = Modifier.padding(top = 6.dp),+            )+        }+    }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.ktindex b9ac86f85f..ca51cafa8b 100644--- a/appstore/src/main/java/com/vayunmathur/apps

Diff truncated.