Modern Apps git

← Modern-Apps.git

appstore: fix detekt findings

Commit
cb414e0df391a1a4da81c920479c819338e41859
Author
Vayun Mathur <[email protected]>
When
2026-11-17 14:54 UTC (18 days ago)
Parents
fcfe5e1
Fixes every error-severity detekt finding in appstore (inventory clusters C3/C4): named constants for magic numbers, extracted functions/composables for long/complex methods, wrapped long lines, removed unused parameters, and narrowed/logged exception handling. No detekt config, baseline or suppression changes; behaviour preserved.

Verified: ./check appstore and :appstore:testDevUnitTest green.

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 55fd583094..49cfc4aec7 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/UpdateCheckWorker.kt@@ -414,7 +414,9 @@ class UpdateCheckWorker(             .setPriority(NotificationCompat.PRIORITY_LOW)             .build()         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU ||-            ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED+            ActivityCompat.checkSelfPermission(+                context, Manifest.permission.POST_NOTIFICATIONS,+            ) == PackageManager.PERMISSION_GRANTED         ) {             runCatching {                 NotificationManagerCompat.from(context).notify(INSTALLED_NOTIFICATION_ID, notification)
appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.ktindex 083e2554e7..5edcdd7e57 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/installer/InstallCoordinator.kt@@ -319,7 +319,8 @@ class InstallCoordinator(         }         once()         if (expectedSize > 0 && target.length() != expectedSize) {-            // Truncated (or over-long): delete first and retry once, since HttpURLConnection will not overwrite cleanly on all devices.+            // Truncated (or over-long): delete first and retry once, since HttpURLConnection+            // will not overwrite cleanly on all devices.             target.delete()             once()             if (target.length() != expectedSize) {@@ -441,7 +442,10 @@ class InstallCoordinator(                     expectedSha256 = emptyMap(),                     minVersionCode = trust.minVersionCode,                     signerOrigin = "Accrescent's signed app list",-                    // Server is the authority for Accrescent: it already picks splits per-device, so a client-side leanback refusal would second-guess it (mirrors the tvRefusal() exemption); every other source keeps the TV-compatibility requirement from isTv.+                    // Server is the authority for Accrescent: it already picks splits per-device,+                    // so a client-side leanback refusal would second-guess it (mirrors the+                    // tvRefusal() exemption); every other source keeps the TV-compatibility+                    // requirement from isTv.                     requireTvCompatible = false,                 ) 
appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreHomeOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreHomeOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreHomeOps.ktindex 27fa1e3d6a..a4a4f3a730 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreHomeOps.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreHomeOps.kt@@ -35,7 +35,11 @@ internal suspend fun AppStoreViewModel.loadHome(enabled: Set<AppSource> = enable  private suspend fun AppStoreViewModel.loadOfflineRecents(enabled: Set<AppSource>) {     suspend fun recentOrEmpty(source: AppSource): List<UnifiedApp> =-        if (source in enabled) catalog.recentlyUpdatedBySource(source, AppStoreViewModel.RECENT_PER_SOURCE_LIMIT) else emptyList()+        if (source in enabled) {+            catalog.recentlyUpdatedBySource(source, AppStoreViewModel.RECENT_PER_SOURCE_LIMIT)+        } else {+            emptyList()+        }     modernRecentFlow.value = recentOrEmpty(AppSource.MODERN_APPS)     fdroidRecentFlow.value = recentOrEmpty(AppSource.FDROID)     izzyRecentFlow.value = recentOrEmpty(AppSource.IZZY)@@ -272,7 +276,10 @@ private fun AppStoreViewModel.syncReportMessage(report: SyncReport, enabled: Set     val counts = listOf(report.fdroidCount, report.modernCount, report.proprietaryCount, report.izzyCount)     return when {         report.allSkipped -> context.getString(R.string.sync_all_sources_off)-        !report.anyFailed -> context.resources.getQuantityString(R.plurals.sync_done, counts.sumOf { it ?: 0 }, counts.sumOf { it ?: 0 })+        !report.anyFailed -> {+            val synced = counts.sumOf { it ?: 0 }+            context.resources.getQuantityString(R.plurals.sync_done, synced, synced)+        }         counts.all { it == null } -> context.getString(R.string.sync_failed_all)         report.fdroidCount == null -> context.getString(R.string.sync_failed_fdroid)         report.izzyCount == null && AppSource.IZZY in enabled ->
appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreHomeOps.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreHomeOps.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreHomeOps.ktindex 56e4a086f1..cbef6cea1d 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreHomeOps.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreHomeOps.kt@@ -67,7 +67,10 @@ private fun TvStoreViewModel.tvSyncReportMessage(report: SyncReport, enabled: Se     val counts = listOf(report.fdroidCount, report.modernCount, report.proprietaryCount, report.izzyCount)     return when {         report.allSkipped -> context.getString(R.string.sync_all_sources_off)-        !report.anyFailed -> context.resources.getQuantityString(R.plurals.sync_done, counts.sumOf { it ?: 0 }, counts.sumOf { it ?: 0 })+        !report.anyFailed -> {+            val synced = counts.sumOf { it ?: 0 }+            context.resources.getQuantityString(R.plurals.sync_done, synced, synced)+        }         counts.all { it == null } -> context.getString(R.string.sync_failed_all)         report.fdroidCount == null -> context.getString(R.string.sync_failed_fdroid)         report.izzyCount == null && AppSource.IZZY in enabled ->
appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreViewModel.ktindex 8b1b41572a..1d030417a3 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/TvStoreViewModel.kt@@ -397,24 +397,7 @@ class TvStoreViewModel(             isLoading = true,         )         browseJob = viewModelScope.launch {-            val apps = when {-                sectionId == "category" ->-                    section?.let { catalog.allByCategory(it.title).ifEmpty { it.apps } }-                        ?: emptyList()-                section?.source != null && section.source != AppSource.PLAYSTORE &&-                    section.source != AppSource.ACCRESCENT ->-                    catalog.allBySource(section.source)-                sectionId == "modern" || sectionId == "modern-recent" ->-                    catalog.allBySource(AppSource.MODERN_APPS)-                sectionId == "proprietary-recent" ->-                    catalog.allBySource(AppSource.PROPRIETARY)-                sectionId == "fdroid-recent" ->-                    catalog.allBySource(AppSource.FDROID)-                sectionId == "izzy-recent" ->-                    catalog.allBySource(AppSource.IZZY)-                sectionId == "accrescent" -> accrescent.allListings()-                else -> playFullClustersFlow.value[sectionId] ?: section?.apps ?: emptyList()-            }+            val apps = browseApps(section, sectionId)             browseContentFlow.value = TvBrowseUiState(                 sectionId = sectionId,                 title = title,@@ -424,6 +407,29 @@ class TvStoreViewModel(         }     } +    /** The full catalogue behind one Browse section; see [loadBrowse]. */+    private suspend fun browseApps(section: TvSection?, sectionId: String): List<UnifiedApp> {+        if (sectionId == "category") {+            return section?.let { catalog.allByCategory(it.title).ifEmpty { it.apps } } ?: emptyList()+        }+        val source = section?.source+        if (source != null && source != AppSource.PLAYSTORE && source != AppSource.ACCRESCENT) {+            return catalog.allBySource(source)+        }+        return browseAppsBySectionId(section, sectionId)+    }++    /** The catalogue behind a section named by id, when not by category/source. */+    private suspend fun browseAppsBySectionId(section: TvSection?, sectionId: String): List<UnifiedApp> =+        when (sectionId) {+            "modern", "modern-recent" -> catalog.allBySource(AppSource.MODERN_APPS)+            "proprietary-recent" -> catalog.allBySource(AppSource.PROPRIETARY)+            "fdroid-recent" -> catalog.allBySource(AppSource.FDROID)+            "izzy-recent" -> catalog.allBySource(AppSource.IZZY)+            "accrescent" -> accrescent.allListings()+            else -> playFullClustersFlow.value[sectionId] ?: section?.apps ?: emptyList()+        }+     /** Title for a known section id when home has not (re)built its row yet. */     private fun browseFallbackTitle(sectionId: String): String = when (sectionId) {         "modern", "modern-recent" -> context.getString(R.string.section_modern_apps_recent)