@@ -72,9 +72,8 @@ class AccessControlViewModel(
7272 val apps : List <AppInfo > = emptyList(),
7373 val selectedPackages : Set <String > = emptySet(),
7474 /* *
75- * Snapshot of the selected packages taken when the screen loads. Selected-first sorting
76- * only ever looks at this snapshot, so toggling apps never reorders the visible list —
77- * newly selected apps float to the top on the next screen entry instead.
75+ * Selection snapshot used for ordering the currently visible list. It is refreshed when
76+ * the screen is entered, so changing a checkbox does not immediately move that row.
7877 */
7978 val initialSelectedPackages : Set <String > = emptySet(),
8079 val searchQuery : String = " " ,
@@ -183,6 +182,20 @@ class AccessControlViewModel(
183182 }
184183 }
185184
185+ /* *
186+ * Synchronize selection-related state when the screen becomes visible again. The ViewModel is
187+ * activity-scoped by the Compose Koin owner, so navigating away does not recreate it.
188+ */
189+ fun refreshSelection () {
190+ val selectedPackages = settings.accessControlPackages.value
191+ _uiState .update { state ->
192+ state.copy(
193+ selectedPackages = selectedPackages,
194+ initialSelectedPackages = selectedPackages,
195+ )
196+ }
197+ }
198+
186199 private fun loadInstalledApps (): List <AppInfo > {
187200 val pm = getApplication<Application >().packageManager
188201 val selfPackageName = getApplication<Application >().packageName
0 commit comments