[BUGFIX] manager: Fix Module Flashing fails when orientation changes (#503)

The issue is caused by re-rendering of Activity when orientation changes.
All states are reset when it is re-rendered. Using ViewModel to manage zipUri fixes the issue.

Fixes issue: https://github.com/KernelSU-Next/KernelSU-Next/issues/488
This commit is contained in:
Suraj J Pai
2025-06-12 04:14:45 +05:30
committed by GitHub
parent e7697d86fe
commit 7abc9bc821
2 changed files with 20 additions and 2 deletions

View File

@@ -290,8 +290,11 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
val confirmTitle = stringResource(R.string.module)
var zipUris by remember { mutableStateOf<List<Uri>>(emptyList()) }
val confirmDialog = rememberConfirmDialog(onConfirm = {
navigator.navigate(FlashScreenDestination(FlashIt.FlashModules(zipUris)))
viewModel.markNeedRefresh()
if (viewModel.zipUris.isNotEmpty()) {
navigator.navigate(FlashScreenDestination(FlashIt.FlashModules(viewModel.zipUris)))
viewModel.clearZipUris()
viewModel.markNeedRefresh()
}
})
val selectZipLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
@@ -311,6 +314,10 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
data.data?.let { uris.add(it) }
}
if (uris.isEmpty()) return@rememberLauncherForActivityResult
viewModel.updateZipUris(uris)
// Show confirm dialog with selected zip file(s) name(s)
val moduleNames =
uris.mapIndexed { index, uri -> "\n${index + 1}. ${uri.getFileName(context)}" }

View File

@@ -1,5 +1,6 @@
package com.rifsxd.ksunext.ui.viewmodel
import android.net.Uri
import android.os.SystemClock
import android.util.Log
import androidx.compose.runtime.derivedStateOf
@@ -93,6 +94,16 @@ class ModuleViewModel : ViewModel() {
isNeedRefresh = true
}
var zipUris by mutableStateOf<List<Uri>>(emptyList())
fun updateZipUris(uris: List<Uri>) {
zipUris = uris
}
fun clearZipUris() {
zipUris = emptyList()
}
fun fetchModuleList() {
viewModelScope.launch {