appstore: dense TV grids with full-info cards, two-pane detail
- Commit
701b2490e973bc1144490a7804fd794b8d4e0d56- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-26 01:03 UTC (1 month ago)
- Parents
987bcec
Diff
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 85a31b98a8..7890d653e1 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvMainActivity.kt@@ -1,9 +1,5 @@ package com.vayunmathur.appstore.tv -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@@ -11,13 +7,8 @@ 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.Text import com.vayunmathur.appstore.R import com.vayunmathur.appstore.data.AppStoreDatabaseRepository import com.vayunmathur.appstore.data.UnifiedApp@@ -26,12 +17,11 @@ 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.IconProvider 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@@ -40,19 +30,23 @@ import com.vayunmathur.library.util.rememberNavBackStack import kotlinx.serialization.Serializable /**- * TV-only destinations: the rail tabs plus one pushed detail.+ * TV-only destinations: the rail tabs plus pushed browse and detail pages. * * 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.+ * updates, library and sources 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 rail: home, search, updates, library. D-pad only, no swipe. */+ /** The rail: home, search, updates, library, sources. D-pad only, no swipe. */ @Serializable data object Main : TvStoreRoute + /** One home section's full catalogue, pushed over the rail. */+ @Serializable+ data class Browse(val sectionId: String) : TvStoreRoute+ /** One app's page, pushed over the rail. */ @Serializable data class Detail(val packageName: String) : TvStoreRoute@@ -86,7 +80,9 @@ class TvMainActivity : MaActivity() { @Composable override fun Content() { val repository = remember { AppStoreDatabaseRepository.get(this) }- val factory = remember { TvStoreViewModelFactory(this, repository.database) }+ val factory = remember {+ TvStoreViewModelFactory(this, repository.database)+ } val viewModel: TvStoreViewModel = viewModel(factory = factory) TvStoreNavigation(viewModel = viewModel) }@@ -95,9 +91,10 @@ class TvMainActivity : MaActivity() { /** * The TV navigation host: [rememberNavBackStack] + [MainNavigation] over [TvStoreRoute]. *- * The detail destination reads the selection the rail already set via- * [TvStoreViewModel.selectApp] — popping clears it, so BACK from detail always lands on- * the destination that opened it with no stale selection behind it.+ * The browse and detail destinations read the selection the rail already set via+ * [TvStoreViewModel.openBrowse]/[TvStoreViewModel.selectApp] — popping clears them,+ * so BACK from either always lands on the destination that opened it with no stale+ * selection behind it. */ @Composable private fun TvStoreNavigation(viewModel: TvStoreViewModel) {@@ -106,6 +103,19 @@ private fun TvStoreNavigation(viewModel: TvStoreViewModel) { entry<TvStoreRoute.Main> { TvStoreRail(backStack = backStack, viewModel = viewModel) }+ entry<TvStoreRoute.Browse> {+ TvStoreBrowse(+ viewModel = viewModel,+ onAppClick = { app ->+ viewModel.selectApp(app)+ backStack.add(TvStoreRoute.Detail(app.packageName))+ },+ onBack = {+ backStack.pop()+ viewModel.clearBrowse()+ },+ )+ } entry<TvStoreRoute.Detail> { TvStoreDetail( viewModel = viewModel,@@ -123,10 +133,12 @@ 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+private const val TV_DEST_SOURCES = 4 /**- * The store shell: a [TvAppFrame] rail (Home, Search, Updates with count, Library) with- * the store brand, and the selected destination's screen beside it.+ * The store shell: a [TvAppFrame] rail (Home, Search, Updates with count, Library,+ * Sources — the phone's bottom bar turned sideways) and the selected destination's+ * screen beside it. */ @Composable private fun TvStoreRail(@@ -144,14 +156,20 @@ private fun TvStoreRail( stringResource(R.string.nav_updates) } val libraryLabel = stringResource(R.string.nav_library)- val destinations = remember(homeLabel, searchLabel, updatesLabel, libraryLabel) {+ val sourcesLabel = stringResource(R.string.nav_sources)+ val destinations = remember(+ homeLabel, searchLabel, updatesLabel, libraryLabel, sourcesLabel+ ) { listOf( TvDestination(homeLabel) { IconHome() }, TvDestination(searchLabel) { IconSearch() }, TvDestination(updatesLabel) { IconDownload() }, TvDestination(libraryLabel) { IconPackage() },+ TvDestination(sourcesLabel) { IconProvider() }, ) }+ // Survives returning from a pushed route: without saveable the rail reset to+ // Home behind every detail page, so BACK landed on the wrong destination. var selectedIndex by rememberSaveable { mutableIntStateOf(0) } fun openDetail(app: UnifiedApp) {@@ -163,7 +181,6 @@ private fun TvStoreRail( destinations = destinations, selected = selectedIndex, onSelect = { selectedIndex = it },- brand = { TvStoreBrand() }, backReturnsToRail = backStack.backStack.size <= 1, ) { when (selectedIndex) {@@ -176,27 +193,16 @@ private fun TvStoreRail( ) TV_DEST_UPDATES -> TvStoreUpdates(viewModel = viewModel, onAppClick = ::openDetail) TV_DEST_LIBRARY -> TvStoreLibrary(viewModel = viewModel, onAppClick = ::openDetail)- else -> TvStoreHome(viewModel = viewModel, onAppClick = ::openDetail)- }- }-}--/** 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() }+ TV_DEST_SOURCES -> TvStoreSources(viewModel = viewModel)+ else -> TvStoreHome(+ viewModel = viewModel,+ onAppClick = ::openDetail,+ onOpenUpdates = { selectedIndex = TV_DEST_UPDATES },+ onOpenBrowse = { section ->+ viewModel.openBrowse(section)+ backStack.add(TvStoreRoute.Browse(section.id))+ },+ ) }- 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/TvStoreBrowse.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreBrowse.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreBrowse.ktnew file mode 100644index 0000000000..5329d3540a--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreBrowse.kt@@ -0,0 +1,72 @@+package com.vayunmathur.appstore.tv++import androidx.activity.compose.BackHandler+import androidx.compose.foundation.layout.fillMaxSize+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.ui.Modifier+import androidx.compose.ui.res.stringResource+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvGrid+import com.vayunmathur.library.tv.TvLoading+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.tvFullWidth+import com.vayunmathur.library.ui.IconPackage++/**+ * One home section's full catalogue as a grid of full-information cards.+ * Mirrors the phone's Browse page: the home rows are capped slices, this lists+ * literally every app behind the section, A–Z, in the same card search uses.+ */+@Composable+fun TvStoreBrowse(+ viewModel: TvStoreViewModel,+ onAppClick: (UnifiedApp) -> Unit,+ onBack: () -> Unit,+ modifier: Modifier = Modifier,+) {+ val state by viewModel.browse.collectAsState()+ BackHandler(onBack = onBack)+ TvStoreBrowseScreen(+ state = state,+ onAppClick = onAppClick,+ onBack = onBack,+ modifier = modifier,+ )+}++@Composable+internal fun TvStoreBrowseScreen(+ state: TvBrowseUiState,+ modifier: Modifier = Modifier,+ onAppClick: (UnifiedApp) -> Unit = {},+ onBack: () -> Unit = {},+) {+ when {+ state.isLoading && state.apps.isEmpty() ->+ TvLoading(label = stringResource(R.string.sync_in_progress))+ state.apps.isEmpty() -> TvEmptyState(+ title = stringResource(R.string.browse_empty_title),+ body = stringResource(R.string.browse_empty_message),+ icon = { IconPackage() },+ )+ else -> TvGrid(columns = 3, modifier = modifier.fillMaxSize()) {+ tvFullWidth(key = "header") {+ TvScreenHeader(title = state.title)+ }+ items(state.apps, key = { it.packageName }) { app ->+ TvStoreAppCard(+ app = app,+ onClick = { onAppClick(app) },+ installedIcon = state.installedIcons[app.packageName],+ isInstalled = app.packageName in state.installedPackages,+ stage = state.stages[app.packageName],+ )+ }+ }+ }+}
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreCards.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreCards.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreCards.ktnew file mode 100644index 0000000000..68c2d83d1b--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreCards.kt@@ -0,0 +1,189 @@+package com.vayunmathur.appstore.tv++import android.graphics.drawable.Drawable+import androidx.compose.foundation.Image+import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxScope+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp+import androidx.core.graphics.drawable.toBitmap+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text+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.library.image.compose.AsyncImage+import com.vayunmathur.library.tv.TvBadge+import com.vayunmathur.library.tv.TvIcon+import com.vayunmathur.library.tv.TvInfoCard+import com.vayunmathur.library.ui.IconCheck+import java.util.Locale++/**+ * The one app card for every TV grid: icon, name, developer/source byline, the+ * summary as a two-line description, source/verified/installed badges, and the+ * install progress strip. Everything a phone search result shows.+ *+ * One card everywhere — home, browse, search, updates, library — so the whole TV+ * store reads the same from the couch.+ */+@Composable+fun TvStoreAppCard(+ app: UnifiedApp,+ onClick: () -> Unit,+ modifier: Modifier = Modifier,+ installedIcon: Drawable? = null,+ isInstalled: Boolean = false,+ hasUpdate: Boolean = false,+ stage: InstallStage? = null,+ versionLabel: String? = null,+ /** e.g. the Updates screen's per-app Update button. */+ trailing: (@Composable () -> Unit)? = null,+ onFocus: (() -> Unit)? = null,+) {+ TvInfoCard(+ title = app.name,+ onClick = onClick,+ modifier = modifier,+ subtitle = (app.author ?: app.tvSourceLabel()),+ description = versionLabel ?: app.summary.ifBlank { null },+ leading = { TvStoreAppArt(app = app, installedIcon = installedIcon) },+ badges = {+ TvStoreCardBadges(+ app = app,+ isInstalled = isInstalled,+ hasUpdate = hasUpdate,+ stage = stage,+ )+ },+ trailing = trailing,+ progress = stage?.downloadFraction(),+ onFocus = onFocus,+ )+}++/** Source/verified/installed pills under the card text. Update outranks installed. */+@Composable+private fun TvStoreCardBadges(+ app: UnifiedApp,+ isInstalled: Boolean,+ hasUpdate: Boolean,+ stage: InstallStage?,+) {+ TvBadge(text = app.tvSourceLabel())+ if (app.rating != null) {+ TvBadge(text = String.format(Locale.US, "%.1f ★", app.rating))+ }+ if (app.reproducible) {+ TvBadge(text = stringResource(R.string.chip_reproducible))+ }+ if (stage is InstallStage.Failed) {+ Text(+ text = stringResource(R.string.stage_failed, stage.reason),+ style = MaterialTheme.typography.labelMedium,+ color = MaterialTheme.colorScheme.error,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ return+ }+ if (hasUpdate) {+ TvBadge(text = stringResource(R.string.action_update))+ return+ }+ if (isInstalled) {+ TvIcon { IconCheck() }+ Text(+ text = stringResource(R.string.installed),+ style = MaterialTheme.typography.labelMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ }+}++/**+ * Icon art with the phone's fallback chain: the installed launcher icon beats+ * re-downloading the listing's copy, then the listing URL, then an initial.+ */+@Composable+internal fun BoxScope.TvStoreAppArt(+ app: UnifiedApp,+ installedIcon: Drawable?,+ size: Dp = 64.dp,+) {+ val px = with(LocalDensity.current) { size.roundToPx() * 2 }.coerceAtLeast(1)+ val bitmap = remember(installedIcon, px) {+ installedIcon?.let {+ runCatching {+ it.toBitmap(width = px, height = px).asImageBitmap()+ }.getOrNull()+ }+ }+ when {+ bitmap != null -> Image(+ bitmap = bitmap,+ contentDescription = null,+ modifier = Modifier.size(size).clip(MaterialTheme.shapes.small),+ contentScale = ContentScale.Crop,+ )+ app.iconUrl != null -> AsyncImage(+ model = app.iconUrl,+ contentDescription = null,+ modifier = Modifier.size(size).clip(MaterialTheme.shapes.small),+ contentScale = ContentScale.Crop,+ )+ else -> Box(+ Modifier.size(size)+ .clip(MaterialTheme.shapes.small)+ .background(MaterialTheme.colorScheme.surfaceVariant),+ contentAlignment = Alignment.Center,+ ) {+ Text(+ text = app.name.take(1).uppercase(),+ style = MaterialTheme.typography.titleMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ }+}++/** 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+ },+)++/** 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)
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.ktindex ab8ef54b29..38a4918a95 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetail.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetail.kt@@ -5,49 +5,51 @@ 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.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester-import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.focus.focusRequester 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 as TvText+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.formatSize-import com.vayunmathur.library.image.compose.AsyncImage-import com.vayunmathur.library.tv.TvBackdrop+import com.vayunmathur.library.tv.TvBadge import com.vayunmathur.library.tv.TvButton+import com.vayunmathur.library.tv.TvDialog import com.vayunmathur.library.tv.TvEmptyState-import com.vayunmathur.library.tv.TvHeroText import com.vayunmathur.library.tv.TvInitialFocus-import com.vayunmathur.library.tv.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.IconDownload 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.+ * One app's TV page: two panes side by side, no backdrop. Left is identity plus+ * actions — icon, name, developer, source badge, Install/Update/Open and the+ * uninstall secondary, then the Size/Rated/Version stats. Right is the scrolling+ * body — summary, description, What's new, chips, the security card, screenshots,+ * links. Same order and same strings as the phone's detail page. */ @Composable fun TvStoreDetail(@@ -62,6 +64,8 @@ fun TvStoreDetail( onInstall = viewModel::install, onOpen = viewModel::openApp, onUninstall = viewModel::uninstallApp,+ onOpenInBrowser = viewModel::openInBrowser,+ onOpenInPlayStore = viewModel::openInPlayStore, onDismissFailure = viewModel::dismissInstallFailure, onBack = onBack, modifier = modifier,@@ -75,11 +79,14 @@ internal fun TvStoreDetailScreen( onInstall: (UnifiedApp) -> Unit = {}, onOpen: (String) -> Unit = {}, onUninstall: (String) -> Unit = {},+ onOpenInBrowser: (String) -> Unit = {},+ onOpenInPlayStore: (String) -> Unit = {}, onDismissFailure: (String) -> Unit = {}, onBack: () -> Unit = {}, ) { val app = state.app val primaryFocus = remember(app?.packageName) { FocusRequester() }+ var showUninstallConfirm by remember(app?.packageName) { mutableStateOf(false) } if (app == null) { TvEmptyState( title = stringResource(R.string.home_empty_title),@@ -89,188 +96,234 @@ internal fun TvStoreDetailScreen( ) return }+ TvInitialFocus(primaryFocus, app.packageName)+ Column(modifier.fillMaxSize()) {+ TvButton(+ text = stringResource(R.string.tv_detail_back),+ onClick = onBack,+ icon = { IconBack() },+ modifier = Modifier.padding(start = tvContentStart(), top = 20.dp, bottom = 8.dp),+ )+ Row(+ Modifier.fillMaxSize().padding(start = tvContentStart(), end = 48.dp, bottom = 32.dp),+ horizontalArrangement = Arrangement.spacedBy(40.dp),+ ) {+ TvStoreDetailIdentity(+ state = state,+ focusRequester = primaryFocus,+ onInstall = { onInstall(app) },+ onOpen = { onOpen(app.packageName) },+ onUninstall = { showUninstallConfirm = true },+ onDismissFailure = { onDismissFailure(app.packageName) },+ modifier = Modifier.weight(0.65f).fillMaxHeight(),+ )+ TvStoreDetailBody(+ state = state,+ onOpenInBrowser = onOpenInBrowser,+ onOpenInPlayStore = onOpenInPlayStore,+ modifier = Modifier.weight(1f).fillMaxHeight().verticalScroll(rememberScrollState()),+ )+ }+ }+ if (showUninstallConfirm) {+ TvDialog(+ title = stringResource(R.string.uninstall_3, app.name),+ body = stringResource(+ R.string.this_will_uninstall_you_can_reinstall_la, app.packageName+ ),+ onDismissRequest = { showUninstallConfirm = false },+ ) {+ TvButton(+ text = stringResource(UiR.string.cancel),+ onClick = { showUninstallConfirm = false },+ )+ TvButton(+ text = stringResource(R.string.uninstall),+ onClick = {+ showUninstallConfirm = false+ onUninstall(app.packageName)+ },+ primary = true,+ )+ }+ }+}++/**+ * Left pane: icon, name, developer, source badge, primary Install/Update/Open+ * plus the Open/Uninstall secondary exactly like the phone, then the stats row.+ */+@Composable+private fun TvStoreDetailIdentity(+ state: TvDetailUiState,+ focusRequester: FocusRequester,+ onInstall: () -> Unit,+ onOpen: () -> Unit,+ onUninstall: () -> Unit,+ onDismissFailure: () -> Unit,+ modifier: Modifier = Modifier,+) {+ val app = state.app ?: 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,+ Column(modifier, verticalArrangement = Arrangement.spacedBy(12.dp)) {+ Box(contentAlignment = Alignment.Center) {+ TvStoreAppArt(app = app, installedIcon = state.installedIcon, size = 120.dp)+ }+ Text(+ text = app.name,+ style = MaterialTheme.typography.headlineMedium,+ fontWeight = FontWeight.Bold,+ color = MaterialTheme.colorScheme.onSurface,+ )+ app.author?.let {+ Text(+ text = it,+ style = MaterialTheme.typography.titleMedium,+ color = MaterialTheme.colorScheme.primary,+ )+ }+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ TvBadge(text = app.tvSourceLabel())+ if (app.reproducible) TvBadge(text = stringResource(R.string.chip_reproducible))+ if (app.rating != null) {+ TvBadge(+ text = String.format(java.util.Locale.US, "%.1f ★", app.rating), )- } else {- TvStoreHeroFallback(app = app) } }- LazyColumn(- Modifier.fillMaxSize(),- verticalArrangement = Arrangement.spacedBy(8.dp),- ) {- item("back") {+ // Primary action: exactly the phone's AppInstallActions logic.+ when {+ busy -> TvButton(+ text = stage.tvStageLabel(),+ onClick = {},+ enabled = false,+ modifier = Modifier.focusRequester(focusRequester),+ )+ state.hasUpdate -> { TvButton(- text = stringResource(R.string.tv_detail_back),- onClick = onBack,- icon = { IconBack() },- modifier = Modifier.padding(- start = tvContentStart(),- top = 40.dp,- bottom = 8.dp,- ),+ text = stringResource(R.string.action_update),+ onClick = onInstall,+ primary = true,+ icon = { IconDownload() },+ modifier = Modifier.focusRequester(focusRequester), )- }- 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),+ TvButton(+ text = stringResource(UiR.string.open),+ onClick = onOpen, ) }- 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)+ state.isInstalled -> {+ TvButton(+ text = stringResource(UiR.string.open),+ onClick = onOpen,+ primary = true,+ modifier = Modifier.focusRequester(focusRequester),+ )+ TvButton(+ text = stringResource(R.string.uninstall),+ onClick = onUninstall,+ icon = { IconDelete() },+ ) }- item("bottom") { Spacer(Modifier.height(48.dp)) }+ else -> TvButton(+ text = stringResource(R.string.action_install),+ onClick = onInstall,+ primary = true,+ icon = { IconDownload() },+ modifier = Modifier.focusRequester(focusRequester),+ )+ }+ if (state.isInstalled && state.installedInfo?.versionName != null && !state.hasUpdate) {+ Text(+ text = stringResource(R.string.installed_2, state.installedInfo.versionName),+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ ) }- TvInitialFocus(primaryFocus, app.packageName)+ if (stage is InstallStage.Failed) {+ Text(+ text = stringResource(R.string.stage_failed, stage.reason),+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.error,+ )+ TvButton(+ text = stringResource(R.string.action_dismiss),+ onClick = onDismissFailure,+ )+ }+ // Stats row: Size / Rated / Version, like the phone's facts row.+ TvStoreDetailStats(app = app)+ TvStoreVerificationLine(state = state) } } -/** Hero block: name, developer, source, version/size meta, tier chip, actions + trust card. */+/** Size / Rated / Version in whatever subset the source published. Like the phone. */ @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) }+private fun TvStoreDetailStats(app: UnifiedApp, modifier: Modifier = Modifier) {+ val cells = buildList<Pair<String, String>> {+ 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) } }- 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,+ if (cells.isEmpty()) return+ Row(modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(24.dp)) {+ cells.forEach { (label, value) ->+ Column(horizontalAlignment = Alignment.CenterHorizontally) {+ Text(+ text = value,+ style = MaterialTheme.typography.titleMedium,+ fontWeight = FontWeight.SemiBold,+ color = MaterialTheme.colorScheme.onSurface,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ )+ Text(+ text = label,+ style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant,- modifier = Modifier.padding(top = 8.dp),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis, ) }- 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. */+/** What the last install proved, in the verifier's own words — or the neutral line. */ @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() },+private fun TvStoreVerificationLine(state: TvDetailUiState, modifier: Modifier = Modifier) {+ val message = state.verification.toTvMessage()+ if (message == null) {+ 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 }
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.ktindex 7af6aa7313..86e615998e 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetailSections.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreDetailSections.kt@@ -2,14 +2,11 @@ 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@@ -17,7 +14,6 @@ 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@@ -28,139 +24,189 @@ 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.AppSource 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.TvBadge import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvMediaCard import com.vayunmathur.library.tv.TvShelf-import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.ui.IconGlobe /**- * 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 right pane of the TV detail page: the scrolling body. Same order and same+ * strings as the phone's detail page — summary headline, description, What's new,+ * category chips, the security/source card with its verification line, the+ * screenshots shelf, links, and the remaining facts last. *- * 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.+ * Split from TvStoreDetail.kt to keep both files under the 350-line limit. */ @Composable-internal fun TvStoreTrustPanel(app: UnifiedApp, modifier: Modifier = Modifier) {+internal fun TvStoreDetailBody(+ state: TvDetailUiState,+ onOpenInBrowser: (String) -> Unit,+ onOpenInPlayStore: (String) -> Unit,+ modifier: Modifier = Modifier,+) {+ val app = state.app ?: return+ Column(modifier, verticalArrangement = Arrangement.spacedBy(20.dp)) {+ // Summary headline always; full description behind a toggle — most are long.+ if (app.summary.isNotBlank()) {+ Text(+ text = app.summary,+ style = MaterialTheme.typography.headlineSmall,+ fontWeight = FontWeight.Medium,+ color = MaterialTheme.colorScheme.onSurface,+ )+ }+ if (app.description.isNotBlank() && app.description != app.summary) {+ 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 },+ )+ }+ 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),+ )+ }+ }+ TvStoreDetailChips(app = app)+ TvStoreTrustCard(state = state)+ val shots = app.tvScreenshots.ifEmpty { app.screenshots }+ if (shots.isNotEmpty()) {+ TvStoreScreenshotShelf(urls = shots)+ }+ TvStoreDetailLinks(+ app = app,+ onOpenInBrowser = onOpenInBrowser,+ onOpenInPlayStore = onOpenInPlayStore,+ )+ TvStoreDetailFacts(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()+ }+}++/** Categories, reproducible badge, ads and anti-features. Like the phone's chips row. */+@Composable+private fun TvStoreDetailChips(app: UnifiedApp, modifier: Modifier = Modifier) {+ if (app.categories.isEmpty() && app.antiFeatures.isEmpty() &&+ !app.containsAds && !app.reproducible+ ) {+ return+ }+ Row(+ modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.spacedBy(8.dp),+ ) {+ if (app.reproducible) {+ TvBadge(text = stringResource(R.string.chip_reproducible))+ }+ app.categories.take(CHIP_LIMIT).forEach { TvBadge(text = it) }+ if (app.containsAds) {+ TvBadge(text = stringResource(R.string.chip_contains_ads))+ }+ // F-Droid's anti-feature labels are the honest part of its listings and+ // there is no reason to bury them; they are flagged rather than hidden.+ app.antiFeatures.take(CHIP_LIMIT).forEach { TvBadge(text = it) }+ }+}++/**+ * What can be checked about this app's download, and what the last install proved.+ * The phone's "F-Droid — Built from public source code…" card with the verification+ * line, neutral by design: it describes the source's practices, not a ranking.+ */+@Composable+private fun TvStoreTrustCard(state: TvDetailUiState, modifier: Modifier = Modifier) {+ val app = state.app ?: return val profile = TrustProfile.of(app.source) val scheme = MaterialTheme.colorScheme Column( modifier+ .fillMaxWidth() .clip(MaterialTheme.shapes.medium)- .background(scheme.surface.copy(alpha = 0.85f))+ .background(scheme.surface) .padding(20.dp),- verticalArrangement = Arrangement.spacedBy(10.dp),+ verticalArrangement = Arrangement.spacedBy(8.dp), ) { Text(- text = stringResource(R.string.trust_page_title),+ text = stringResource(profile.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, )+ val message = state.verification.toTvCardMessage() 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),+ text = message ?: stringResource(R.string.detail_tap_for_trust), style = MaterialTheme.typography.bodyMedium,- color = scheme.onSurfaceVariant,+ color = if (message == null) {+ scheme.onSurfaceVariant+ } else if (state.verification is com.vayunmathur.appstore.data.security.VerificationResult.Verified) {+ scheme.primary+ } else {+ scheme.error+ }, ) } } -/** 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)+private fun com.vayunmathur.appstore.data.security.VerificationResult?.toTvCardMessage(): String? =+ when (this) {+ is com.vayunmathur.appstore.data.security.VerificationResult.Rejected ->+ stringResource(R.string.detail_install_blocked, reason)+ is com.vayunmathur.appstore.data.security.VerificationResult.Verified ->+ stringResource(R.string.detail_checked_on_install, detail)+ is com.vayunmathur.appstore.data.security.VerificationResult.Unverified ->+ stringResource(R.string.detail_installed_unverified, reason)+ null -> null }-} /** TV screenshots where the source publishes a set; landscape cards in a shelf. */ @Composable-internal fun TvStoreScreenshotShelf(urls: List<String>, modifier: Modifier = Modifier) {+private 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,@@ -191,139 +237,54 @@ internal fun TvStoreScreenshotShelf(urls: List<String>, modifier: Modifier = Mod } } -/** Description, what's new, compat line, facts, permissions. */+/** Website / source / privacy links as buttons, plus the Play fallback. Like the phone. */ @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),- )- }+private fun TvStoreDetailLinks(+ app: UnifiedApp,+ onOpenInBrowser: (String) -> Unit,+ onOpenInPlayStore: (String) -> Unit,+ modifier: Modifier = Modifier,+) {+ val links = buildList<Pair<Int, String>> {+ app.website?.let { add(R.string.link_website to it) }+ app.sourceCode?.let { add(R.string.link_source to it) }+ app.privacyPolicyUrl?.let { add(R.string.link_privacy to it) }+ }+ if (links.isEmpty() && app.source != AppSource.PLAYSTORE) return+ Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(10.dp)) {+ links.forEach { (label, url) ->+ TvButton(+ text = stringResource(label),+ onClick = { onOpenInBrowser(url) },+ icon = { IconGlobe() },+ ) }- 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),- )- }+ if (app.source == AppSource.PLAYSTORE) {+ TvButton(+ text = stringResource(R.string.view_in_play_store),+ onClick = { onOpenInPlayStore(app.packageName) },+ ) }- 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. */+/** The remaining facts, as a plain table — deliberately last, like the phone. */ @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))+private fun TvStoreDetailFacts(app: UnifiedApp, modifier: Modifier = Modifier) {+ Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(10.dp)) {+ if (app.ratingCount > 0) {+ TvStoreFact(stringResource(R.string.detail_rating_count), formatCount(app.ratingCount)) }- 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,- )- }+ if (app.permissions.isNotEmpty()) {+ TvStoreFact(+ stringResource(R.string.detail_permissions),+ app.permissions.joinToString("\n") { it.substringAfterLast('.') },+ ) }- }-}--/** 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))+ app.targetSdk?.let {+ TvStoreFact(stringResource(R.string.detail_target_sdk), it.toString()) } TvStoreFact(stringResource(R.string.detail_package), app.packageName) }@@ -331,7 +292,7 @@ private fun TvStoreVersionRow(app: UnifiedApp) { @Composable private fun TvStoreFact(label: String, value: String) {- Column(Modifier.fillMaxWidth(0.6f)) {+ Column(Modifier.fillMaxWidth()) { Text( text = label, style = MaterialTheme.typography.bodyMedium,@@ -344,3 +305,5 @@ private fun TvStoreFact(label: String, value: String) { ) } }++private const val CHIP_LIMIT = 6
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.ktindex ec54991fcd..4a0542dfb6 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreHome.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreHome.kt@@ -1,68 +1,68 @@ 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.Row import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.height+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.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.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.pluralStringResource 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 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.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.TvChip import com.vayunmathur.library.tv.TvEmptyState-import com.vayunmathur.library.tv.TvHeroText+import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvLoading-import com.vayunmathur.library.tv.TvShelf-import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.tv.tvFullWidth+import com.vayunmathur.library.tv.tvGridHeader 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 store front on TV: the phone's home reflowed for a wide screen. One+ * scrolling grid: the updates banner, the category chips, then one headed block+ * per source — same sections, same order, same titles and subtitles as the phone. *- * 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.+ * Two grid rows per section (six cards): the screen shows a dozen+ items without+ * scrolling, and Browse lists the whole catalogue behind each header. */ @Composable fun TvStoreHome( viewModel: TvStoreViewModel, onAppClick: (UnifiedApp) -> Unit,+ onOpenUpdates: () -> Unit,+ onOpenBrowse: (TvSection) -> Unit, modifier: Modifier = Modifier, ) { val state by viewModel.home.collectAsState()+ // The updates banner counts every source, but the Play half of the update check+ // only ran when the Updates tab was opened — a fresh launch showed the F-Droid+ // count until the user visited that tab (issue #701). Kick off one check from+ // home. Mirrors the phone's HomePage.+ LaunchedEffect(Unit) {+ viewModel.checkForUpdates()+ } TvStoreHomeScreen( state = state,- onInstall = viewModel::install,- onOpen = viewModel::openApp,+ onSelectCategory = viewModel::selectCategory, onAppClick = onAppClick,+ onOpenUpdates = onOpenUpdates,+ onOpenBrowse = onOpenBrowse, modifier = modifier, ) }@@ -71,220 +71,137 @@ fun TvStoreHome( internal fun TvStoreHomeScreen( state: TvHomeUiState, modifier: Modifier = Modifier,- onInstall: (UnifiedApp) -> Unit = {},- onOpen: (String) -> Unit = {},+ onSelectCategory: (String?) -> Unit = {}, onAppClick: (UnifiedApp) -> Unit = {},+ onOpenUpdates: () -> Unit = {},+ onOpenBrowse: (TvSection) -> 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- }-+ // Unkeyed: runs once. Keying on the update count would yank focus back to the+ // banner every time a check completes or an update installs and drops off.+ TvInitialFocus(primaryFocus) when {- state.isLoading && sections.isEmpty() -> TvLoading(label = stringResource(R.string.sync_in_progress))- sections.isEmpty() -> TvEmptyState(+ state.isLoading && state.sections.isEmpty() ->+ TvLoading(label = stringResource(R.string.sync_in_progress))+ state.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 -> TvGrid(columns = 3, modifier = modifier.fillMaxSize()) {+ if (state.updateCount > 0) {+ tvFullWidth(key = "updates") {+ TvUpdatesBanner(+ count = state.updateCount,+ onClick = onOpenUpdates,+ focusRequester = primaryFocus, )- } 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.categories.isNotEmpty()) {+ tvFullWidth(key = "categories") {+ TvCategoryChips(+ categories = state.categories,+ selected = state.selectedCategory,+ onSelect = onSelectCategory,+ ) }- if (state.statusMessage.isNotBlank()) {- item("status") {- TvStoreStatusLine(- message = state.statusMessage,- isLoading = state.isLoading,- )- }+ }+ // Transient sync line, e.g. what the catalogues are currently fetching.+ if (state.statusMessage.isNotBlank()) {+ tvFullWidth(key = "status") {+ Text(+ text = state.statusMessage,+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ ) }- items(sections, key = { it.id }) { section ->- TvStoreSectionShelf(- section = section,- state = state,- onAppClick = onAppClick,- onHeroFocus = { heroApp = it },+ }+ state.sections.forEachIndexed { index, section ->+ tvGridHeader(+ key = "${section.id}-header",+ title = section.title,+ subtitle = section.subtitle,+ first = index == 0 && state.updateCount == 0 &&+ state.categories.isEmpty() && state.statusMessage.isBlank(),+ action = {+ TvButton(+ text = stringResource(R.string.action_browse),+ onClick = { onOpenBrowse(section) },+ )+ },+ )+ val cards = section.apps.take(HOME_CARDS_PER_SECTION)+ items(cards, key = { "${section.id}-${it.packageName}" }) { app ->+ TvStoreAppCard(+ app = app,+ onClick = { onAppClick(app) },+ installedIcon = state.installedIcons[app.packageName],+ isInstalled = app.packageName in state.installedPackages,+ hasUpdate = app.packageName in state.updatePackages,+ stage = state.stages[app.packageName], ) }- 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. */+/**+ * The phone's "N updates available · review and install" banner as one full-width+ * focusable row: the count, the phone's subtitle, and a chevron.+ */ @Composable-private fun TvStoreHero(- app: UnifiedApp,- state: TvHomeUiState,+private fun TvUpdatesBanner(+ count: Int,+ onClick: () -> Unit, 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),- )- }+ TvButton(+ text = pluralStringResource(R.plurals.updates_count, count, count) ++ " · " + stringResource(R.string.updates_banner_subtitle),+ onClick = onClick,+ primary = true,+ icon = { IconDownload() },+ modifier = modifier.fillMaxWidth().focusRequester(focusRequester),+ ) } -/** One titled shelf of app tiles; focusing a tile moves the hero to it. */+/** The phone's category chips as a wrapping row inside one full-width grid item. */ @Composable-private fun TvStoreSectionShelf(- section: TvSection,- state: TvHomeUiState,- onAppClick: (UnifiedApp) -> Unit,- onHeroFocus: (UnifiedApp) -> Unit,+private fun TvCategoryChips(+ categories: List<String>,+ selected: String?,+ onSelect: (String?) -> 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) },- )+ // FlowRow would want the experimental layout API; a fixed 6-per-row chunk+ // reads the same on a TV and keeps the imports stable. The All chip leads.+ val cells = listOf<String?>(null) + categories.take(CATEGORY_CHIP_LIMIT)+ Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(10.dp)) {+ cells.chunked(CATEGORY_CHIPS_PER_ROW).forEach { chunk ->+ Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {+ chunk.forEach { category ->+ if (category == null) {+ TvChip(+ label = stringResource(R.string.filter_all),+ selected = selected == null,+ onClick = { onSelect(null) },+ )+ } else {+ TvChip(+ label = category,+ selected = selected == category,+ onClick = { onSelect(if (selected == category) null else category) },+ )+ }+ }+ } } } } -/** 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,- )- }-}+private const val HOME_CARDS_PER_SECTION = 6+private const val CATEGORY_CHIPS_PER_ROW = 6+private const val CATEGORY_CHIP_LIMIT = 23
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.ktindex 5bcc01c2af..6f222fc872 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibrary.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibrary.kt@@ -1,13 +1,10 @@ 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@@ -18,24 +15,23 @@ 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.ui.labelRes 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.TvGrid import com.vayunmathur.library.tv.TvScreenHeader-import com.vayunmathur.library.tv.tvContentPadding-import com.vayunmathur.library.tv.tvContentStart+import com.vayunmathur.library.tv.tvFullWidth import com.vayunmathur.library.ui.IconPackage /**- * Every installed app the store can attribute to a source, grouped by source chip.+ * Every installed app the store can attribute to a source, as a grid of+ * full-information cards with the phone's source filter chips. *- * 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.+ * Uninstall lives only on an app's own page: a delete action next to every card+ * 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(@@ -60,54 +56,46 @@ internal fun TvStoreLibraryScreen( 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() },+ )+ return+ }+ TvGrid(columns = 3, modifier = modifier.fillMaxSize()) {+ tvFullWidth(key = "header") {+ TvScreenHeader(title = stringResource(R.string.nav_library)) }- 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),+ tvFullWidth(key = "filters") {+ Row(+ Modifier.fillMaxWidth().padding(vertical = 4.dp),+ horizontalArrangement = Arrangement.spacedBy(10.dp), ) {- items(state.apps, key = { it.packageName }) { app ->- TvStoreAppRow(- app = app,- onClick = { onAppClick(app) },- supporting = app.versionName,- badge = stringResource(R.string.installed),+ for (entry in SourceFilter.entries) {+ val count = state.counts[entry] ?: 0+ TvChip(+ label = stringResource(+ R.string.filter_with_count,+ stringResource(entry.labelRes()),+ count,+ ),+ selected = state.filter == entry,+ onClick = { onFilterChange(entry) }, ) } } }+ items(state.apps, key = { it.packageName }) { app ->+ TvStoreAppCard(+ app = app,+ onClick = { onAppClick(app) },+ installedIcon = state.installedIcons[app.packageName],+ isInstalled = true,+ stage = null,+ versionLabel = app.versionName,+ )+ } } }
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibraryOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibraryOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibraryOps.ktnew file mode 100644index 0000000000..9112911bc4--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreLibraryOps.kt@@ -0,0 +1,78 @@+package com.vayunmathur.appstore.tv++import androidx.lifecycle.viewModelScope+import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.InstalledInfo+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.util.SourceFilter+import kotlinx.coroutines.launch++// ---- Library + Accrescent attribution ----+// Moved from TvStoreViewModel.kt (FileLength split); behavior identical.++// --- Accrescent home row ------------------------------------------------------------+/**+ * Refresh Accrescent's signed allowlist and its home listings. Fail soft like the+ * phone's `loadAccrescent`: a network blip leaves the previous rows in place rather+ * than emptying them.+ */+internal suspend fun TvStoreViewModel.loadAccrescent(enabled: Set<AppSource> = enabledSourcesFlow.value) {+ if (AppSource.ACCRESCENT !in enabled) return+ accrescent.refreshRepoData()+ // The same response tells us which packages Accrescent vouches for, which the+ // library uses for attribution. Fail soft like the phone: a blip keeps the+ // previous answer rather than emptying the library.+ val ids = accrescent.appIds()+ if (ids.isNotEmpty()) accrescentPackagesFlow.value = ids+ val page = accrescent.listApps()+ if (page.apps.isNotEmpty()) accrescentAppsFlow.value = page.apps+}++internal fun TvStoreViewModel.setLibraryFilter(filter: SourceFilter) {+ libraryFilterFlow.value = filter+}++/** Re-read the device's installed set, for the library screen appearing. */+internal fun TvStoreViewModel.refreshInstalled() {+ viewModelScope.launch {+ installedRepo.refresh()+ refreshPlayInstalledPackages()+ }+}++/**+ * Ask Play which installed packages it actually hosts, for library attribution.+ *+ * Mirrors the phone's `refreshPlayInstalledPackages`: only packages no offline+ * source lists are worth asking about, and a failed lookup keeps the previous+ * answer rather than emptying the library.+ */+internal suspend fun TvStoreViewModel.refreshPlayInstalledPackages(+ enabled: Set<AppSource> = enabledSourcesFlow.value,+) {+ if (AppSource.PLAYSTORE !in enabled) {+ playInstalledPackagesFlow.value = emptySet()+ return+ }+ val index = catalog.indexSnapshot()+ val candidates = installedRepo.apps.value+ .map { it.packageName }+ .filter { it !in index }+ if (candidates.isEmpty()) {+ playInstalledPackagesFlow.value = emptySet()+ return+ }+ play.detailsOrNull(candidates)?.map { it.packageName }?.toSet()?.let {+ playInstalledPackagesFlow.value = it+ }+}++/** An installed package as a listing, for the library screen. */+internal fun InstalledInfo.toTvListing(source: AppSource) = UnifiedApp(+ packageName = packageName,+ source = source,+ name = name,+ versionName = versionName,+ versionCode = versionCode,+ lastUpdated = lastUpdateTime,+)
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreOps.ktnew file mode 100644index 0000000000..176e0b3bbe--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreOps.kt@@ -0,0 +1,216 @@+package com.vayunmathur.appstore.tv++import androidx.lifecycle.viewModelScope+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.data.installer.InstallFailureBatch+import com.vayunmathur.appstore.data.installer.InstallStage+import com.vayunmathur.appstore.data.play.PlayAuthState+import com.vayunmathur.appstore.data.priority+import com.vayunmathur.appstore.data.searchCandidate+import com.vayunmathur.appstore.data.security.VerificationResult+import com.vayunmathur.appstore.domain.SearchRanking+import com.vayunmathur.library.util.AppMessages+import kotlinx.coroutines.delay+import kotlinx.coroutines.launch++// ---- Search hub + updates hub bodies ----+// Moved from TvStoreViewModel.kt (FileLength split); behavior identical.++/**+ * Two-wave search: the on-disk catalogues answer instantly, then Accrescent's cached+ * listings and Play's reply merge in. Mirrors the phone's `setSearchImpl`: the local+ * half is published first so the user never waits on the network to see something.+ */+internal fun TvStoreViewModel.setSearchImpl(query: String) {+ queryFlow.value = query+ searchJob?.cancel()+ if (query.isBlank()) {+ searchResultsFlow.value = emptyList()+ hasSearchedFlow.value = false+ isSearchingFlow.value = false+ return+ }+ searchJob = viewModelScope.launch {+ delay(SEARCH_DEBOUNCE_MS)+ isSearchingFlow.value = true+ searchPlayErrorFlow.value = ""+ val enabled = enabledSourcesFlow.value++ val local = catalog.searchLocal(query)+ searchResultsFlow.value = SearchRanking.rank(local, query) { it.searchCandidate() }++ // Accrescent has no search RPC: client-side over the listings already cached+ // from the home carousel, so no extra network round-trip.+ val accrescentResults =+ if (AppSource.ACCRESCENT in enabled) accrescent.search(query) else emptyList()+ // Play may refuse (429): the auth state records the refusal and the local half+ // stays on screen — surfaced above the list, never as a silent gap.+ val remote = if (AppSource.PLAYSTORE in enabled) play.search(query) else emptyList()+ searchPlayErrorFlow.value = (play.authState.value as? PlayAuthState.Error)+ ?.let { context.getString(R.string.play_unavailable, it.message) }+ .orEmpty()+ searchResultsFlow.value = SearchRanking.rank(+ (local + remote + accrescentResults)+ .sortedBy { it.source.priority }+ .distinctBy { it.packageName },+ query,+ ) { it.searchCandidate() }+ isSearchingFlow.value = false+ hasSearchedFlow.value = true+ }+}++/**+ * Recheck every enabled source for newer builds of installed packages. Mirrors the+ * phone's `checkForUpdatesImpl`: catalogue first, Play only for packages no offline+ * source lists, Accrescent's allowlist refresh then per-package update info.+ */+internal fun TvStoreViewModel.checkForUpdatesImpl() {+ if (isCheckingUpdatesFlow.value) return+ viewModelScope.launch {+ try {+ val enabled = enabledSourcesFlow.value+ isCheckingUpdatesFlow.value = true+ statusMessageFlow.value = context.getString(R.string.updates_checking)++ installedRepo.refresh()+ catalogUpdatesFlow.value = catalog.updatesFor(installedRepo.updatable.value)++ // Direct DB read, not packageIndex.value: the flow's StateFlow cache starts+ // empty until Room emits, so a cold-start check reading .value sees no+ // packages and asks Play about every installed app.+ val index = catalog.indexSnapshot()+ val installed = installedRepo.updatable.value+ if (AppSource.PLAYSTORE in enabled) {+ val playCandidates = installed+ .filter { it.packageName !in index }+ .map { it.packageName }+ // Fail soft: a refused/failed lookup (null) keeps the previous Play+ // rows rather than wiping valid updates. Only an answered lookup+ // (even an empty one) clears.+ val remote = play.detailsOrNull(playCandidates)+ if (remote != null) {+ val byPackage = remote.associateBy { it.packageName }+ playUpdatesFlow.value = installed.mapNotNull { inst ->+ byPackage[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+ }+ }+ } else {+ // A check with Play off must not leave a stale snapshot behind (#845).+ playUpdatesFlow.value = emptyList()+ }++ if (AppSource.ACCRESCENT in enabled) {+ accrescent.refreshRepoData()+ val accrescentIds = accrescent.appIds()+ accrescentUpdatesFlow.value = installed+ .filter { it.packageName in accrescentIds }+ .mapNotNull { inst -> accrescentUpdate(inst.packageName, inst.versionCode) }+ } else {+ accrescentUpdatesFlow.value = emptyList()+ }++ lastUpdateCheckFlow.value = System.currentTimeMillis()+ statusMessageFlow.value = ""+ } finally {+ // An escaping failure must not wedge the tab mid-check.+ isCheckingUpdatesFlow.value = false+ }+ }+}++/**+ * Update everything, sequentially, and report the run once when it is over. Mirrors the+ * phone's `updateAllImpl`: concurrent system dialogs would bury the user in prompts,+ * and failures are collected and summarised instead of one snackbar per app.+ */+internal fun TvStoreViewModel.updateAllImpl() {+ if (updateAllJob?.isActive == true) return+ updateAllJob = viewModelScope.launch {+ val batch = updatesUi.value.updates+ if (batch.isEmpty()) return@launch+ var started = 0+ val failures = mutableListOf<String>()+ var repeats = 0+ var previousReason: String? = null+ InstallFailureBatch.begin()+ try {+ for ((index, app) in batch.withIndex()) {+ statusMessageFlow.value = context.getString(+ R.string.updates_progress, app.name, index + 1, batch.size+ )+ val outcome = installer.install(app)+ if (outcome.started) {+ started+++ previousReason = null+ repeats = 0+ } else {+ val failure = when (val verdict = outcome.verification) {+ is VerificationResult.Rejected -> verdict.reason+ is VerificationResult.Unverified -> verdict.reason+ is VerificationResult.Verified ->+ context.getString(R.string.install_failure_unknown)+ }+ failures += failure+ repeats = if (failure == previousReason) repeats + 1 else 1+ previousReason = failure+ if (repeats >= REPEATED_FAILURE_LIMIT) break+ }+ }+ // PackageInstaller commits asynchronously: wait for the last verdict before+ // summarising, or it lands on its own afterwards.+ delay(INSTALL_SETTLE_MS)+ } finally {+ statusMessageFlow.value = ""+ failures += InstallFailureBatch.end()+ }++ AppMessages.show(+ if (failures.isEmpty()) {+ context.resources.getQuantityString(+ R.plurals.updates_batch_installed, started, started+ )+ } else {+ context.getString(+ R.string.updates_batch_partial,+ started,+ batch.size,+ failures.first(),+ )+ },+ duration = if (failures.isEmpty()) {+ AppMessages.Duration.Short+ } else {+ AppMessages.Duration.Long+ },+ )+ installedRepo.refresh()+ }+}++/**+ * The available Accrescent update for [packageName] as an installable listing, or null+ * when there is none. Same shape as the phone's helper: the version code is the+ * update's, so the updates filter keeps it only while genuinely newer.+ */+private suspend fun TvStoreViewModel.accrescentUpdate(+ packageName: String,+ currentVersionCode: Long,+): UnifiedApp? {+ val update = runCatching {+ accrescent.updateInfo(packageName, currentVersionCode)+ }.getOrNull() ?: return null+ val details = accrescent.details(packageName) ?: UnifiedApp(+ packageName = packageName,+ source = AppSource.ACCRESCENT,+ name = packageName.substringAfterLast('.'),+ )+ return details.copy(versionCode = update.versionCode, versionName = update.versionName)+}++private const val SEARCH_DEBOUNCE_MS = 350L+private const val INSTALL_SETTLE_MS = 1_500L+/** How many times in a row an update may fail for the same reason before the run ends. */+private const val REPEATED_FAILURE_LIMIT = 3
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.ktindex fd69cb9135..db28fe3439 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSearch.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSearch.kt@@ -1,13 +1,10 @@ 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@@ -18,32 +15,34 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.unit.dp+import androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text import com.vayunmathur.appstore.R import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.appstore.ui.labelRes 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.TvGrid 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.tv.tvFullWidth 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 TV search hub: a D-pad text field, source-filter chips, and the+ * local-then-remote merged results as a 3-column grid of full-information 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.+ * One scrolling grid owns everything — the field and chips are full-width grid+ * items — so DOWN from the field lands on the chips and DOWN again on results.+ * 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 — and a Play refusal (e.g. 429) is said above the results, never a+ * silent gap. Mirrors the phone's Search page. */ @Composable fun TvStoreSearch(@@ -73,105 +72,90 @@ internal fun TvStoreSearchScreen( onFilterChange: (SourceFilter) -> Unit = {}, onAppClick: (UnifiedApp) -> Unit = {}, ) {- val fieldFocus = remember(state.query) { FocusRequester() }+ val fieldFocus = remember { 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),- )+ // Unkeyed: runs once. Keying on the query would yank focus back to the+ // field on every keystroke.+ TvInitialFocus(fieldFocus)+ TvGrid(columns = 3, modifier = modifier.fillMaxSize()) {+ tvFullWidth(key = "header") {+ TvScreenHeader(title = stringResource(R.string.nav_search))+ }+ tvFullWidth(key = "field") {+ 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(bottom = 4.dp),+ )+ }+ tvFullWidth(key = "filters") {+ TvStoreSearchFilters(filter = state.filter, onFilterChange = onFilterChange)+ } if (playError != null) {- TvStoreNoticeLine(text = playError, isError = true)+ tvFullWidth(key = "play-error") {+ Text(+ text = playError,+ style = MaterialTheme.typography.bodyMedium,+ color = MaterialTheme.colorScheme.error,+ )+ } } when {- state.query.isBlank() -> TvEmptyState(- title = stringResource(R.string.search_prompt_title),- body = stringResource(R.string.tv_search_prompt_tv),- icon = { IconSearch() },- )+ state.query.isBlank() -> tvFullWidth(key = "prompt") {+ 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- },- )+ tvFullWidth(key = "loading") {+ TvLoading(label = stringResource(R.string.sync_in_progress)) }+ state.results.isEmpty() -> tvFullWidth(key = "no-results") {+ TvEmptyState(+ title = stringResource(R.string.search_no_results_title, state.query),+ body = stringResource(R.string.search_no_results_message),+ icon = { IconPackage() },+ )+ }+ else -> items(state.results, key = { it.packageName }) { app ->+ TvStoreAppCard(+ app = app,+ onClick = { onAppClick(app) },+ installedIcon = state.installedIcons[app.packageName],+ isInstalled = app.packageName in state.installedPackages,+ stage = state.stages[app.packageName],+ ) } } } } -/** Source-filter chips as a focusable D-pad row; LEFT/RIGHT moves, DOWN drops to results. */+/** Source-filter chips as a focusable D-pad row in one full-width grid item. */ @Composable-private fun TvStoreSourceFilters(+private fun TvStoreSearchFilters( filter: SourceFilter, onFilterChange: (SourceFilter) -> Unit, modifier: Modifier = Modifier, ) { Row(- modifier- .fillMaxWidth()- .padding(start = tvContentStart(), end = TvDimens.SafeHorizontal),+ modifier.fillMaxWidth().padding(vertical = 4.dp), horizontalArrangement = Arrangement.spacedBy(10.dp), ) { for (entry in SourceFilter.entries) { TvChip(- label = stringResource(entry.tvLabelRes()),+ label = stringResource(entry.labelRes()), 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/TvStoreSources.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSources.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSources.ktnew file mode 100644index 0000000000..e52d05dd60--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreSources.kt@@ -0,0 +1,110 @@+package com.vayunmathur.appstore.tv++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+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 androidx.tv.material3.MaterialTheme+import androidx.tv.material3.Text+import com.vayunmathur.appstore.R+import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.DefaultRepos+import com.vayunmathur.appstore.data.ModernAppsRepo+import com.vayunmathur.appstore.data.accrescent.AccrescentRepo+import com.vayunmathur.library.tv.TvGrid+import com.vayunmathur.library.tv.TvScreenHeader+import com.vayunmathur.library.tv.TvSwitchRow+import com.vayunmathur.library.tv.tvFullWidth++/**+ * Which sources the store talks to at all. Mirrors the phone's Sources page: the+ * auto-install switch plus one switch row per source, in the same order. The source+ * list is fixed — see DefaultRepos for why nothing can be added to it.+ */+@Composable+fun TvStoreSources(+ viewModel: TvStoreViewModel,+ modifier: Modifier = Modifier,+) {+ val enabledSources by viewModel.enabledSourcesFlow.collectAsState()+ val autoInstallUpdates by viewModel.autoInstallUpdates.collectAsState()+ TvStoreSourcesScreen(+ enabledSources = enabledSources,+ autoInstallUpdates = autoInstallUpdates,+ onSetSourceEnabled = viewModel::setSourceEnabled,+ onSetAutoInstall = viewModel::setAutoInstallUpdates,+ modifier = modifier,+ )+}++@Composable+internal fun TvStoreSourcesScreen(+ enabledSources: Set<AppSource>,+ autoInstallUpdates: Boolean,+ modifier: Modifier = Modifier,+ onSetSourceEnabled: (AppSource, Boolean) -> Unit = { _, _ -> },+ onSetAutoInstall: (Boolean) -> Unit = {},+) {+ val noneEnabled = AppSource.TOGGLEABLE.none { it in enabledSources }+ TvGrid(columns = 1, modifier = modifier.fillMaxSize()) {+ tvFullWidth(key = "header") {+ TvScreenHeader(title = stringResource(R.string.nav_sources))+ }+ if (noneEnabled) {+ tvFullWidth(key = "none") {+ Text(+ text = stringResource(R.string.sources_all_disabled),+ style = MaterialTheme.typography.bodyLarge,+ color = MaterialTheme.colorScheme.error,+ modifier = Modifier.padding(vertical = 8.dp),+ )+ }+ }+ tvFullWidth(key = "auto") {+ TvSwitchRow(+ headline = stringResource(R.string.setting_auto_install_updates_title),+ supporting = stringResource(R.string.setting_auto_install_updates_summary),+ checked = autoInstallUpdates,+ onCheckedChange = onSetAutoInstall,+ )+ }+ for (source in SOURCES_IN_ORDER) {+ tvFullWidth(key = "source-${source.source.name}") {+ TvSwitchRow(+ headline = stringResource(source.titleRes),+ supporting = source.subtitle,+ checked = source.source in enabledSources,+ onCheckedChange = { onSetSourceEnabled(source.source, it) },+ )+ }+ }+ }+}++/** The phone's Sources page order, with the same titles and subtitles. */+private data class TvSourceRow(+ val source: AppSource,+ val titleRes: Int,+ val subtitle: String,+)++private val SOURCES_IN_ORDER = listOf(+ TvSourceRow(AppSource.MODERN_APPS, R.string.source_modern_apps, ModernAppsRepo.PROJECT_URL),+ TvSourceRow(AppSource.FDROID, R.string.source_chip_fdroid, DefaultRepos.FDROID.url),+ TvSourceRow(+ AppSource.PROPRIETARY,+ R.string.source_chip_proprietary,+ DefaultRepos.PROPRIETARY.url,+ ),+ TvSourceRow(AppSource.PLAYSTORE, R.string.source_play, "play.google.com"),+ TvSourceRow(+ AppSource.ACCRESCENT,+ R.string.source_chip_accrescent,+ AccrescentRepo.REPOSITORY_URL,+ ),+)
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.ktdeleted file mode 100644index 11c9164259..0000000000--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreTiles.kt+++ /dev/null@@ -1,235 +0,0 @@-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.ktindex ad5a346e51..de1bcc1285 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUiState.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUiState.kt@@ -1,5 +1,6 @@ package com.vayunmathur.appstore.tv +import android.graphics.drawable.Drawable import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.InstalledInfo import com.vayunmathur.appstore.data.UnifiedApp@@ -7,21 +8,42 @@ 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. */+/**+ * One titled row on the TV home screen. Same shape as the phone's `AppSection`:+ * the title and subtitle are the phone's own section strings, so the TV rows read+ * exactly like the phone's.+ */ data class TvSection( val id: String, val title: String,- val apps: List<UnifiedApp>,+ val subtitle: String? = null,+ val source: AppSource? = null,+ val apps: List<UnifiedApp> = emptyList(), ) -/** Everything the TV browse screen draws. */+/** Everything the TV home screen draws. Same shape as the phone's `HomeUiState`. */ data class TvHomeUiState( val sections: List<TvSection> = emptyList(),+ val categories: List<String> = emptyList(),+ val selectedCategory: String? = null,+ val updateCount: Int = 0,+ /** Packages with a pending update, so cards can badge Update over Installed. */+ val updatePackages: Set<String> = emptySet(),+ val installedPackages: Set<String> = emptySet(),+ val installedIcons: Map<String, Drawable> = emptyMap(),+ val stages: Map<String, InstallStage> = emptyMap(), val isLoading: Boolean = false, val statusMessage: String = "",+)++/** Everything the TV browse screen draws. Same shape as the phone's `BrowseUiState`. */+data class TvBrowseUiState(+ val sectionId: String = "",+ val title: String = "",+ val apps: List<UnifiedApp> = emptyList(),+ val isLoading: Boolean = false, 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 installedIcons: Map<String, Drawable> = emptyMap(), val stages: Map<String, InstallStage> = emptyMap(), ) @@ -30,6 +52,7 @@ data class TvLibraryUiState( val apps: List<UnifiedApp> = emptyList(), val filter: SourceFilter = SourceFilter.ALL, val counts: Map<SourceFilter, Int> = emptyMap(),+ val installedIcons: Map<String, Drawable> = emptyMap(), ) internal data class TvLibraryInputs(@@ -44,6 +67,7 @@ data class TvDetailUiState( val app: UnifiedApp? = null, val installedInfo: InstalledInfo? = null, val stage: InstallStage? = null,+ val installedIcon: Drawable? = null, val verification: VerificationResult? = null, /** True while richer Play/Accrescent details are being fetched over the network. */ val isLoadingDetails: Boolean = false,@@ -68,12 +92,14 @@ data class TvSearchUiState( */ val playError: String = "", val installedPackages: Set<String> = emptySet(),+ val installedIcons: Map<String, Drawable> = emptyMap(), 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(),+ val installedIcons: Map<String, Drawable> = emptyMap(), /** 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(),
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.ktindex b566992e30..e19c728331 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUpdates.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreUpdates.kt@@ -1,14 +1,8 @@ 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.foundation.lazy.grid.items import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState@@ -16,33 +10,29 @@ 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.TvGrid 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.tv.tvFullWidth+import com.vayunmathur.library.tv.tvGridHeader 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.+ * The TV updates hub: pending updates as a grid of full-information cards with+ * old → new version lines, a per-card Update action, 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.+ * Mirrors the phone's UpdatesPage: ope
Diff truncated.