Modern Apps git

← Modern-Apps.git

appstore: keep previous Play rows when lookup fails on refresh

Commit
40d65adf8071b04a12b932be049eda523e27f8e3
Author
vayun-mathur <[email protected]>
When
2026-10-23 19:10 UTC (1 month ago)
Parents
3f46825

Diff

appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.ktindex 43980a3233..9b86cd207e 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt@@ -157,7 +157,10 @@ class UpdateCheckWorker(         val unknown = installed             .filter { it.packageName !in index }             .map { it.packageName }-        val remote = env.play.details(unknown).associateBy { it.packageName }+        // Null (lookup failed) reads as no Play contribution here rather than wiping:+        // the worker diffs the merged set against the last notification, so a failed+        // lookup returning rows would silently cancel a standing notification.+        val remote = env.play.detailsOrNull(unknown).orEmpty().associateBy { it.packageName }         return installed.mapNotNull { inst ->             remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }         }
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 7752581e9c..36407a90f9 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@@ -227,6 +227,19 @@ class PlayRepository(private val context: Context) {     suspend fun details(packageNames: List<String>): List<UnifiedApp> =         withFreshApi { it.getDetails(packageNames) }.orEmpty().filterTv() +    /**+     * Like [details], but null when the lookup itself failed (no account could be+     * dispensed, Play refused twice, no network) rather than empty.+     *+     * Lets the update check tell "Play has no updates for these packages" apart from+     * "Play didn't answer": the former clears the Play rows, the latter keeps the+     * previous ones rather than wiping valid updates on a transient failure.+     */+    suspend fun detailsOrNull(packageNames: List<String>): List<UnifiedApp>? {+        if (packageNames.isEmpty()) return emptyList()+        return withFreshApi { it.getDetails(packageNames) }?.filterTv()+    }+     suspend fun topChart(): List<UnifiedApp> =         withFreshApi { it.topChart() }.orEmpty().filterTv() 
appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.ktindex 0cde2c602d..be081ac90d 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/tv/TvStoreViewModel.kt@@ -444,9 +444,15 @@ class TvStoreViewModel(                     val playCandidates = installed                         .filter { it.packageName !in index }                         .map { it.packageName }-                    val remote = play.details(playCandidates).associateBy { it.packageName }-                    playUpdatesFlow.value = installed.mapNotNull { inst ->-                        remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+                    // 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).
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.ktindex 98658c3cfe..d1351010eb 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreUpdateOps.kt@@ -43,13 +43,20 @@ internal fun AppStoreViewModel.checkForUpdatesImpl() {                     .filter { it.packageName !in index }                     .map { it.packageName } -                val remote = play.details(playCandidates).associateBy { it.packageName }-                playUpdatesFlow.value = installed.mapNotNull { inst ->-                    remote[inst.packageName]?.takeIf { it.versionCode > inst.versionCode }+                // Fail soft: a refused/failed lookup (null) keeps the previous Play rows+                // rather than wiping valid updates — "Play didn't answer" is not "Play+                // has no 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 }+                    }+                    // The same response tells us which of these packages Play actually+                    // hosts, which the library uses to tell a genuine Play app from a+                    // sideloaded one.+                    if (byPackage.isNotEmpty()) playInstalledPackagesFlow.value = byPackage.keys.toSet()                 }-                // The same response tells us which of these packages Play actually hosts, which-                // the library uses to tell a genuine Play app from a sideloaded one.-                if (remote.isNotEmpty()) playInstalledPackagesFlow.value = remote.keys.toSet()             } else {                 // A cold-start check with Play off must not leave a stale snapshot behind.                 playUpdatesFlow.value = emptyList()
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 8bb8565221..068307f02f 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -469,8 +469,11 @@ class AppStoreViewModel(             playInstalledPackagesFlow.value = emptySet()             return         }-        val available = play.details(candidates).map { it.packageName }.toSet()-        if (available.isNotEmpty()) playInstalledPackagesFlow.value = available+        // Null (lookup failed) keeps the previous attribution rather than emptying+        // the library; an answered lookup (even empty) replaces it.+        play.detailsOrNull(candidates)?.map { it.packageName }?.toSet()?.let {+            playInstalledPackagesFlow.value = it+        }     }      // (loadAccrescent/accrescentUpdate live in AppStoreUpdateOps.kt.)