@@ -17,6 +17,7 @@ import androidx.compose.foundation.lazy.LazyColumn
1717import androidx.compose.foundation.lazy.items
1818import androidx.compose.material.icons.Icons
1919import androidx.compose.material.icons.automirrored.outlined.OpenInNew
20+ import androidx.compose.material.icons.outlined.Cancel
2021import androidx.compose.material.icons.outlined.FileDownload
2122import androidx.compose.material.icons.outlined.PostAdd
2223import androidx.compose.material.icons.outlined.Save
@@ -45,6 +46,7 @@ import app.revanced.manager.R
4546import app.revanced.manager.data.room.apps.installed.InstallType
4647import app.revanced.manager.ui.component.AppScaffold
4748import app.revanced.manager.ui.component.AppTopBar
49+ import app.revanced.manager.ui.component.ConfirmDialog
4850import app.revanced.manager.ui.component.InstallerStatusDialog
4951import app.revanced.manager.ui.component.haptics.HapticExtendedFloatingActionButton
5052import app.revanced.manager.ui.component.patcher.InstallPickerDialog
@@ -58,25 +60,23 @@ import app.revanced.manager.util.EventEffect
5860@Composable
5961fun PatcherScreen (
6062 onBackClick : () -> Unit ,
61- vm : PatcherViewModel
63+ viewModel : PatcherViewModel
6264) {
63- fun leaveScreen () {
64- vm.onBack()
65- onBackClick()
66- }
67- BackHandler (onBack = ::leaveScreen)
6865
6966 val context = LocalContext .current
7067 val exportApkLauncher =
71- rememberLauncherForActivityResult(CreateDocument (APK_MIMETYPE ), vm ::export)
68+ rememberLauncherForActivityResult(CreateDocument (APK_MIMETYPE ), viewModel ::export)
7269
73- val patcherSucceeded by vm .patcherSucceeded.observeAsState(null )
74- val canInstall by remember { derivedStateOf { patcherSucceeded == true && (vm .installedPackageName != null || ! vm .isInstalling) } }
70+ val patcherSucceeded by viewModel .patcherSucceeded.observeAsState(null )
71+ val canInstall by remember { derivedStateOf { patcherSucceeded == true && (viewModel .installedPackageName != null || ! viewModel .isInstalling) } }
7572 var showInstallPicker by rememberSaveable { mutableStateOf(false ) }
73+ var showDismissConfirmationDialog by rememberSaveable { mutableStateOf(false ) }
74+
75+ BackHandler (onBack = { showDismissConfirmationDialog = true })
7676
7777 val steps by remember {
7878 derivedStateOf {
79- vm .steps.groupBy { it.category }
79+ viewModel .steps.groupBy { it.category }
8080 }
8181 }
8282
@@ -93,34 +93,47 @@ fun PatcherScreen(
9393 if (showInstallPicker)
9494 InstallPickerDialog (
9595 onDismiss = { showInstallPicker = false },
96- onConfirm = vm::install
96+ onConfirm = viewModel::install
97+ )
98+
99+ if (showDismissConfirmationDialog) {
100+ ConfirmDialog (
101+ onDismiss = { showDismissConfirmationDialog = false },
102+ onConfirm = {
103+ viewModel.onBack()
104+ onBackClick()
105+ },
106+ title = stringResource(R .string.patcher_stop_confirm_title),
107+ description = stringResource(R .string.patcher_stop_confirm_description),
108+ icon = Icons .Outlined .Cancel
97109 )
110+ }
98111
99- vm .packageInstallerStatus?.let {
100- InstallerStatusDialog (it, vm, vm ::dismissPackageInstallerDialog)
112+ viewModel .packageInstallerStatus?.let {
113+ InstallerStatusDialog (it, viewModel, viewModel ::dismissPackageInstallerDialog)
101114 }
102115
103116 val activityLauncher = rememberLauncherForActivityResult(
104117 contract = ActivityResultContracts .StartActivityForResult (),
105- onResult = vm ::handleActivityResult
118+ onResult = viewModel ::handleActivityResult
106119 )
107- EventEffect (flow = vm .launchActivityFlow) { intent ->
120+ EventEffect (flow = viewModel .launchActivityFlow) { intent ->
108121 activityLauncher.launch(intent)
109122 }
110123
111- vm .activityPromptDialog?.let { title ->
124+ viewModel .activityPromptDialog?.let { title ->
112125 AlertDialog (
113- onDismissRequest = vm ::rejectInteraction,
126+ onDismissRequest = viewModel ::rejectInteraction,
114127 confirmButton = {
115128 TextButton (
116- onClick = vm ::allowInteraction
129+ onClick = viewModel ::allowInteraction
117130 ) {
118131 Text (stringResource(R .string.continue_))
119132 }
120133 },
121134 dismissButton = {
122135 TextButton (
123- onClick = vm ::rejectInteraction
136+ onClick = viewModel ::rejectInteraction
124137 ) {
125138 Text (stringResource(R .string.cancel))
126139 }
@@ -137,20 +150,20 @@ fun PatcherScreen(
137150 AppTopBar (
138151 title = stringResource(R .string.patcher),
139152 scrollBehavior = scrollBehavior,
140- onBackClick = ::leaveScreen
153+ onBackClick = { showDismissConfirmationDialog = true }
141154 )
142155 },
143156 bottomBar = {
144157 BottomAppBar (
145158 actions = {
146159 IconButton (
147- onClick = { exportApkLauncher.launch(" ${vm .packageName} _${vm .version} _revanced_patched.apk" ) },
160+ onClick = { exportApkLauncher.launch(" ${viewModel .packageName} _${viewModel .version} _revanced_patched.apk" ) },
148161 enabled = patcherSucceeded == true
149162 ) {
150163 Icon (Icons .Outlined .Save , stringResource(id = R .string.save_apk))
151164 }
152165 IconButton (
153- onClick = { vm .exportLogs(context) },
166+ onClick = { viewModel .exportLogs(context) },
154167 enabled = patcherSucceeded != null
155168 ) {
156169 Icon (Icons .Outlined .PostAdd , stringResource(id = R .string.save_logs))
@@ -161,11 +174,11 @@ fun PatcherScreen(
161174 HapticExtendedFloatingActionButton (
162175 text = {
163176 Text (
164- stringResource(if (vm .installedPackageName == null ) R .string.install_app else R .string.open_app)
177+ stringResource(if (viewModel .installedPackageName == null ) R .string.install_app else R .string.open_app)
165178 )
166179 },
167180 icon = {
168- vm .installedPackageName?.let {
181+ viewModel .installedPackageName?.let {
169182 Icon (
170183 Icons .AutoMirrored .Outlined .OpenInNew ,
171184 stringResource(R .string.open_app)
@@ -176,10 +189,10 @@ fun PatcherScreen(
176189 )
177190 },
178191 onClick = {
179- if (vm .installedPackageName == null )
180- if (vm .isDeviceRooted()) showInstallPicker = true
181- else vm .install(InstallType .DEFAULT )
182- else vm .open()
192+ if (viewModel .installedPackageName == null )
193+ if (viewModel .isDeviceRooted()) showInstallPicker = true
194+ else viewModel .install(InstallType .DEFAULT )
195+ else viewModel .open()
183196 }
184197 )
185198 }
@@ -193,7 +206,7 @@ fun PatcherScreen(
193206 .fillMaxSize()
194207 ) {
195208 LinearProgressIndicator (
196- progress = { vm .progress },
209+ progress = { viewModel .progress },
197210 modifier = Modifier .fillMaxWidth()
198211 )
199212
@@ -209,8 +222,8 @@ fun PatcherScreen(
209222 Steps (
210223 category = category,
211224 steps = steps,
212- stepCount = if (category == StepCategory .PATCHING ) vm .patchesProgress else null ,
213- stepProgressProvider = vm
225+ stepCount = if (category == StepCategory .PATCHING ) viewModel .patchesProgress else null ,
226+ stepProgressProvider = viewModel
214227 )
215228 }
216229 }
0 commit comments