From d5c63ead2673a64327fd2027b9e4df76fbe45a23 Mon Sep 17 00:00:00 2001 From: Ushie Date: Wed, 12 Feb 2025 20:40:47 +0300 Subject: [PATCH] fix: Use `compatible` rather than `support` when referring to patch compatibility (#2422) --- .../revanced/manager/ui/model/BundleInfo.kt | 28 +++--- .../ui/screen/PatchesSelectorScreen.kt | 86 +++++++++---------- .../ui/viewmodel/PatchesSelectorViewModel.kt | 23 +++-- .../ui/viewmodel/SelectedAppInfoViewModel.kt | 25 +++--- app/src/main/res/values/strings.xml | 17 ++-- 5 files changed, 91 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt b/app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt index 9dd9d1b0..efdb4a17 100644 --- a/app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt +++ b/app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt @@ -12,34 +12,34 @@ import kotlinx.coroutines.flow.map data class BundleInfo( val name: String, val uid: Int, - val supported: List, - val unsupported: List, + val compatible: List, + val incompatible: List, val universal: List ) { val all = sequence { - yieldAll(supported) - yieldAll(unsupported) + yieldAll(compatible) + yieldAll(incompatible) yieldAll(universal) } - val patchCount get() = supported.size + unsupported.size + universal.size + val patchCount get() = compatible.size + incompatible.size + universal.size - fun patchSequence(allowUnsupported: Boolean) = if (allowUnsupported) { + fun patchSequence(allowIncompatible: Boolean) = if (allowIncompatible) { all } else { sequence { - yieldAll(supported) + yieldAll(compatible) yieldAll(universal) } } companion object Extensions { inline fun Iterable.toPatchSelection( - allowUnsupported: Boolean, + allowIncompatible: Boolean, condition: (Int, PatchInfo) -> Boolean ): PatchSelection = this.associate { bundle -> val patches = - bundle.patchSequence(allowUnsupported) + bundle.patchSequence(allowIncompatible) .mapNotNullTo(mutableSetOf()) { patch -> patch.name.takeIf { condition( @@ -60,8 +60,8 @@ data class BundleInfo( source.state.map { state -> val bundle = state.patchBundleOrNull() ?: return@map null - val supported = mutableListOf() - val unsupported = mutableListOf() + val compatible = mutableListOf() + val incompatible = mutableListOf() val universal = mutableListOf() bundle.patches.filter { it.compatibleWith(packageName) }.forEach { @@ -70,15 +70,15 @@ data class BundleInfo( it.supports( packageName, version - ) -> supported + ) -> compatible - else -> unsupported + else -> incompatible } targetList.add(it) } - BundleInfo(source.getName(), source.uid, supported, unsupported, universal) + BundleInfo(source.getName(), source.uid, compatible, incompatible, universal) } } 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 26141959..094757d2 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 @@ -76,8 +76,8 @@ import app.revanced.manager.ui.component.haptics.HapticExtendedFloatingActionBut import app.revanced.manager.ui.component.haptics.HapticTab import app.revanced.manager.ui.component.patches.OptionItem import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel +import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW_INCOMPATIBLE 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 @@ -147,9 +147,9 @@ fun PatchesSelectorScreen( verticalArrangement = Arrangement.spacedBy(12.dp) ) { CheckedFilterChip( - selected = vm.filter and SHOW_UNSUPPORTED == 0, - onClick = { vm.toggleFlag(SHOW_UNSUPPORTED) }, - label = { Text(stringResource(R.string.supported)) } + selected = vm.filter and SHOW_INCOMPATIBLE == 0, + onClick = { vm.toggleFlag(SHOW_INCOMPATIBLE) }, + label = { Text(stringResource(R.string.this_version)) } ) CheckedFilterChip( @@ -163,18 +163,18 @@ fun PatchesSelectorScreen( } if (vm.compatibleVersions.isNotEmpty()) - UnsupportedPatchDialog( + IncompatiblePatchDialog( appVersion = vm.appVersion ?: stringResource(R.string.any_version), - supportedVersions = vm.compatibleVersions, + compatibleVersions = vm.compatibleVersions, onDismissRequest = vm::dismissDialogs ) - var showUnsupportedPatchesDialog by rememberSaveable { + var showIncompatiblePatchesDialog by rememberSaveable { mutableStateOf(false) } - if (showUnsupportedPatchesDialog) - UnsupportedPatchesDialog( + if (showIncompatiblePatchesDialog) + IncompatiblePatchesDialog( appVersion = vm.appVersion ?: stringResource(R.string.any_version), - onDismissRequest = { showUnsupportedPatchesDialog = false } + onDismissRequest = { showIncompatiblePatchesDialog = false } ) vm.optionsDialog?.let { (bundle, patch) -> @@ -204,7 +204,7 @@ fun PatchesSelectorScreen( uid: Int, patches: List, visible: Boolean, - supported: Boolean, + compatible: Boolean, header: (@Composable () -> Unit)? = null ) { if (patches.isNotEmpty() && visible) { @@ -224,14 +224,14 @@ fun PatchesSelectorScreen( onOptionsDialog = { vm.optionsDialog = uid to patch }, - selected = supported && vm.isSelected( + selected = compatible && vm.isSelected( uid, patch ), onToggle = { when { - // Open unsupported dialog if the patch is not supported - !supported -> vm.openUnsupportedDialog(patch) + // Open incompatible dialog if the patch is not supported + !compatible -> vm.openIncompatibleDialog(patch) // Show selection warning if enabled vm.selectionWarningEnabled -> showSelectionWarning = true @@ -245,7 +245,7 @@ fun PatchesSelectorScreen( else -> vm.togglePatch(uid, patch) } }, - supported = supported + compatible = compatible ) } } @@ -321,15 +321,15 @@ fun PatchesSelectorScreen( patchList( uid = bundle.uid, - patches = bundle.supported.searched(), + patches = bundle.compatible.searched(), visible = true, - supported = true + compatible = true ) patchList( uid = bundle.uid, patches = bundle.universal.searched(), visible = vm.filter and SHOW_UNIVERSAL != 0, - supported = true + compatible = true ) { ListHeader( title = stringResource(R.string.universal_patches), @@ -338,13 +338,13 @@ fun PatchesSelectorScreen( patchList( uid = bundle.uid, - patches = bundle.unsupported.searched(), - visible = vm.filter and SHOW_UNSUPPORTED != 0, - supported = vm.allowIncompatiblePatches + patches = bundle.incompatible.searched(), + visible = vm.filter and SHOW_INCOMPATIBLE != 0, + compatible = vm.allowIncompatiblePatches ) { ListHeader( - title = stringResource(R.string.unsupported_patches), - onHelpClick = { showUnsupportedPatchesDialog = true } + title = stringResource(R.string.incompatible_patches), + onHelpClick = { showIncompatiblePatchesDialog = true } ) } } @@ -427,15 +427,15 @@ fun PatchesSelectorScreen( ) { patchList( uid = bundle.uid, - patches = bundle.supported, + patches = bundle.compatible, visible = true, - supported = true + compatible = true ) patchList( uid = bundle.uid, patches = bundle.universal, visible = vm.filter and SHOW_UNIVERSAL != 0, - supported = true + compatible = true ) { ListHeader( title = stringResource(R.string.universal_patches), @@ -443,13 +443,13 @@ fun PatchesSelectorScreen( } patchList( uid = bundle.uid, - patches = bundle.unsupported, - visible = vm.filter and SHOW_UNSUPPORTED != 0, - supported = vm.allowIncompatiblePatches + patches = bundle.incompatible, + visible = vm.filter and SHOW_INCOMPATIBLE != 0, + compatible = vm.allowIncompatiblePatches ) { ListHeader( - title = stringResource(R.string.unsupported_patches), - onHelpClick = { showUnsupportedPatchesDialog = true } + title = stringResource(R.string.incompatible_patches), + onHelpClick = { showIncompatiblePatchesDialog = true } ) } } @@ -506,24 +506,24 @@ private fun PatchItem( onOptionsDialog: () -> Unit, selected: Boolean, onToggle: () -> Unit, - supported: Boolean = true + compatible: Boolean = true ) = ListItem( modifier = Modifier - .let { if (!supported) it.alpha(0.5f) else it } + .let { if (!compatible) it.alpha(0.5f) else it } .clickable(onClick = onToggle) .fillMaxSize(), leadingContent = { HapticCheckbox( checked = selected, onCheckedChange = { onToggle() }, - enabled = supported + enabled = compatible ) }, headlineContent = { Text(patch.name) }, supportingContent = patch.description?.let { { Text(it) } }, trailingContent = { if (patch.options?.isNotEmpty() == true) { - IconButton(onClick = onOptionsDialog, enabled = supported) { + IconButton(onClick = onOptionsDialog, enabled = compatible) { Icon(Icons.Outlined.Settings, null) } } @@ -559,7 +559,7 @@ fun ListHeader( } @Composable -private fun UnsupportedPatchesDialog( +private fun IncompatiblePatchesDialog( appVersion: String, onDismissRequest: () -> Unit ) = AlertDialog( @@ -572,11 +572,11 @@ private fun UnsupportedPatchesDialog( Text(stringResource(R.string.ok)) } }, - title = { Text(stringResource(R.string.unsupported_patches)) }, + title = { Text(stringResource(R.string.incompatible_patches)) }, text = { Text( stringResource( - R.string.unsupported_patches_dialog, + R.string.incompatible_patches_dialog, appVersion ) ) @@ -584,9 +584,9 @@ private fun UnsupportedPatchesDialog( ) @Composable -private fun UnsupportedPatchDialog( +private fun IncompatiblePatchDialog( appVersion: String, - supportedVersions: List, + compatibleVersions: List, onDismissRequest: () -> Unit ) = AlertDialog( icon = { @@ -598,13 +598,13 @@ private fun UnsupportedPatchDialog( Text(stringResource(R.string.ok)) } }, - title = { Text(stringResource(R.string.unsupported_patch)) }, + title = { Text(stringResource(R.string.incompatible_patch)) }, text = { Text( stringResource( - R.string.app_not_supported, + R.string.app_version_not_compatible, appVersion, - supportedVersions.joinToString(", ") + compatibleVersions.joinToString(", ") ) ) } 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 54f2b7b8..00080f84 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 @@ -3,11 +3,11 @@ package app.revanced.manager.ui.viewmodel import android.app.Application import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.setValue import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.Saver +import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshots.SnapshotStateMap import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -30,15 +30,20 @@ import app.revanced.manager.util.saver.persistentMapSaver import app.revanced.manager.util.saver.persistentSetSaver import app.revanced.manager.util.saver.snapshotStateMapSaver import app.revanced.manager.util.toast +import kotlinx.collections.immutable.PersistentMap +import kotlinx.collections.immutable.PersistentSet +import kotlinx.collections.immutable.persistentMapOf +import kotlinx.collections.immutable.persistentSetOf +import kotlinx.collections.immutable.toPersistentMap +import kotlinx.collections.immutable.toPersistentSet +import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.async import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import org.koin.core.component.KoinComponent import org.koin.core.component.get -import kotlinx.collections.immutable.* -import kotlinx.coroutines.CoroutineStart -import kotlinx.coroutines.async -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.map @OptIn(SavedStateHandleSaveableApi::class) class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.ViewModelParams) : @@ -208,8 +213,8 @@ class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.Vi compatibleVersions.clear() } - fun openUnsupportedDialog(unsupportedPatch: PatchInfo) { - compatibleVersions.addAll(unsupportedPatch.compatiblePackages?.find { it.packageName == packageName }?.versions.orEmpty()) + fun openIncompatibleDialog(incompatiblePatch: PatchInfo) { + compatibleVersions.addAll(incompatiblePatch.compatiblePackages?.find { it.packageName == packageName }?.versions.orEmpty()) } fun toggleFlag(flag: Int) { @@ -217,7 +222,7 @@ class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.Vi } companion object { - const val SHOW_UNSUPPORTED = 1 // 2^0 + const val SHOW_INCOMPATIBLE = 1 // 2^0 const val SHOW_UNIVERSAL = 2 // 2^1 private val optionsSaver: Saver = snapshotStateMapSaver( diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/SelectedAppInfoViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/SelectedAppInfoViewModel.kt index 302b5e89..4067a659 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/SelectedAppInfoViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/SelectedAppInfoViewModel.kt @@ -30,14 +30,13 @@ import app.revanced.manager.domain.repository.PatchOptionsRepository import app.revanced.manager.domain.repository.PatchSelectionRepository import app.revanced.manager.network.downloader.LoadedDownloaderPlugin import app.revanced.manager.network.downloader.ParceledDownloaderData -import app.revanced.manager.patcher.patch.PatchInfo import app.revanced.manager.plugin.downloader.GetScope import app.revanced.manager.plugin.downloader.PluginHostApi import app.revanced.manager.plugin.downloader.UserInteractionException import app.revanced.manager.ui.model.BundleInfo import app.revanced.manager.ui.model.BundleInfo.Extensions.bundleInfoFlow -import app.revanced.manager.ui.model.BundleInfo.Extensions.toPatchSelection import app.revanced.manager.ui.model.BundleInfo.Extensions.requiredOptionsSet +import app.revanced.manager.ui.model.BundleInfo.Extensions.toPatchSelection import app.revanced.manager.ui.model.SelectedApp import app.revanced.manager.ui.model.navigation.Patcher import app.revanced.manager.ui.model.navigation.SelectedApplicationInfo @@ -275,25 +274,25 @@ class SelectedAppInfoViewModel( ) suspend fun getPatcherParams(): Patcher.ViewModelParams { - val allowUnsupported = prefs.disablePatchVersionCompatCheck.get() + val allowIncompatible = prefs.disablePatchVersionCompatCheck.get() val bundles = bundleInfoFlow.first() return Patcher.ViewModelParams( selectedApp, - getPatches(bundles, allowUnsupported), + getPatches(bundles, allowIncompatible), getOptionsFiltered(bundles) ) } fun getOptionsFiltered(bundles: List) = options.filtered(bundles) - fun getPatches(bundles: List, allowUnsupported: Boolean) = - selectionState.patches(bundles, allowUnsupported) + fun getPatches(bundles: List, allowIncompatible: Boolean) = + selectionState.patches(bundles, allowIncompatible) fun getCustomPatches( bundles: List, - allowUnsupported: Boolean + allowIncompatible: Boolean ): PatchSelection? = - (selectionState as? SelectionState.Customized)?.patches(bundles, allowUnsupported) + (selectionState as? SelectionState.Customized)?.patches(bundles, allowIncompatible) fun updateConfiguration(selection: PatchSelection?, options: Options) = viewModelScope.launch { val bundles = bundleInfoFlow.first() @@ -343,13 +342,13 @@ class SelectedAppInfoViewModel( } private sealed interface SelectionState : Parcelable { - fun patches(bundles: List, allowUnsupported: Boolean): PatchSelection + fun patches(bundles: List, allowIncompatible: Boolean): PatchSelection @Parcelize data class Customized(val patchSelection: PatchSelection) : SelectionState { - override fun patches(bundles: List, allowUnsupported: Boolean) = + override fun patches(bundles: List, allowIncompatible: Boolean) = bundles.toPatchSelection( - allowUnsupported + allowIncompatible ) { uid, patch -> patchSelection[uid]?.contains(patch.name) ?: false } @@ -357,8 +356,8 @@ private sealed interface SelectionState : Parcelable { @Parcelize data object Default : SelectionState { - override fun patches(bundles: List, allowUnsupported: Boolean) = - bundles.toPatchSelection(allowUnsupported) { _, patch -> patch.include } + override fun patches(bundles: List, allowIncompatible: Boolean) = + bundles.toPatchSelection(allowIncompatible) { _, patch -> patch.include } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fab90c15..33a272e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -87,7 +87,7 @@ Choose between light or dark theme Safeguards Disable version compatibility check - The check restricts patches to supported app versions + The check restricts patches to compatible app versions Selecting incompatible patches can result in a broken app.\n\nDo you want to proceed anyways? Require suggested app version Enforce selection of the suggested app version @@ -211,7 +211,7 @@ No patched apps found Tap on the patches to get more information about them %s selected - Incompatible patches + Incompatible patches Universal patches Patch selection and options has been reset to recommended defaults Patch options have been reset @@ -220,13 +220,12 @@ 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. - This version + 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. + This patch is not compatible with the selected app version (%1$s).\n\nIt is only compatible with the following version(s): %2$s. Continue with this version? - Not all patches support this version (%s). Do you want to continue anyway? + Not all patches are compatible with this version (%s). Do you want to continue anyway? Download application? The app you selected isn\'t installed. Do you want to download it? Failed to load APK @@ -400,7 +399,7 @@ The installation was cancelled manually. Try again? The installation was blocked. Review your device security settings and try again. The installation was prevented by an existing installation of the app. Uninstall the installed app and try again? - The app is incompatible with this device. Use an APK that is supported by this device and try again. + The app is incompatible with this device. Use an APK that is compatible by this device and try again. The app is invalid. Uninstall the app and try again? The app could not be installed due to insufficient storage. Free up some space and try again. The installation took too long. Try again? @@ -413,8 +412,8 @@ Add patch bundle Bundle URL Auto update - These patches are not compatible with the selected app version (%1$s).\n\nClick on the patches to see more details. - Unsupported patch + These patches are not compatible with the selected app version (%1$s).\n\nClick on the patches to see more details. + Incompatible patch Any Never show again Show update message on launch