@@ -58,7 +58,6 @@ import androidx.compose.ui.Modifier
58
58
import androidx.compose.ui.draw.alpha
59
59
import androidx.compose.ui.draw.rotate
60
60
import androidx.compose.ui.res.stringResource
61
- import androidx.compose.ui.text.style.TextAlign
62
61
import androidx.compose.ui.unit.dp
63
62
import androidx.lifecycle.compose.collectAsStateWithLifecycle
64
63
import app.revanced.manager.R
@@ -88,9 +87,9 @@ import kotlinx.coroutines.launch
88
87
fun PatchesSelectorScreen (
89
88
onSave : (PatchSelection ? , Options ) -> Unit ,
90
89
onBackClick : () -> Unit ,
91
- vm : PatchesSelectorViewModel
90
+ viewModel : PatchesSelectorViewModel
92
91
) {
93
- val bundles by vm .bundlesFlow.collectAsStateWithLifecycle(initialValue = emptyList())
92
+ val bundles by viewModel .bundlesFlow.collectAsStateWithLifecycle(initialValue = emptyList())
94
93
val pagerState = rememberPagerState(
95
94
initialPage = 0 ,
96
95
initialPageOffsetFraction = 0f
@@ -106,15 +105,15 @@ fun PatchesSelectorScreen(
106
105
}
107
106
var showBottomSheet by rememberSaveable { mutableStateOf(false ) }
108
107
val showSaveButton by remember {
109
- derivedStateOf { vm .selectionIsValid(bundles) }
108
+ derivedStateOf { viewModel .selectionIsValid(bundles) }
110
109
}
111
110
112
- val defaultPatchSelectionCount by vm .defaultSelectionCount
111
+ val defaultPatchSelectionCount by viewModel .defaultSelectionCount
113
112
.collectAsStateWithLifecycle(initialValue = 0 )
114
113
115
114
val selectedPatchCount by remember {
116
115
derivedStateOf {
117
- vm .customPatchSelection?.values?.sumOf { it.size } ? : defaultPatchSelectionCount
116
+ viewModel .customPatchSelection?.values?.sumOf { it.size } ? : defaultPatchSelectionCount
118
117
}
119
118
}
120
119
@@ -146,58 +145,54 @@ fun PatchesSelectorScreen(
146
145
verticalArrangement = Arrangement .spacedBy(12 .dp)
147
146
) {
148
147
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 ) },
151
150
label = { Text (stringResource(R .string.this_version)) }
152
151
)
153
152
154
153
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 ) },
157
156
label = { Text (stringResource(R .string.universal)) },
158
157
)
159
158
}
160
159
}
161
160
}
162
161
}
163
162
164
- if (vm .compatibleVersions.isNotEmpty())
163
+ if (viewModel .compatibleVersions.isNotEmpty())
165
164
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
169
168
)
170
169
var showIncompatiblePatchesDialog by rememberSaveable {
171
170
mutableStateOf(false )
172
171
}
173
172
if (showIncompatiblePatchesDialog)
174
173
IncompatiblePatchesDialog (
175
- appVersion = vm .appVersion ? : stringResource(R .string.any_version),
174
+ appVersion = viewModel .appVersion ? : stringResource(R .string.any_version),
176
175
onDismissRequest = { showIncompatiblePatchesDialog = false }
177
176
)
178
177
179
- vm .optionsDialog?.let { (bundle, patch) ->
178
+ viewModel .optionsDialog?.let { (bundle, patch) ->
180
179
OptionsDialog (
181
- onDismissRequest = vm ::dismissDialogs,
180
+ onDismissRequest = viewModel ::dismissDialogs,
182
181
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) }
186
185
)
187
186
}
188
187
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)
193
192
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 })
201
196
202
197
fun LazyListScope.patchList (
203
198
uid : Int ,
@@ -221,27 +216,25 @@ fun PatchesSelectorScreen(
221
216
PatchItem (
222
217
patch = patch,
223
218
onOptionsDialog = {
224
- vm .optionsDialog = uid to patch
219
+ viewModel .optionsDialog = uid to patch
225
220
},
226
- selected = compatible && vm .isSelected(
221
+ selected = compatible && viewModel .isSelected(
227
222
uid,
228
223
patch
229
224
),
230
225
onToggle = {
231
226
when {
232
227
// Open incompatible dialog if the patch is not supported
233
- ! compatible -> vm .openIncompatibleDialog(patch)
228
+ ! compatible -> viewModel .openIncompatibleDialog(patch)
234
229
235
230
// Show selection warning if enabled
236
- vm .selectionWarningEnabled -> showSelectionWarning = true
231
+ viewModel .selectionWarningEnabled -> showSelectionWarning = true
237
232
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
242
235
243
236
// Toggle the patch otherwise
244
- else -> vm .togglePatch(uid, patch)
237
+ else -> viewModel .togglePatch(uid, patch)
245
238
}
246
239
},
247
240
compatible = compatible
@@ -327,7 +320,7 @@ fun PatchesSelectorScreen(
327
320
patchList(
328
321
uid = bundle.uid,
329
322
patches = bundle.universal.searched(),
330
- visible = vm .filter and SHOW_UNIVERSAL != 0 ,
323
+ visible = viewModel .filter and SHOW_UNIVERSAL != 0 ,
331
324
compatible = true
332
325
) {
333
326
ListHeader (
@@ -338,8 +331,8 @@ fun PatchesSelectorScreen(
338
331
patchList(
339
332
uid = bundle.uid,
340
333
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
343
336
) {
344
337
ListHeader (
345
338
title = stringResource(R .string.incompatible_patches),
@@ -362,7 +355,7 @@ fun PatchesSelectorScreen(
362
355
verticalArrangement = Arrangement .spacedBy(4 .dp)
363
356
) {
364
357
SmallFloatingActionButton (
365
- onClick = vm ::reset,
358
+ onClick = viewModel ::reset,
366
359
containerColor = MaterialTheme .colorScheme.tertiaryContainer
367
360
) {
368
361
Icon (Icons .Outlined .Restore , stringResource(R .string.reset))
@@ -385,7 +378,7 @@ fun PatchesSelectorScreen(
385
378
expanded = patchLazyListStates.getOrNull(pagerState.currentPage)?.isScrollingUp
386
379
? : true ,
387
380
onClick = {
388
- onSave(vm .getCustomSelection(), vm .getOptions())
381
+ onSave(viewModel .getCustomSelection(), viewModel .getOptions())
389
382
}
390
383
)
391
384
}
@@ -453,7 +446,7 @@ fun PatchesSelectorScreen(
453
446
patchList(
454
447
uid = bundle.uid,
455
448
patches = bundle.universal,
456
- visible = vm .filter and SHOW_UNIVERSAL != 0 ,
449
+ visible = viewModel .filter and SHOW_UNIVERSAL != 0 ,
457
450
compatible = true
458
451
) {
459
452
ListHeader (
@@ -463,8 +456,8 @@ fun PatchesSelectorScreen(
463
456
patchList(
464
457
uid = bundle.uid,
465
458
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
468
461
) {
469
462
ListHeader (
470
463
title = stringResource(R .string.incompatible_patches),
@@ -479,7 +472,9 @@ fun PatchesSelectorScreen(
479
472
}
480
473
481
474
@Composable
482
- private fun SelectionWarningDialog (onDismiss : () -> Unit ) {
475
+ private fun SelectionWarningDialog (
476
+ onDismiss : () -> Unit
477
+ ) {
483
478
SafeguardDialog (
484
479
onDismiss = onDismiss,
485
480
title = R .string.warning,
@@ -489,33 +484,12 @@ private fun SelectionWarningDialog(onDismiss: () -> Unit) {
489
484
490
485
@Composable
491
486
private fun UniversalPatchWarningDialog (
492
- onCancel : () -> Unit ,
493
- onConfirm : () -> Unit
487
+ onDismiss : () -> Unit
494
488
) {
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),
519
493
)
520
494
}
521
495
0 commit comments