From b98c531ff83015a736fd13a3832e73440c89c1df Mon Sep 17 00:00:00 2001 From: Tiann <4233744+tiann@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:16:21 +0600 Subject: [PATCH] manager: refine flashing module confirm dialog --- .../com/rifsxd/ksunext/ui/screen/Module.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt index 36ec9bab..d59f4241 100644 --- a/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt +++ b/manager/app/src/main/java/com/rifsxd/ksunext/ui/screen/Module.kt @@ -213,6 +213,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() ) { result -> @@ -231,8 +237,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(