From 7c4272d6390ec4ce2759b768be33815a4b0752ad Mon Sep 17 00:00:00 2001 From: Xinto Date: Tue, 7 Jan 2025 02:40:00 +0400 Subject: [PATCH] Update the filter menu --- .../manager/ui/component/CheckedFilterChip.kt | 61 +++++++++++++++++++ .../ui/screen/PatchesSelectorScreen.kt | 38 +++++------- .../ui/viewmodel/PatchesSelectorViewModel.kt | 4 +- app/src/main/res/values/strings.xml | 6 +- 4 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/app/revanced/manager/ui/component/CheckedFilterChip.kt diff --git a/app/src/main/java/app/revanced/manager/ui/component/CheckedFilterChip.kt b/app/src/main/java/app/revanced/manager/ui/component/CheckedFilterChip.kt new file mode 100644 index 0000000000..a81c456f7b --- /dev/null +++ b/app/src/main/java/app/revanced/manager/ui/component/CheckedFilterChip.kt @@ -0,0 +1,61 @@ +package app.revanced.manager.ui.component + +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.expandIn +import androidx.compose.animation.shrinkOut +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Done +import androidx.compose.material3.FilterChip +import androidx.compose.material3.FilterChipDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.SelectableChipColors +import androidx.compose.material3.SelectableChipElevation +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Shape + +@Composable +fun CheckedFilterChip( + selected: Boolean, + onClick: () -> Unit, + label: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + trailingIcon: @Composable (() -> Unit)? = null, + shape: Shape = FilterChipDefaults.shape, + colors: SelectableChipColors = FilterChipDefaults.filterChipColors(), + elevation: SelectableChipElevation? = FilterChipDefaults.filterChipElevation(), + border: BorderStroke? = FilterChipDefaults.filterChipBorder(enabled, selected), + interactionSource: MutableInteractionSource? = null +) { + FilterChip( + selected = selected, + onClick = onClick, + label = label, + modifier = modifier, + enabled = enabled, + leadingIcon = { + AnimatedVisibility( + visible = selected, + enter = expandIn(expandFrom = Alignment.CenterStart), + exit = shrinkOut(shrinkTowards = Alignment.CenterStart) + ) { + Icon( + modifier = Modifier.size(FilterChipDefaults.IconSize), + imageVector = Icons.Filled.Done, + contentDescription = null, + ) + } + }, + trailingIcon = trailingIcon, + shape = shape, + colors = colors, + elevation = elevation, + border = border, + interactionSource = interactionSource + ) +} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt index 35da5a65de..626d519388 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/PatchesSelectorScreen.kt @@ -48,6 +48,7 @@ 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.CheckedFilterChip import app.revanced.manager.ui.component.LazyColumnWithScrollbar import app.revanced.manager.ui.component.SafeguardDialog import app.revanced.manager.ui.component.haptics.HapticCheckbox @@ -57,14 +58,13 @@ import app.revanced.manager.ui.component.patches.OptionItem import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_SUPPORTED import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_UNIVERSAL -import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_UNSUPPORTED import app.revanced.manager.util.Options import app.revanced.manager.util.PatchSelection import app.revanced.manager.util.isScrollingUp import app.revanced.manager.util.transparentListItemColors import kotlinx.coroutines.launch -@OptIn(ExperimentalMaterial3Api::class) +@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable fun PatchesSelectorScreen( onSave: (PatchSelection?, Options) -> Unit, @@ -127,27 +127,22 @@ fun PatchesSelectorScreen( style = MaterialTheme.typography.titleMedium ) - Row( + FlowRow( modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(5.dp) + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalArrangement = Arrangement.spacedBy(12.dp) ) { - FilterChip( + CheckedFilterChip( selected = vm.filter and SHOW_SUPPORTED != 0, onClick = { vm.toggleFlag(SHOW_SUPPORTED) }, label = { Text(stringResource(R.string.supported)) } ) - FilterChip( + CheckedFilterChip( selected = vm.filter and SHOW_UNIVERSAL != 0, onClick = { vm.toggleFlag(SHOW_UNIVERSAL) }, label = { Text(stringResource(R.string.universal)) }, ) - - FilterChip( - selected = vm.filter and SHOW_UNSUPPORTED != 0, - onClick = { vm.toggleFlag(SHOW_UNSUPPORTED) }, - label = { Text(stringResource(R.string.unsupported)) }, - ) } } } @@ -194,11 +189,11 @@ fun PatchesSelectorScreen( fun LazyListScope.patchList( uid: Int, patches: List, - filterFlag: Int, + visible: Boolean, supported: Boolean, header: (@Composable () -> Unit)? = null ) { - if (patches.isNotEmpty() && (vm.filter and filterFlag) != 0 || vm.filter == 0) { + if (patches.isNotEmpty() && visible) { header?.let { item { it() @@ -311,13 +306,13 @@ fun PatchesSelectorScreen( patchList( uid = bundle.uid, patches = bundle.supported.searched(), - filterFlag = SHOW_SUPPORTED, + visible = true, supported = true ) patchList( uid = bundle.uid, patches = bundle.universal.searched(), - filterFlag = SHOW_UNIVERSAL, + visible = vm.filter and SHOW_UNIVERSAL != 0, supported = true ) { ListHeader( @@ -325,12 +320,11 @@ fun PatchesSelectorScreen( ) } - if (!vm.allowIncompatiblePatches) return@LazyColumnWithScrollbar patchList( uid = bundle.uid, patches = bundle.unsupported.searched(), - filterFlag = SHOW_UNSUPPORTED, - supported = true + visible = vm.filter and SHOW_SUPPORTED == 0, + supported = vm.allowIncompatiblePatches ) { ListHeader( title = stringResource(R.string.unsupported_patches), @@ -447,13 +441,13 @@ fun PatchesSelectorScreen( patchList( uid = bundle.uid, patches = bundle.supported, - filterFlag = SHOW_SUPPORTED, + visible = true, supported = true ) patchList( uid = bundle.uid, patches = bundle.universal, - filterFlag = SHOW_UNIVERSAL, + visible = vm.filter and SHOW_UNIVERSAL != 0, supported = true ) { ListHeader( @@ -463,7 +457,7 @@ fun PatchesSelectorScreen( patchList( uid = bundle.uid, patches = bundle.unsupported, - filterFlag = SHOW_UNSUPPORTED, + visible = vm.filter and SHOW_SUPPORTED == 0, supported = vm.allowIncompatiblePatches ) { ListHeader( diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt index 31f6d6437f..976de5431e 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/PatchesSelectorViewModel.kt @@ -2,6 +2,7 @@ package app.revanced.manager.ui.viewmodel import android.app.Application import androidx.compose.runtime.Stable +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.setValue @@ -104,7 +105,7 @@ class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.Vi val compatibleVersions = mutableStateListOf() - var filter by mutableIntStateOf(0) + var filter by mutableIntStateOf(SHOW_SUPPORTED xor SHOW_UNIVERSAL) private set private val defaultPatchSelection = bundlesFlow.map { bundles -> @@ -220,7 +221,6 @@ class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.Vi companion object { const val SHOW_SUPPORTED = 1 // 2^0 const val SHOW_UNIVERSAL = 2 // 2^1 - const val SHOW_UNSUPPORTED = 4 // 2^2 private val optionsSaver: Saver = snapshotStateMapSaver( // Patch name -> Options diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fbbf43bed3..bd4835b075 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -210,7 +210,7 @@ No patched apps found Tap on the patches to get more information about them %s selected - Unsupported patches + Incompatible patches Universal patches Patch selection and options has been reset to recommended defaults Patch options have been reset @@ -219,8 +219,8 @@ Stop using defaults? It is recommended to use the default patch selection and options. Changing them may result in unexpected issues.\n\nYou need to turn on \"Allow changing patch selection\" in the advanced settings before toggling patches. Universal patches have a more generalized use and do not work as reliably as patches that target specific apps. You may encounter issues while using them.\n\nThis warning can be disabled in the advanced settings. - Supported - Universal + This version + Any app Unsupported Search patches This patch is not compatible with the selected app version (%1$s).\n\nIt only supports the following version(s): %2$s.