From 6699202d35a2fe141efceadf5786a9b60b123704 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 24 Oct 2026 05:54:34 +0000 Subject: [PATCH] app: keep lists while refreshing The superuser, log and module lists are refreshed whenever their tab is shown, when returning to the main screen, after configuration changes, and on other events (the module list on every activity start, the logs on every superuser request). Each refresh set the loading flag, which replaced the list with a spinner, so the list lost its scroll position and expanded cards collapsed. Module update buttons also disappeared until update info was fetched again. The DenyList even scanned every installed app again on rotation. Only show the loading state until the first load finishes, keep update info of unchanged modules across refreshes, and scan apps for the DenyList only once per screen. Assisted-by: Claude Opus 5.5 --- .../magisk/ui/deny/DenyListViewModel.kt | 3 +++ .../com/topjohnwu/magisk/ui/log/LogViewModel.kt | 3 ++- .../magisk/ui/module/ModuleViewModel.kt | 16 ++++++++++++++-- .../magisk/ui/superuser/SuperuserViewModel.kt | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt index c74953920..61a76e313 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListViewModel.kt @@ -181,6 +181,9 @@ class DenyListViewModel : AsyncLoadViewModel() { } override suspend fun doLoadWork() { + // Scanning every app is slow and resets the list, so only do it once: this is called + // again whenever the screen is recreated, e.g. on rotation + if (_allApps.value.isNotEmpty()) return _loading.value = true val apps = withContext(Dispatchers.Default) { val pm = AppContext.packageManager diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt index 667aff472..a87873035 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/log/LogViewModel.kt @@ -47,7 +47,8 @@ class LogViewModel( private var magiskLogRaw = "" override suspend fun doLoadWork() { - _uiState.update { it.copy(loading = true) } + // Keep showing the current list while refreshing: loading is only true until the first + // load finishes, so a refresh doesn't swap the list for a spinner and lose its scroll withContext(Dispatchers.Default) { magiskLogRaw = repo.fetchMagiskLogs() val suLogs = if (Info.env.isActive) repo.fetchSuLogs() else emptyList() diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index 699582e4d..81cf0d7c4 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -83,12 +83,24 @@ class ModuleViewModel : AsyncLoadViewModel() { } override suspend fun doLoadWork() { - _uiState.update { it.copy(loading = true) } + // Keep showing the current list while refreshing: loading is only true until the first + // load finishes, so a refresh doesn't swap the list for a spinner and lose its scroll val moduleLoaded = Info.env.isActive && withContext(Dispatchers.IO) { LocalModule.loaded() } if (moduleLoaded) { + val previous = _uiState.value.modules.associateBy { it.module.base.name } val modules = withContext(Dispatchers.Default) { - LocalModule.installed().map { ModuleItem(it) } + LocalModule.installed().map { module -> + // Keep the update info of the same module version until it is fetched + // again, so update buttons don't disappear on every refresh + previous[module.base.name]?.module + ?.takeIf { it.versionCode == module.versionCode } + ?.let { + module.updateInfo = it.updateInfo + module.outdated = it.outdated + } + ModuleItem(module) + } } _uiState.update { it.copy(loading = false, modules = modules) } loadUpdateInfo() diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 146da0e42..324b9e486 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -75,7 +75,8 @@ class SuperuserViewModel( _uiState.update { it.copy(loading = false) } return } - _uiState.update { it.copy(loading = true) } + // Keep showing the current list while refreshing: loading is only true until the first + // load finishes, so a refresh doesn't swap the list for a spinner and lose its scroll writeLock.withLock { val loaded = withContext(Dispatchers.IO) { db.deleteOutdated()