From 6e3d5569601e89b3edff657a9c9eec016a0e581a Mon Sep 17 00:00:00 2001 From: weishu Date: Wed, 19 Feb 2025 14:19:42 +0800 Subject: [PATCH] manager: refine flashing module confirm dialog --- .../me/weishu/kernelsu/ui/screen/Module.kt | 55 +++++++------------ 1 file changed, 19 insertions(+), 36 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 d21993db..e7610eab 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 @@ -135,11 +135,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) { val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) - var zipUri by remember { mutableStateOf(null) } - var zipUris by remember { mutableStateOf>(emptyList()) } - - var showConfirmDialog by remember { mutableStateOf(false) } - val webUILauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() ) { viewModel.fetchModuleList() } @@ -208,6 +203,12 @@ fun ModuleScreen(navigator: DestinationsNavigator) { floatingActionButton = { if (!hideInstallButton) { val moduleInstall = stringResource(id = R.string.module_install) + val confirmTitle = stringResource(R.string.module) + var zipUris by remember { mutableStateOf>(emptyList()) } + val confirmDialog = rememberConfirmDialog(onConfirm = { + navigator.navigate(FlashScreenDestination(FlashIt.FlashModules(zipUris))) + viewModel.markNeedRefresh() + }) val selectZipLauncher = rememberLauncherForActivityResult( contract = ActivityResultContracts.StartActivityForResult() ) { @@ -226,8 +227,19 @@ fun ModuleScreen(navigator: DestinationsNavigator) { data.data?.let { uris.add(it) } } - zipUris = uris - showConfirmDialog = uris.isNotEmpty() + if (uris.size == 1) { + navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(uris.first()))) + } else if (uris.size > 1) { + // multiple files selected + val moduleNames = uris.mapIndexed { index, uri -> "\n${index + 1}. ${uri.getFileName(context)}" }.joinToString("") + val confirmContent = context.getString(R.string.module_install_prompt_with_name, moduleNames) + zipUris = uris + confirmDialog.showConfirm( + title = confirmTitle, + content = confirmContent, + markdown = true + ) + } } ExtendedFloatingActionButton( @@ -248,35 +260,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) { snackbarHost = { SnackbarHost(hostState = snackBarHost) } ) { innerPadding -> - // confirmation dialog - if (showConfirmDialog && zipUris.isNotEmpty()) { - val moduleNames = zipUris.joinToString("\n") { it.getFileName(context).toString() } - - AlertDialog( - onDismissRequest = { showConfirmDialog = false }, - confirmButton = { - TextButton(onClick = { - showConfirmDialog = false - navigator.navigate(FlashScreenDestination(FlashIt.FlashModules(zipUris))) - viewModel.markNeedRefresh() - }) { - Text(stringResource(R.string.confirm)) - } - }, - dismissButton = { - TextButton(onClick = { showConfirmDialog = false }) { - Text(stringResource(android.R.string.cancel)) - } - }, - title = { Text(stringResource(R.string.module)) }, - text = { - Text( - stringResource(R.string.module_install_prompt_with_name, moduleNames) - ) - } - ) - } - when { hasMagisk -> { Box(