mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-04-29 21:44:26 +02:00
fix: show available and selected patches in patch selector screen
This commit is contained in:
parent
4cbd480e84
commit
f126fe9fa8
@ -57,8 +57,8 @@ import app.revanced.manager.R
|
||||
import app.revanced.manager.patcher.patch.Option
|
||||
import app.revanced.manager.patcher.patch.PatchInfo
|
||||
import app.revanced.manager.ui.component.AppTopBar
|
||||
import app.revanced.manager.ui.component.SafeguardDialog
|
||||
import app.revanced.manager.ui.component.LazyColumnWithScrollbar
|
||||
import app.revanced.manager.ui.component.SafeguardDialog
|
||||
import app.revanced.manager.ui.component.SearchView
|
||||
import app.revanced.manager.ui.component.patches.OptionItem
|
||||
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel
|
||||
@ -93,6 +93,21 @@ fun PatchesSelectorScreen(
|
||||
derivedStateOf { vm.selectionIsValid(bundles) }
|
||||
}
|
||||
|
||||
val availablePatchCount by remember {
|
||||
derivedStateOf {
|
||||
bundles.sumOf { it.patchCount }
|
||||
}
|
||||
}
|
||||
|
||||
val defaultPatchSelectionCount by vm.defaultSelectionCount
|
||||
.collectAsStateWithLifecycle(initialValue = 0)
|
||||
|
||||
val selectedPatchCount by remember {
|
||||
derivedStateOf {
|
||||
vm.customPatchSelection?.values?.sumOf { it.size } ?: defaultPatchSelectionCount
|
||||
}
|
||||
}
|
||||
|
||||
val patchLazyListStates = remember(bundles) { List(bundles.size) { LazyListState() } }
|
||||
|
||||
if (showBottomSheet) {
|
||||
@ -265,7 +280,7 @@ fun PatchesSelectorScreen(
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AppTopBar(
|
||||
title = stringResource(R.string.select_patches),
|
||||
title = stringResource(R.string.patches_selected, selectedPatchCount, availablePatchCount),
|
||||
onBackClick = onBackClick,
|
||||
actions = {
|
||||
IconButton(onClick = vm::reset) {
|
||||
|
@ -69,11 +69,6 @@ fun SelectedAppInfoScreen(
|
||||
patches.values.sumOf { it.size }
|
||||
}
|
||||
}
|
||||
val availablePatchCount by remember {
|
||||
derivedStateOf {
|
||||
bundles.sumOf { it.patchCount }
|
||||
}
|
||||
}
|
||||
|
||||
val navController =
|
||||
rememberNavController<SelectedAppInfoDestination>(startDestination = SelectedAppInfoDestination.Main)
|
||||
@ -111,7 +106,6 @@ fun SelectedAppInfoScreen(
|
||||
navController.navigate(SelectedAppInfoDestination.VersionSelector)
|
||||
},
|
||||
onBackClick = onBackClick,
|
||||
availablePatchCount = availablePatchCount,
|
||||
selectedPatchCount = selectedPatchCount,
|
||||
packageName = packageName,
|
||||
version = version,
|
||||
@ -154,7 +148,6 @@ private fun SelectedAppInfoScreen(
|
||||
onPatchSelectorClick: () -> Unit,
|
||||
onVersionSelectorClick: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
availablePatchCount: Int,
|
||||
selectedPatchCount: Int,
|
||||
packageName: String,
|
||||
version: String,
|
||||
@ -182,7 +175,7 @@ private fun SelectedAppInfoScreen(
|
||||
) {
|
||||
AppInfo(packageInfo, placeholderLabel = packageName) {
|
||||
Text(
|
||||
stringResource(R.string.selected_app_meta, version, availablePatchCount),
|
||||
stringResource(R.string.selected_app_meta, version),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
|
@ -36,6 +36,7 @@ import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
import kotlinx.collections.immutable.*
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@Stable
|
||||
@OptIn(SavedStateHandleSaveableApi::class)
|
||||
@ -77,7 +78,7 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent {
|
||||
}
|
||||
|
||||
private var hasModifiedSelection = false
|
||||
private var customPatchSelection: PersistentPatchSelection? by savedStateHandle.saveable(
|
||||
var customPatchSelection: PersistentPatchSelection? by savedStateHandle.saveable(
|
||||
key = "selection",
|
||||
stateSaver = selectionSaver,
|
||||
) {
|
||||
@ -103,12 +104,13 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent {
|
||||
var filter by mutableIntStateOf(SHOW_SUPPORTED or SHOW_UNIVERSAL or SHOW_UNSUPPORTED)
|
||||
private set
|
||||
|
||||
private suspend fun generateDefaultSelection(): PersistentPatchSelection {
|
||||
val bundles = bundlesFlow.first()
|
||||
val generatedSelection =
|
||||
bundles.toPatchSelection(allowIncompatiblePatches) { _, patch -> patch.include }
|
||||
private val defaultPatchSelection = bundlesFlow.map { bundles ->
|
||||
bundles.toPatchSelection(allowIncompatiblePatches) { _, patch -> patch.include }
|
||||
.toPersistentPatchSelection()
|
||||
}
|
||||
|
||||
return generatedSelection.toPersistentPatchSelection()
|
||||
val defaultSelectionCount = defaultPatchSelection.map { selection ->
|
||||
selection.values.sumOf { it.size }
|
||||
}
|
||||
|
||||
fun selectionIsValid(bundles: List<BundleInfo>) = bundles.any { bundle ->
|
||||
@ -124,7 +126,7 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent {
|
||||
fun togglePatch(bundle: Int, patch: PatchInfo) = viewModelScope.launch {
|
||||
hasModifiedSelection = true
|
||||
|
||||
val selection = customPatchSelection ?: generateDefaultSelection()
|
||||
val selection = customPatchSelection ?: defaultPatchSelection.first()
|
||||
val newPatches = selection[bundle]?.let { patches ->
|
||||
if (patch.name in patches)
|
||||
patches.remove(patch.name)
|
||||
|
@ -9,7 +9,7 @@
|
||||
<string name="dashboard">Dashboard</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="select_app">Select an app</string>
|
||||
<string name="select_patches">Select patches</string>
|
||||
<string name="patches_selected">%1$d/%2$d selected</string>
|
||||
|
||||
<string name="unsupported_architecture_warning">Patching on this device architecture is unsupported and will most likely fail.</string>
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
<string name="bundle_name_default">Default</string>
|
||||
<string name="bundle_name_fallback">Unnamed</string>
|
||||
|
||||
<string name="selected_app_meta">%1$s • %2$d available patches</string>
|
||||
<string name="selected_app_meta">%1$s</string>
|
||||
|
||||
<string name="patch_item_description">Start patching the application</string>
|
||||
<string name="patch_selector_item">Patch selection and options</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user