@@ -58,7 +58,6 @@ import androidx.compose.ui.Modifier
5858import androidx.compose.ui.draw.alpha
5959import androidx.compose.ui.draw.rotate
6060import androidx.compose.ui.res.stringResource
61- import androidx.compose.ui.text.style.TextAlign
6261import androidx.compose.ui.unit.dp
6362import androidx.lifecycle.compose.collectAsStateWithLifecycle
6463import app.revanced.manager.R
@@ -88,9 +87,9 @@ import kotlinx.coroutines.launch
8887fun PatchesSelectorScreen (
8988 onSave : (PatchSelection ? , Options ) -> Unit ,
9089 onBackClick : () -> Unit ,
91- vm : PatchesSelectorViewModel
90+ viewModel : PatchesSelectorViewModel
9291) {
93- val bundles by vm .bundlesFlow.collectAsStateWithLifecycle(initialValue = emptyList())
92+ val bundles by viewModel .bundlesFlow.collectAsStateWithLifecycle(initialValue = emptyList())
9493 val pagerState = rememberPagerState(
9594 initialPage = 0 ,
9695 initialPageOffsetFraction = 0f
@@ -106,15 +105,15 @@ fun PatchesSelectorScreen(
106105 }
107106 var showBottomSheet by rememberSaveable { mutableStateOf(false ) }
108107 val showSaveButton by remember {
109- derivedStateOf { vm .selectionIsValid(bundles) }
108+ derivedStateOf { viewModel .selectionIsValid(bundles) }
110109 }
111110
112- val defaultPatchSelectionCount by vm .defaultSelectionCount
111+ val defaultPatchSelectionCount by viewModel .defaultSelectionCount
113112 .collectAsStateWithLifecycle(initialValue = 0 )
114113
115114 val selectedPatchCount by remember {
116115 derivedStateOf {
117- vm .customPatchSelection?.values?.sumOf { it.size } ? : defaultPatchSelectionCount
116+ viewModel .customPatchSelection?.values?.sumOf { it.size } ? : defaultPatchSelectionCount
118117 }
119118 }
120119
@@ -146,58 +145,54 @@ fun PatchesSelectorScreen(
146145 verticalArrangement = Arrangement .spacedBy(12 .dp)
147146 ) {
148147 CheckedFilterChip (
149- selected = vm .filter and SHOW_INCOMPATIBLE == 0 ,
150- onClick = { vm .toggleFlag(SHOW_INCOMPATIBLE ) },
148+ selected = viewModel .filter and SHOW_INCOMPATIBLE == 0 ,
149+ onClick = { viewModel .toggleFlag(SHOW_INCOMPATIBLE ) },
151150 label = { Text (stringResource(R .string.this_version)) }
152151 )
153152
154153 CheckedFilterChip (
155- selected = vm .filter and SHOW_UNIVERSAL != 0 ,
156- onClick = { vm .toggleFlag(SHOW_UNIVERSAL ) },
154+ selected = viewModel .filter and SHOW_UNIVERSAL != 0 ,
155+ onClick = { viewModel .toggleFlag(SHOW_UNIVERSAL ) },
157156 label = { Text (stringResource(R .string.universal)) },
158157 )
159158 }
160159 }
161160 }
162161 }
163162
164- if (vm .compatibleVersions.isNotEmpty())
163+ if (viewModel .compatibleVersions.isNotEmpty())
165164 IncompatiblePatchDialog (
166- appVersion = vm .appVersion ? : stringResource(R .string.any_version),
167- compatibleVersions = vm .compatibleVersions,
168- onDismissRequest = vm ::dismissDialogs
165+ appVersion = viewModel .appVersion ? : stringResource(R .string.any_version),
166+ compatibleVersions = viewModel .compatibleVersions,
167+ onDismissRequest = viewModel ::dismissDialogs
169168 )
170169 var showIncompatiblePatchesDialog by rememberSaveable {
171170 mutableStateOf(false )
172171 }
173172 if (showIncompatiblePatchesDialog)
174173 IncompatiblePatchesDialog (
175- appVersion = vm .appVersion ? : stringResource(R .string.any_version),
174+ appVersion = viewModel .appVersion ? : stringResource(R .string.any_version),
176175 onDismissRequest = { showIncompatiblePatchesDialog = false }
177176 )
178177
179- vm .optionsDialog?.let { (bundle, patch) ->
178+ viewModel .optionsDialog?.let { (bundle, patch) ->
180179 OptionsDialog (
181- onDismissRequest = vm ::dismissDialogs,
180+ onDismissRequest = viewModel ::dismissDialogs,
182181 patch = patch,
183- values = vm .getOptions(bundle, patch),
184- reset = { vm .resetOptions(bundle, patch) },
185- set = { key, value -> vm .setOption(bundle, patch, key, value) }
182+ values = viewModel .getOptions(bundle, patch),
183+ reset = { viewModel .resetOptions(bundle, patch) },
184+ set = { key, value -> viewModel .setOption(bundle, patch, key, value) }
186185 )
187186 }
188187
189- var showSelectionWarning by rememberSaveable {
190- mutableStateOf(false )
191- }
192- if (showSelectionWarning) {
188+ var showSelectionWarning by rememberSaveable { mutableStateOf( false ) }
189+ var showUniversalWarning by rememberSaveable { mutableStateOf(false ) }
190+
191+ if (showSelectionWarning)
193192 SelectionWarningDialog (onDismiss = { showSelectionWarning = false })
194- }
195- vm.pendingUniversalPatchAction?.let {
196- UniversalPatchWarningDialog (
197- onCancel = vm::dismissUniversalPatchWarning,
198- onConfirm = vm::confirmUniversalPatchWarning
199- )
200- }
193+
194+ if (showUniversalWarning)
195+ UniversalPatchWarningDialog (onDismiss = { showUniversalWarning = false })
201196
202197 fun LazyListScope.patchList (
203198 uid : Int ,
@@ -221,27 +216,25 @@ fun PatchesSelectorScreen(
221216 PatchItem (
222217 patch = patch,
223218 onOptionsDialog = {
224- vm .optionsDialog = uid to patch
219+ viewModel .optionsDialog = uid to patch
225220 },
226- selected = compatible && vm .isSelected(
221+ selected = compatible && viewModel .isSelected(
227222 uid,
228223 patch
229224 ),
230225 onToggle = {
231226 when {
232227 // Open incompatible dialog if the patch is not supported
233- ! compatible -> vm .openIncompatibleDialog(patch)
228+ ! compatible -> viewModel .openIncompatibleDialog(patch)
234229
235230 // Show selection warning if enabled
236- vm .selectionWarningEnabled -> showSelectionWarning = true
231+ viewModel .selectionWarningEnabled -> showSelectionWarning = true
237232
238- // Set pending universal patch action if the universal patch warning is enabled and there are no compatible packages
239- vm.universalPatchWarningEnabled && patch.compatiblePackages == null -> {
240- vm.pendingUniversalPatchAction = { vm.togglePatch(uid, patch) }
241- }
233+ // Show universal warning if enabled
234+ viewModel.universalPatchWarningEnabled -> showUniversalWarning = true
242235
243236 // Toggle the patch otherwise
244- else -> vm .togglePatch(uid, patch)
237+ else -> viewModel .togglePatch(uid, patch)
245238 }
246239 },
247240 compatible = compatible
@@ -327,7 +320,7 @@ fun PatchesSelectorScreen(
327320 patchList(
328321 uid = bundle.uid,
329322 patches = bundle.universal.searched(),
330- visible = vm .filter and SHOW_UNIVERSAL != 0 ,
323+ visible = viewModel .filter and SHOW_UNIVERSAL != 0 ,
331324 compatible = true
332325 ) {
333326 ListHeader (
@@ -338,8 +331,8 @@ fun PatchesSelectorScreen(
338331 patchList(
339332 uid = bundle.uid,
340333 patches = bundle.incompatible.searched(),
341- visible = vm .filter and SHOW_INCOMPATIBLE != 0 ,
342- compatible = vm .allowIncompatiblePatches
334+ visible = viewModel .filter and SHOW_INCOMPATIBLE != 0 ,
335+ compatible = viewModel .allowIncompatiblePatches
343336 ) {
344337 ListHeader (
345338 title = stringResource(R .string.incompatible_patches),
@@ -362,7 +355,7 @@ fun PatchesSelectorScreen(
362355 verticalArrangement = Arrangement .spacedBy(4 .dp)
363356 ) {
364357 SmallFloatingActionButton (
365- onClick = vm ::reset,
358+ onClick = viewModel ::reset,
366359 containerColor = MaterialTheme .colorScheme.tertiaryContainer
367360 ) {
368361 Icon (Icons .Outlined .Restore , stringResource(R .string.reset))
@@ -385,7 +378,7 @@ fun PatchesSelectorScreen(
385378 expanded = patchLazyListStates.getOrNull(pagerState.currentPage)?.isScrollingUp
386379 ? : true ,
387380 onClick = {
388- onSave(vm .getCustomSelection(), vm .getOptions())
381+ onSave(viewModel .getCustomSelection(), viewModel .getOptions())
389382 }
390383 )
391384 }
@@ -453,7 +446,7 @@ fun PatchesSelectorScreen(
453446 patchList(
454447 uid = bundle.uid,
455448 patches = bundle.universal,
456- visible = vm .filter and SHOW_UNIVERSAL != 0 ,
449+ visible = viewModel .filter and SHOW_UNIVERSAL != 0 ,
457450 compatible = true
458451 ) {
459452 ListHeader (
@@ -463,8 +456,8 @@ fun PatchesSelectorScreen(
463456 patchList(
464457 uid = bundle.uid,
465458 patches = bundle.incompatible,
466- visible = vm .filter and SHOW_INCOMPATIBLE != 0 ,
467- compatible = vm .allowIncompatiblePatches
459+ visible = viewModel .filter and SHOW_INCOMPATIBLE != 0 ,
460+ compatible = viewModel .allowIncompatiblePatches
468461 ) {
469462 ListHeader (
470463 title = stringResource(R .string.incompatible_patches),
@@ -479,7 +472,9 @@ fun PatchesSelectorScreen(
479472}
480473
481474@Composable
482- private fun SelectionWarningDialog (onDismiss : () -> Unit ) {
475+ private fun SelectionWarningDialog (
476+ onDismiss : () -> Unit
477+ ) {
483478 SafeguardDialog (
484479 onDismiss = onDismiss,
485480 title = R .string.warning,
@@ -489,33 +484,12 @@ private fun SelectionWarningDialog(onDismiss: () -> Unit) {
489484
490485@Composable
491486private fun UniversalPatchWarningDialog (
492- onCancel : () -> Unit ,
493- onConfirm : () -> Unit
487+ onDismiss : () -> Unit
494488) {
495- AlertDialog (
496- onDismissRequest = onCancel,
497- confirmButton = {
498- TextButton (onClick = onConfirm) {
499- Text (stringResource(R .string.continue_))
500- }
501- },
502- dismissButton = {
503- TextButton (onClick = onCancel) {
504- Text (stringResource(R .string.cancel))
505- }
506- },
507- icon = {
508- Icon (Icons .Outlined .WarningAmber , null )
509- },
510- title = {
511- Text (
512- text = stringResource(R .string.warning),
513- style = MaterialTheme .typography.headlineSmall.copy(textAlign = TextAlign .Center )
514- )
515- },
516- text = {
517- Text (stringResource(R .string.universal_patch_warning_description))
518- }
489+ SafeguardDialog (
490+ onDismiss = onDismiss,
491+ title = R .string.warning,
492+ body = stringResource(R .string.universal_patch_warning_description),
519493 )
520494}
521495
0 commit comments