Skip to content

fix: Use compatible rather than support when referring to patch compatibility #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions app/src/main/java/app/revanced/manager/ui/model/BundleInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ import kotlinx.coroutines.flow.map
data class BundleInfo(
val name: String,
val uid: Int,
val supported: List<PatchInfo>,
val unsupported: List<PatchInfo>,
val compatible: List<PatchInfo>,
val incompatible: List<PatchInfo>,
val universal: List<PatchInfo>
) {
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<BundleInfo>.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(
Expand All @@ -60,8 +60,8 @@ data class BundleInfo(
source.state.map { state ->
val bundle = state.patchBundleOrNull() ?: return@map null

val supported = mutableListOf<PatchInfo>()
val unsupported = mutableListOf<PatchInfo>()
val compatible = mutableListOf<PatchInfo>()
val incompatible = mutableListOf<PatchInfo>()
val universal = mutableListOf<PatchInfo>()

bundle.patches.filter { it.compatibleWith(packageName) }.forEach {
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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) ->
Expand Down Expand Up @@ -204,7 +204,7 @@ fun PatchesSelectorScreen(
uid: Int,
patches: List<PatchInfo>,
visible: Boolean,
supported: Boolean,
compatible: Boolean,
header: (@Composable () -> Unit)? = null
) {
if (patches.isNotEmpty() && visible) {
Expand All @@ -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
Expand All @@ -245,7 +245,7 @@ fun PatchesSelectorScreen(
else -> vm.togglePatch(uid, patch)
}
},
supported = supported
compatible = compatible
)
}
}
Expand Down Expand Up @@ -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),
Expand All @@ -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 }
)
}
}
Expand Down Expand Up @@ -427,29 +427,29 @@ 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),
)
}
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 }
)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -559,7 +559,7 @@ fun ListHeader(
}

@Composable
private fun UnsupportedPatchesDialog(
private fun IncompatiblePatchesDialog(
appVersion: String,
onDismissRequest: () -> Unit
) = AlertDialog(
Expand All @@ -572,21 +572,21 @@ 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
)
)
}
)

@Composable
private fun UnsupportedPatchDialog(
private fun IncompatiblePatchDialog(
appVersion: String,
supportedVersions: List<String>,
compatibleVersions: List<String>,
onDismissRequest: () -> Unit
) = AlertDialog(
icon = {
Expand All @@ -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(", ")
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.coroutines.flow.first
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import kotlinx.collections.immutable.*
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

@OptIn(SavedStateHandleSaveableApi::class)
class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.ViewModelParams) :
Expand Down Expand Up @@ -208,16 +213,16 @@ 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) {
filter = filter xor flag
}

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<PersistentOptions, Options> = snapshotStateMapSaver(
Expand Down
Loading