appstore: 2-line version label, 429 handling, home update check, browse (#813, #797, #701, #669)
- Commit
438ba490824093839e364fee20f175410ef2862f- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-13 21:10 UTC (1 month ago)
- Parents
6d5f1f3
Diff
appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.ktindex 3d7f613353..b720ab24a6 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/accrescent/AccrescentRepository.kt@@ -104,7 +104,7 @@ class AccrescentRepository( suspend fun search(query: String): List<UnifiedApp> { val q = query.trim().lowercase() if (q.isEmpty()) return emptyList()- ensureAllListingsLoaded()+ runCatching { ensureAllListingsLoaded() }.getOrNull() ?: return emptyList() return listingsCache.values.filter { it.packageName.lowercase().contains(q) || it.name.lowercase().contains(q) ||
appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayRepository.ktindex c746deccf2..dd453b6bf1 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayRepository.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayRepository.kt@@ -8,6 +8,7 @@ import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.data.models.PlayFile+import com.aurora.gplayapi.exceptions.GooglePlayException import com.aurora.gplayapi.helpers.AuthHelper import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.data.searchCandidate@@ -118,19 +119,23 @@ class PlayRepository(private val context: Context) { suspend fun <T> withApi(block: suspend (PlayStoreApi) -> T): T? { val cached = cachedAuthData ?: return null try {- return block(PlayStoreApi(cached, httpClient))+ return block(PlayStoreApi(cached, httpClient)).also { clearPlayError() } } catch (e: CancellationException) { throw e } catch (expected: java.io.IOException) { Log.status(TAG, "Play call failed; cycling anonymous account", expected) } catch (expected: IllegalStateException) { Log.status(TAG, "Play call failed; cycling anonymous account", expected)+ } catch (expected: GooglePlayException) {+ // gplayapi surfaces HTTP failures (e.g. 429 Too Many Requests, issue #797)+ // as GooglePlayException, not IOException. Same cycle-and-retry as the rest.+ Log.status(TAG, "Play call failed (${expected.message}); cycling anonymous account", expected) } invalidate() val fresh = ensureAuth().getOrNull() ?: return null return try {- block(PlayStoreApi(fresh, httpClient))+ block(PlayStoreApi(fresh, httpClient)).also { clearPlayError() } } catch (e: CancellationException) { throw e } catch (expected: java.io.IOException) {@@ -139,6 +144,12 @@ class PlayRepository(private val context: Context) { } catch (expected: IllegalStateException) { Log.status(TAG, "Play call failed again after cycling", expected) null+ } catch (expected: GooglePlayException) {+ // Refused twice, so a retry loop would only hammer it further (issue #797).+ // Record it for the search screen instead of letting it kill the caller.+ Log.status(TAG, "Play call failed again after cycling", expected)+ _authState.value = PlayAuthState.Error(playFailureMessage(expected))+ null } } @@ -229,6 +240,9 @@ class PlayRepository(private val context: Context) { false } catch (_: IllegalStateException) { false+ } catch (_: GooglePlayException) {+ // A validity probe is best-effort: a refusal means "not usable", not a crash.+ false } } @@ -263,9 +277,38 @@ class PlayRepository(private val context: Context) { } } + /**+ * Clear a stale Play failure once a call succeeds, so the status line and the next+ * search stop blaming Play for a refusal that has since cleared.+ */+ private fun clearPlayError() {+ if (_authState.value is PlayAuthState.Error) {+ val cached = cachedAuthData+ _authState.value = if (cached != null) PlayAuthState.Authenticated(cached)+ else PlayAuthState.Idle+ }+ }++ /**+ * Short user-facing reason for a refused Play call (issue #797). The ViewModel wraps+ * this in R.string.play_unavailable, so this is the %1$s half, not a sentence.+ */+ private fun playFailureMessage(e: GooglePlayException): String {+ val code = (e as? GooglePlayException.Unknown)?.code+ return when (code) {+ TOO_MANY_REQUESTS -> "too many requests — try again shortly"+ SERVICE_UNAVAILABLE -> "temporarily unavailable — try again shortly"+ else -> e.message ?: "request failed"+ }+ }+ private companion object { const val TAG = "PlayRepository" + /** gplayapi Unknown codes worth naming in user-facing failure text (issue #797). */+ const val TOO_MANY_REQUESTS = 429+ const val SERVICE_UNAVAILABLE = 503+ /** * How far into Play's search stream to read before giving up on a query. Only * reached when the pages so far hold nothing that answers it.
appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.ktindex 80f0602695..2a284fb5b2 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/play/PlayStoreApi.kt@@ -4,6 +4,7 @@ import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.data.models.PlayFile import com.aurora.gplayapi.data.models.StreamCluster+import com.aurora.gplayapi.exceptions.GooglePlayException import com.aurora.gplayapi.helpers.AppDetailsHelper import com.aurora.gplayapi.helpers.PurchaseHelper import com.aurora.gplayapi.helpers.SearchHelper@@ -39,6 +40,10 @@ class PlayStoreApi( null } catch (_: IllegalStateException) { null+ } catch (_: GooglePlayException) {+ // gplayapi reports HTTP failures (e.g. 429 Too Many Requests, issue #797)+ // as GooglePlayException, not IOException.+ null } } @@ -60,6 +65,10 @@ class PlayStoreApi( emptyList() } catch (_: IllegalStateException) { emptyList()+ } catch (_: GooglePlayException) {+ // gplayapi reports HTTP failures (e.g. 429 Too Many Requests, issue #797)+ // as GooglePlayException, not IOException.+ emptyList() } } }@@ -72,6 +81,11 @@ class PlayStoreApi( * the page behind it. [answered] decides when to stop, so a query that is answered * straight away still costs exactly one request and the extra round trips are spent * only where the alternative was showing the user nothing they asked for.+ *+ * @throws GooglePlayException e.g. Unknown(429) when Play rate-limits (bytesOrThrow,+ * issue #797). Deliberately not caught here: PlayRepository.withApi cycles the shared+ * anonymous account and retries once, then records it so the search screen can explain+ * the missing Play half instead of crashing. */ suspend fun search( query: String,@@ -133,6 +147,10 @@ class PlayStoreApi( emptyList() } catch (_: IllegalStateException) { emptyList()+ } catch (_: GooglePlayException) {+ // gplayapi reports HTTP failures (e.g. 429 Too Many Requests, issue #797)+ // as GooglePlayException, not IOException.+ emptyList() } } @@ -158,6 +176,10 @@ class PlayStoreApi( emptyList() } catch (_: IllegalStateException) { emptyList()+ } catch (_: GooglePlayException) {+ // gplayapi reports HTTP failures (e.g. 429 Too Many Requests, issue #797)+ // as GooglePlayException, not IOException.+ emptyList() } }
appstore/src/main/java/com/vayunmathur/appstore/ui/AppComponents.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppComponents.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppComponents.ktindex 0c4cbe969a..b37a1a1607 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppComponents.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppComponents.kt@@ -39,6 +39,7 @@ import com.vayunmathur.library.ui.IconStar import com.vayunmathur.library.ui.LinearProgressIndicator import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.util.sharedCrop import java.util.Locale @@ -200,7 +201,10 @@ fun AppRow( versionLabel, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant,- maxLines = 1,+ // Old and new versions share one "a (1) → b (2)" line, and long+ // version names ellipsized the tail — the new code — away (#813).+ // Two lines keeps both codes visible.+ maxLines = 2, overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 2.dp), )@@ -215,17 +219,34 @@ fun AppRow( } } -/** Heading above a section of the home screen. */+/** Heading above a section of the home screen, with an optional trailing action. */ @Composable-fun SectionHeader(title: String, subtitle: String?, modifier: Modifier = Modifier) {- Column(modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {- Text(title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)- if (!subtitle.isNullOrBlank()) {- Text(- subtitle,- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )+fun SectionHeader(+ title: String,+ subtitle: String?,+ modifier: Modifier = Modifier,+ /** Label for the header's action button; null draws no button (e.g. in a preview). */+ actionLabel: String? = null,+ onAction: () -> Unit = {},+) {+ Row(+ modifier.padding(horizontal = 16.dp, vertical = 8.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Column(Modifier.weight(1f)) {+ Text(title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)+ if (!subtitle.isNullOrBlank()) {+ Text(+ subtitle,+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ }+ if (actionLabel != null) {+ TextButton(onClick = onAction) {+ Text(actionLabel)+ } } } }
appstore/src/main/java/com/vayunmathur/appstore/ui/HomePage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/HomePage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/HomePage.ktindex 4d19fa633e..38912b1d16 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/HomePage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/HomePage.kt@@ -15,6 +15,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember@@ -52,6 +53,12 @@ fun HomePage( onOpenUpdates: () -> Unit, ) { 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 — so a fresh launch showed the F-Droid count+ // until the user visited that tab (issue #701). Kick off one check from home.+ LaunchedEffect(Unit) {+ viewModel.checkForUpdates()+ } HomeScreen( state = state, actions = viewModel,@@ -142,10 +149,31 @@ fun HomeScreen( state.sections.forEach { section -> item("${section.id}-header") {- SectionHeader(section.title, section.subtitle)+ SectionHeader(+ title = section.title,+ subtitle = section.subtitle,+ actionLabel = browseLabel(section.id == state.expandedSectionId),+ onAction = { actions.toggleSection(section.id) },+ ) }- when (section.layout) {- SectionLayout.CAROUSEL -> item("${section.id}-body") {+ val expanded = section.id == state.expandedSectionId+ when {+ // Browse (issue #669): the carousel's apps as a full vertical list of+ // the same search-style rows, replacing the carousel while expanded.+ expanded -> items(+ section.apps,+ key = { "${section.id}-${it.packageName}" },+ ) { app ->+ AppRow(+ app = app,+ isInstalled = app.packageName in state.installedPackages,+ stage = state.stages[app.packageName],+ installedIcon = state.installedIcons[app.packageName],+ onClick = { onAppClick(app) },+ sharedKey = sharedKeyFor(section, app),+ )+ }+ section.layout == SectionLayout.CAROUSEL -> item("${section.id}-body") { AppCarousel( apps = section.apps, installedPackages = state.installedPackages,@@ -155,7 +183,7 @@ fun HomeScreen( sharedKey = { sharedKeyFor(section, it) }, ) }- SectionLayout.LIST -> items(+ else -> items( section.apps, key = { "${section.id}-${it.packageName}" }, ) { app ->@@ -225,6 +253,12 @@ private fun UpdatesBanner(count: Int, onClick: () -> Unit) { } } +/** Browse/Show-less label for a section header, resolved here so previews stay literal. */+@Composable+private fun browseLabel(expanded: Boolean): String = stringResource(+ if (expanded) R.string.action_show_less else R.string.action_browse+)+ @Composable private fun CategoryRow( categories: List<String>,
appstore/src/main/java/com/vayunmathur/appstore/ui/SearchPage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchPage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchPage.ktindex ebd65c6b53..4761f5fc39 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchPage.kt@@ -31,6 +31,7 @@ import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.FilterChip import com.vayunmathur.library.ui.IconSearch import com.vayunmathur.library.ui.LinearProgressIndicator+import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Scaffold import com.vayunmathur.library.ui.Text @@ -102,6 +103,18 @@ fun SearchScreen( LinearProgressIndicator(Modifier.fillMaxWidth().padding(top = 8.dp)) } + // Play's half refused (429, issue #797): say so above the results rather than+ // silently showing a list that is missing half its sources.+ val playError = state.playError.takeIf { it.isNotBlank() }+ if (playError != null) {+ Text(+ playError,+ style = MaterialTheme.typography.labelSmall,+ color = MaterialTheme.colorScheme.error,+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),+ )+ }+ when { state.query.isBlank() -> EmptyState( title = stringResource(R.string.search_prompt_title),
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreSearchOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreSearchOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreSearchOps.ktindex 082a356219..d5afbf2015 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreSearchOps.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreSearchOps.kt@@ -2,8 +2,10 @@ package com.vayunmathur.appstore.util import com.vayunmathur.appstore.util.AppStoreViewModel.Companion.SEARCH_DEBOUNCE_MS 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.play.PlayAuthState import com.vayunmathur.appstore.data.priority import com.vayunmathur.appstore.data.searchCandidate import com.vayunmathur.appstore.domain.SearchRanking@@ -26,6 +28,7 @@ internal fun AppStoreViewModel.setSearchImpl(query: String) { searchJob = viewModelScope.launch { delay(SEARCH_DEBOUNCE_MS) isSearchingFlow.value = true+ searchPlayErrorFlow.value = "" val enabled = enabledSources.value // Local first and published immediately: the F-Droid catalogue is on disk, so@@ -37,7 +40,13 @@ internal fun AppStoreViewModel.setSearchImpl(query: String) { // carousel (its API has no search RPC), so it adds no network round-trip here. val accrescentResults = if (AppSource.ACCRESCENT in enabled) accrescent.search(query) else emptyList()+ // Play may refuse (429 Too Many Requests, issue #797): withApi records the refusal+ // on authState after cycling the account once, and the local half stays on screen. val remote = if (AppSource.PLAYSTORE in enabled) play.search(query) else emptyList()+ val playError = (play.authState.value as? PlayAuthState.Error)+ ?.let { context.getString(R.string.play_unavailable, it.message) }+ .orEmpty()+ searchPlayErrorFlow.value = playError searchResultsFlow.value = rank(merge(local, remote, accrescentResults), query) isSearchingFlow.value = false hasSearchedFlow.value = true
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUiContract.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUiContract.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUiContract.ktindex bcfd58cf62..5f7315184b 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUiContract.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUiContract.kt@@ -54,6 +54,8 @@ data class HomeUiState( val sections: List<AppSection> = emptyList(), val categories: List<String> = emptyList(), val selectedCategory: String? = null,+ /** Section id expanded into a full list via its Browse button, or null for carousels. */+ val expandedSectionId: String? = null, val updateCount: Int = 0, val installedPackages: Set<String> = emptySet(), val installedIcons: Map<String, Drawable> = emptyMap(),@@ -72,6 +74,11 @@ data class SearchUiState( val isSearching: Boolean = false, /** True once a search has run for [query], so "no results" can be told from "not yet". */ val hasSearched: Boolean = false,+ /**+ * Play's half failed (e.g. rate-limited, issue #797) while the offline half answered.+ * Blank when Play answered or was never asked, so the list alone is the whole story.+ */+ val playError: String = "", val installedPackages: Set<String> = emptySet(), val installedIcons: Map<String, Drawable> = emptyMap(), val stages: Map<String, InstallStage> = emptyMap(),@@ -136,6 +143,12 @@ interface HomeActions : AppActions { fun selectCategory(category: String?) {} fun refresh() {} + /**+ * Expand a carousel section into its full vertical list, or collapse it back.+ * One section at a time — an expanded section owns the screen below its header.+ */+ fun toggleSection(sectionId: String) {}+ companion object { val Noop: HomeActions = object : HomeActions {} }
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.ktindex fccb976607..2c17fe32d8 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -106,12 +106,16 @@ class AppStoreViewModel( internal val categoriesFlow = MutableStateFlow<List<String>>(emptyList()) internal val selectedCategoryFlow = MutableStateFlow<String?>(null) internal val categoryAppsFlow = MutableStateFlow<List<UnifiedApp>>(emptyList())+ /** Section id expanded via its Browse button (issue #669), or null for carousels. */+ internal val expandedSectionFlow = MutableStateFlow<String?>(null) internal val queryFlow = MutableStateFlow("") internal val searchResultsFlow = MutableStateFlow<List<UnifiedApp>>(emptyList()) internal val searchFilterFlow = MutableStateFlow(SourceFilter.ALL) internal val isSearchingFlow = MutableStateFlow(false) internal val hasSearchedFlow = MutableStateFlow(false)+ /** Play's half of the last search failed (e.g. 429, issue #797); shown above the list. */+ internal val searchPlayErrorFlow = MutableStateFlow("") internal val selectedAppFlow = MutableStateFlow<UnifiedApp?>(null) internal val isLoadingDetailsFlow = MutableStateFlow(false)@@ -209,7 +213,9 @@ class AppStoreViewModel( val home: StateFlow<HomeUiState> = combine( sections, categoriesFlow,- selectedCategoryFlow,+ combine(selectedCategoryFlow, expandedSectionFlow) { category, expanded ->+ category to expanded+ }, chrome, combine( updates,@@ -220,11 +226,12 @@ class AppStoreViewModel( ) { u, syncing, loading, msg, playError -> HomeChrome(u.size, syncing, loading, msg.ifBlank { playError }) },- ) { built, categories, category, rows, homeChrome ->+ ) { built, categories, (category, expandedSectionId), rows, homeChrome -> HomeUiState( sections = built, categories = categories, selectedCategory = category,+ expandedSectionId = expandedSectionId, updateCount = homeChrome.updateCount, installedPackages = rows.installedPackages, installedIcons = rows.icons,@@ -242,14 +249,17 @@ class AppStoreViewModel( }, isSearchingFlow, hasSearchedFlow,- chrome,- ) { query, (results, filter), searching, searched, rows ->+ combine(searchPlayErrorFlow, chrome) { playError, rows ->+ playError to rows+ },+ ) { query, (results, filter), searching, searched, (playError, rows) -> SearchUiState( query = query, results = results.filter { filter.source == null || it.source == filter.source }, filter = filter, isSearching = searching, hasSearched = searched,+ playError = playError, installedPackages = rows.installedPackages, installedIcons = rows.icons, stages = rows.stages,@@ -420,6 +430,15 @@ class AppStoreViewModel( } } + /**+ * Expand a carousel section into its full vertical list, or collapse it.+ * One section at a time (issue #669); expanding another moves, not stacks.+ */+ override fun toggleSection(sectionId: String) {+ expandedSectionFlow.value =+ if (expandedSectionFlow.value == sectionId) null else sectionId+ }+ override fun refresh() = syncSources() /** Re-download both offline catalogues, then reload the home rows from them. */
appstore/src/main/res/values/strings.xml
diff --git a/appstore/src/main/res/values/strings.xml b/appstore/src/main/res/values/strings.xmlindex c07f36c139..74381224d4 100644--- a/appstore/src/main/res/values/strings.xml+++ b/appstore/src/main/res/values/strings.xml@@ -31,6 +31,7 @@ <string name="filter_with_count">%1$s (%2$d)</string> <!-- Home. -->+ <string name="action_browse">Browse</string> <string name="section_modern_apps">From Modern Apps</string> <string name="section_modern_apps_subtitle">Built in this repo and signed with the same key as this store</string> <string name="section_play_top_charts">Top on the Play Store</string>