Skip to content

Commit bbfaab8

Browse files
committed
fix: Home screen buttons always showed shimmer when fresh install
1 parent f442d28 commit bbfaab8

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

app/src/main/java/app/morphe/manager/ui/viewmodel/HomeViewModel.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,13 @@ class HomeViewModel(
459459
viewModelScope.launch {
460460
combine(
461461
patchBundleRepository.bundleUpdateProgress,
462-
installedAppRepository.getAll()
463-
) { progress, installedApps ->
462+
installedAppRepository.getAll(),
463+
availablePatches
464+
) { progress, installedApps, patchCount ->
464465
val isBundleUpdateInProgress =
465466
progress?.result == PatchBundleRepository.BundleUpdateResult.None
466-
isBundleUpdateInProgress || installedApps.isEmpty()
467+
val hasLoadedData = installedApps.isNotEmpty() || patchCount > 0
468+
isBundleUpdateInProgress || !hasLoadedData
467469
}.collect { loading ->
468470
installedAppsLoading = loading
469471
}
@@ -481,14 +483,20 @@ class HomeViewModel(
481483
installedAppRepository.getAll(),
482484
patchBundleRepository.sources,
483485
patchBundleRepository.bundleUpdateProgress
484-
) { installedApps, sources, _ ->
485-
installedApps to sources
486+
) { installedApps, sources, progress ->
487+
// Only trigger after a completed update (Success/NoUpdates) or on initial load
488+
// (progress == null). Never trigger mid-update (None) to avoid checking against
489+
// incomplete bundle data.
490+
val updateCompleted = progress == null ||
491+
progress.result == PatchBundleRepository.BundleUpdateResult.Success ||
492+
progress.result == PatchBundleRepository.BundleUpdateResult.NoUpdates
493+
Triple(installedApps, sources, updateCompleted)
486494
}
487-
.filter { (installedApps, sources) ->
488-
installedApps.isNotEmpty() && sources.isNotEmpty()
495+
.filter { (installedApps, sources, updateCompleted) ->
496+
installedApps.isNotEmpty() && sources.isNotEmpty() && updateCompleted
489497
}
490498
.conflate() // drop intermediate emissions, process only the latest
491-
.collect { (installedApps, _) ->
499+
.collect { (installedApps, _, _) ->
492500
checkInstalledAppsForUpdates(installedApps)
493501
}
494502
}

0 commit comments

Comments
 (0)