mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-04-30 05:54: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.Option
|
||||||
import app.revanced.manager.patcher.patch.PatchInfo
|
import app.revanced.manager.patcher.patch.PatchInfo
|
||||||
import app.revanced.manager.ui.component.AppTopBar
|
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.LazyColumnWithScrollbar
|
||||||
|
import app.revanced.manager.ui.component.SafeguardDialog
|
||||||
import app.revanced.manager.ui.component.SearchView
|
import app.revanced.manager.ui.component.SearchView
|
||||||
import app.revanced.manager.ui.component.patches.OptionItem
|
import app.revanced.manager.ui.component.patches.OptionItem
|
||||||
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel
|
import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel
|
||||||
@ -93,6 +93,21 @@ fun PatchesSelectorScreen(
|
|||||||
derivedStateOf { vm.selectionIsValid(bundles) }
|
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() } }
|
val patchLazyListStates = remember(bundles) { List(bundles.size) { LazyListState() } }
|
||||||
|
|
||||||
if (showBottomSheet) {
|
if (showBottomSheet) {
|
||||||
@ -265,7 +280,7 @@ fun PatchesSelectorScreen(
|
|||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
AppTopBar(
|
AppTopBar(
|
||||||
title = stringResource(R.string.select_patches),
|
title = stringResource(R.string.patches_selected, selectedPatchCount, availablePatchCount),
|
||||||
onBackClick = onBackClick,
|
onBackClick = onBackClick,
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = vm::reset) {
|
IconButton(onClick = vm::reset) {
|
||||||
|
@ -69,11 +69,6 @@ fun SelectedAppInfoScreen(
|
|||||||
patches.values.sumOf { it.size }
|
patches.values.sumOf { it.size }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val availablePatchCount by remember {
|
|
||||||
derivedStateOf {
|
|
||||||
bundles.sumOf { it.patchCount }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val navController =
|
val navController =
|
||||||
rememberNavController<SelectedAppInfoDestination>(startDestination = SelectedAppInfoDestination.Main)
|
rememberNavController<SelectedAppInfoDestination>(startDestination = SelectedAppInfoDestination.Main)
|
||||||
@ -111,7 +106,6 @@ fun SelectedAppInfoScreen(
|
|||||||
navController.navigate(SelectedAppInfoDestination.VersionSelector)
|
navController.navigate(SelectedAppInfoDestination.VersionSelector)
|
||||||
},
|
},
|
||||||
onBackClick = onBackClick,
|
onBackClick = onBackClick,
|
||||||
availablePatchCount = availablePatchCount,
|
|
||||||
selectedPatchCount = selectedPatchCount,
|
selectedPatchCount = selectedPatchCount,
|
||||||
packageName = packageName,
|
packageName = packageName,
|
||||||
version = version,
|
version = version,
|
||||||
@ -154,7 +148,6 @@ private fun SelectedAppInfoScreen(
|
|||||||
onPatchSelectorClick: () -> Unit,
|
onPatchSelectorClick: () -> Unit,
|
||||||
onVersionSelectorClick: () -> Unit,
|
onVersionSelectorClick: () -> Unit,
|
||||||
onBackClick: () -> Unit,
|
onBackClick: () -> Unit,
|
||||||
availablePatchCount: Int,
|
|
||||||
selectedPatchCount: Int,
|
selectedPatchCount: Int,
|
||||||
packageName: String,
|
packageName: String,
|
||||||
version: String,
|
version: String,
|
||||||
@ -182,7 +175,7 @@ private fun SelectedAppInfoScreen(
|
|||||||
) {
|
) {
|
||||||
AppInfo(packageInfo, placeholderLabel = packageName) {
|
AppInfo(packageInfo, placeholderLabel = packageName) {
|
||||||
Text(
|
Text(
|
||||||
stringResource(R.string.selected_app_meta, version, availablePatchCount),
|
stringResource(R.string.selected_app_meta, version),
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
|
@ -36,6 +36,7 @@ import kotlinx.coroutines.launch
|
|||||||
import org.koin.core.component.KoinComponent
|
import org.koin.core.component.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
import kotlinx.collections.immutable.*
|
import kotlinx.collections.immutable.*
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
@OptIn(SavedStateHandleSaveableApi::class)
|
@OptIn(SavedStateHandleSaveableApi::class)
|
||||||
@ -77,7 +78,7 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var hasModifiedSelection = false
|
private var hasModifiedSelection = false
|
||||||
private var customPatchSelection: PersistentPatchSelection? by savedStateHandle.saveable(
|
var customPatchSelection: PersistentPatchSelection? by savedStateHandle.saveable(
|
||||||
key = "selection",
|
key = "selection",
|
||||||
stateSaver = selectionSaver,
|
stateSaver = selectionSaver,
|
||||||
) {
|
) {
|
||||||
@ -103,12 +104,13 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent {
|
|||||||
var filter by mutableIntStateOf(SHOW_SUPPORTED or SHOW_UNIVERSAL or SHOW_UNSUPPORTED)
|
var filter by mutableIntStateOf(SHOW_SUPPORTED or SHOW_UNIVERSAL or SHOW_UNSUPPORTED)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private suspend fun generateDefaultSelection(): PersistentPatchSelection {
|
private val defaultPatchSelection = bundlesFlow.map { bundles ->
|
||||||
val bundles = bundlesFlow.first()
|
|
||||||
val generatedSelection =
|
|
||||||
bundles.toPatchSelection(allowIncompatiblePatches) { _, patch -> patch.include }
|
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 ->
|
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 {
|
fun togglePatch(bundle: Int, patch: PatchInfo) = viewModelScope.launch {
|
||||||
hasModifiedSelection = true
|
hasModifiedSelection = true
|
||||||
|
|
||||||
val selection = customPatchSelection ?: generateDefaultSelection()
|
val selection = customPatchSelection ?: defaultPatchSelection.first()
|
||||||
val newPatches = selection[bundle]?.let { patches ->
|
val newPatches = selection[bundle]?.let { patches ->
|
||||||
if (patch.name in patches)
|
if (patch.name in patches)
|
||||||
patches.remove(patch.name)
|
patches.remove(patch.name)
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<string name="dashboard">Dashboard</string>
|
<string name="dashboard">Dashboard</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="select_app">Select an app</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>
|
<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_default">Default</string>
|
||||||
<string name="bundle_name_fallback">Unnamed</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_item_description">Start patching the application</string>
|
||||||
<string name="patch_selector_item">Patch selection and options</string>
|
<string name="patch_selector_item">Patch selection and options</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user