From f16184cb5b6a4030b4b25a32cc6a05f1a5d296ea Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Tue, 6 Feb 2024 23:06:59 -0800 Subject: [PATCH] fix abort warning --- .../ui/screens/install/InstallScreen.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt index 840d032e..9cfcc3bc 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/InstallScreen.kt @@ -43,8 +43,20 @@ class InstallScreen : Screen { navigator.back(currentActivity = null) } - // Exit warning dialog (cancel itself if install process state changes) + // Exit warning dialog (dismiss itself if install process state changes, esp. for Success) var showAbortWarning by remember(model.state.collectAsState()) { mutableStateOf(false) } + + // Only show exit warning if currently working + val onTryExit: () -> Unit = remember { + { + if (state.value == InstallScreenState.Working) { + showAbortWarning = true + } else { + navigator.back(currentActivity = null) + } + } + } + if (showAbortWarning) { InstallerAbortDialog( onDismiss = { showAbortWarning = false }, @@ -54,9 +66,7 @@ class InstallScreen : Screen { }, ) } else { - BackHandler { - showAbortWarning = true - } + BackHandler(onBack = onTryExit) } Scaffold( @@ -64,10 +74,7 @@ class InstallScreen : Screen { TopAppBar( title = { Text(stringResource(R.string.installer)) }, navigationIcon = { - IconButton( - // TODO: only show warning when in progress - onClick = { showAbortWarning = true }, - ) { + IconButton(onClick = onTryExit) { Icon( painter = painterResource(R.drawable.ic_back), contentDescription = stringResource(R.string.navigation_back),