From 78c63772aaadd40c930eb8488e8ca625ef7cad9d Mon Sep 17 00:00:00 2001 From: Rifat Azad Date: Tue, 17 Dec 2024 16:35:49 +0600 Subject: [PATCH] manager: added module install confirmation --- .../me/weishu/kernelsu/ui/screen/Module.kt | 49 +++++++++++++++---- manager/app/src/main/res/values/strings.xml | 3 ++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt index e4449321..4e5575a5 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Module.kt @@ -35,6 +35,7 @@ import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.outlined.PlayArrow import androidx.compose.material.icons.outlined.Download import androidx.compose.material.icons.outlined.Delete +import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ElevatedCard @@ -51,6 +52,7 @@ import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarResult import androidx.compose.material3.Switch import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.pulltorefresh.PullToRefreshBox @@ -124,6 +126,9 @@ fun ModuleScreen(navigator: DestinationsNavigator) { val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) + var zipUri by remember { mutableStateOf(null) } + var showConfirmDialog by remember { mutableStateOf(false) } + Scaffold( topBar = { TopAppBar( @@ -137,18 +142,16 @@ fun ModuleScreen(navigator: DestinationsNavigator) { val moduleInstall = stringResource(id = R.string.module_install) val selectZipLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() - ) { - if (it.resultCode != RESULT_OK) { + ) { result -> + if (result.resultCode != RESULT_OK) { return@rememberLauncherForActivityResult } - val data = it.data ?: return@rememberLauncherForActivityResult + val data = result.data ?: return@rememberLauncherForActivityResult val uri = data.data ?: return@rememberLauncherForActivityResult - navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(uri))) - - viewModel.markNeedRefresh() - - Log.i("ModuleScreen", "select zip result: ${it.data}") + // save the selected Uri and trigger confirmation dialog + zipUri = uri + showConfirmDialog = true } ExtendedFloatingActionButton( @@ -167,6 +170,35 @@ fun ModuleScreen(navigator: DestinationsNavigator) { contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal), snackbarHost = { SnackbarHost(hostState = snackBarHost) } ) { innerPadding -> + // confirmation dialog + if (showConfirmDialog && zipUri != null) { + // extract the module name from the zipUri + val moduleName = zipUri?.lastPathSegment?.substringAfterLast('/') ?: "Unknown Module" + + AlertDialog( + onDismissRequest = { showConfirmDialog = false }, + confirmButton = { + TextButton(onClick = { + showConfirmDialog = false + navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(zipUri!!))) + }) { + Text(stringResource(R.string.confirm)) + } + }, + dismissButton = { + TextButton(onClick = { showConfirmDialog = false }) { + Text(stringResource(android.R.string.cancel)) + } + }, + title = { Text(stringResource(R.string.confirm_module_installation)) }, + text = { + Text( + stringResource(R.string.module_install_prompt_with_name, moduleName) + ) + } + ) + } + when { hasMagisk -> { Box( @@ -181,7 +213,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) { ) } } - else -> { ModuleList( navigator, diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml index 07dce877..de562fd9 100644 --- a/manager/app/src/main/res/values/strings.xml +++ b/manager/app/src/main/res/values/strings.xml @@ -1,5 +1,6 @@ + Confirm KernelSU Next Home Not installed @@ -23,6 +24,8 @@ Failed to disable module: %s No module installed Module + Confirm Installation + Do you want to continue installing this module?\nModule: %1$s Uninstall Install Install