feat: Improve unsupported patch warnings (#2066)

Closes #2052
This commit is contained in:
Ushie 2024-07-29 18:21:10 +03:00 committed by GitHub
parent f126fe9fa8
commit c18901c35b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 71 additions and 54 deletions

View file

@ -2,12 +2,7 @@ package app.revanced.manager.ui.screen
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
@ -15,28 +10,8 @@ import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.HelpOutline import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.*
import androidx.compose.material.icons.outlined.Restore import androidx.compose.material3.*
import androidx.compose.material.icons.outlined.Save
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.WarningAmber
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -157,11 +132,19 @@ fun PatchesSelectorScreen(
} }
if (vm.compatibleVersions.isNotEmpty()) if (vm.compatibleVersions.isNotEmpty())
UnsupportedDialog( UnsupportedPatchDialog(
appVersion = vm.appVersion, appVersion = vm.appVersion,
supportedVersions = vm.compatibleVersions, supportedVersions = vm.compatibleVersions,
onDismissRequest = vm::dismissDialogs onDismissRequest = vm::dismissDialogs
) )
var showUnsupportedPatchesDialog by rememberSaveable {
mutableStateOf(false)
}
if (showUnsupportedPatchesDialog)
UnsupportedPatchesDialog(
appVersion = vm.appVersion,
onDismissRequest = { showUnsupportedPatchesDialog = false }
)
vm.optionsDialog?.let { (bundle, patch) -> vm.optionsDialog?.let { (bundle, patch) ->
OptionsDialog( OptionsDialog(
@ -214,12 +197,20 @@ fun PatchesSelectorScreen(
patch patch
), ),
onToggle = { onToggle = {
if (vm.selectionWarningEnabled) { when {
showSelectionWarning = true // Open unsupported dialog if the patch is not supported
} else if (vm.universalPatchWarningEnabled && patch.compatiblePackages == null) { !supported -> vm.openUnsupportedDialog(patch)
// Show selection warning if enabled
vm.selectionWarningEnabled -> showSelectionWarning = true
// Set pending universal patch action if the universal patch warning is enabled and there are no compatible packages
vm.universalPatchWarningEnabled && patch.compatiblePackages == null -> {
vm.pendingUniversalPatchAction = { vm.togglePatch(uid, patch) } vm.pendingUniversalPatchAction = { vm.togglePatch(uid, patch) }
} else { }
vm.togglePatch(uid, patch)
// Toggle the patch otherwise
else -> vm.togglePatch(uid, patch)
} }
}, },
supported = supported supported = supported
@ -270,7 +261,7 @@ fun PatchesSelectorScreen(
) { ) {
ListHeader( ListHeader(
title = stringResource(R.string.unsupported_patches), title = stringResource(R.string.unsupported_patches),
onHelpClick = { vm.openUnsupportedDialog(bundle.unsupported) } onHelpClick = { showUnsupportedPatchesDialog = true }
) )
} }
} }
@ -377,7 +368,7 @@ fun PatchesSelectorScreen(
) { ) {
ListHeader( ListHeader(
title = stringResource(R.string.unsupported_patches), title = stringResource(R.string.unsupported_patches),
onHelpClick = { vm.openUnsupportedDialog(bundle.unsupported) } onHelpClick = { showUnsupportedPatchesDialog = true }
) )
} }
} }
@ -388,7 +379,7 @@ fun PatchesSelectorScreen(
} }
@Composable @Composable
fun SelectionWarningDialog(onDismiss: () -> Unit) { private fun SelectionWarningDialog(onDismiss: () -> Unit) {
SafeguardDialog( SafeguardDialog(
onDismiss = onDismiss, onDismiss = onDismiss,
title = R.string.warning, title = R.string.warning,
@ -397,7 +388,7 @@ fun SelectionWarningDialog(onDismiss: () -> Unit) {
} }
@Composable @Composable
fun UniversalPatchWarningDialog( private fun UniversalPatchWarningDialog(
onCancel: () -> Unit, onCancel: () -> Unit,
onConfirm: () -> Unit onConfirm: () -> Unit
) { ) {
@ -429,7 +420,7 @@ fun UniversalPatchWarningDialog(
} }
@Composable @Composable
fun PatchItem( private fun PatchItem(
patch: PatchInfo, patch: PatchInfo,
onOptionsDialog: () -> Unit, onOptionsDialog: () -> Unit,
selected: Boolean, selected: Boolean,
@ -438,7 +429,7 @@ fun PatchItem(
) = ListItem( ) = ListItem(
modifier = Modifier modifier = Modifier
.let { if (!supported) it.alpha(0.5f) else it } .let { if (!supported) it.alpha(0.5f) else it }
.clickable(enabled = supported, onClick = onToggle) .clickable(onClick = onToggle)
.fillMaxSize(), .fillMaxSize(),
leadingContent = { leadingContent = {
Checkbox( Checkbox(
@ -459,7 +450,7 @@ fun PatchItem(
) )
@Composable @Composable
fun ListHeader( private fun ListHeader(
title: String, title: String,
onHelpClick: (() -> Unit)? = null onHelpClick: (() -> Unit)? = null
) { ) {
@ -485,18 +476,46 @@ fun ListHeader(
} }
@Composable @Composable
fun UnsupportedDialog( private fun UnsupportedPatchesDialog(
appVersion: String, appVersion: String,
supportedVersions: List<String>,
onDismissRequest: () -> Unit onDismissRequest: () -> Unit
) = AlertDialog( ) = AlertDialog(
icon = {
Icon(Icons.Outlined.WarningAmber, null)
},
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
confirmButton = { confirmButton = {
TextButton(onClick = onDismissRequest) { TextButton(onClick = onDismissRequest) {
Text(stringResource(R.string.ok)) Text(stringResource(R.string.ok))
} }
}, },
title = { Text(stringResource(R.string.unsupported_app)) }, title = { Text(stringResource(R.string.unsupported_patches)) },
text = {
Text(
stringResource(
R.string.unsupported_patches_dialog,
appVersion
)
)
}
)
@Composable
private fun UnsupportedPatchDialog(
appVersion: String,
supportedVersions: List<String>,
onDismissRequest: () -> Unit
) = AlertDialog(
icon = {
Icon(Icons.Outlined.WarningAmber, null)
},
onDismissRequest = onDismissRequest,
confirmButton = {
TextButton(onClick = onDismissRequest) {
Text(stringResource(R.string.ok))
}
},
title = { Text(stringResource(R.string.unsupported_patch)) },
text = { text = {
Text( Text(
stringResource( stringResource(
@ -510,7 +529,7 @@ fun UnsupportedDialog(
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun OptionsDialog( private fun OptionsDialog(
patch: PatchInfo, patch: PatchInfo,
values: Map<String, Any?>?, values: Map<String, Any?>?,
reset: () -> Unit, reset: () -> Unit,

View file

@ -190,10 +190,8 @@ class PatchesSelectorViewModel(input: Params) : ViewModel(), KoinComponent {
compatibleVersions.clear() compatibleVersions.clear()
} }
fun openUnsupportedDialog(unsupportedPatches: List<PatchInfo>) { fun openUnsupportedDialog(unsupportedPatch: PatchInfo) {
compatibleVersions.addAll(unsupportedPatches.flatMap { patch -> compatibleVersions.addAll(unsupportedPatch.compatiblePackages?.find { it.packageName == packageName }?.versions.orEmpty())
patch.compatiblePackages?.find { it.packageName == packageName }?.versions.orEmpty()
})
} }
fun toggleFlag(flag: Int) { fun toggleFlag(flag: Int) {

View file

@ -191,7 +191,6 @@
<string name="no_patched_apps_found">No patched apps found</string> <string name="no_patched_apps_found">No patched apps found</string>
<string name="tap_on_patches">Tap on the patches to get more information about them</string> <string name="tap_on_patches">Tap on the patches to get more information about them</string>
<string name="bundles_selected">%s selected</string> <string name="bundles_selected">%s selected</string>
<string name="unsupported_app">Unsupported app</string>
<string name="unsupported_patches">Unsupported patches</string> <string name="unsupported_patches">Unsupported patches</string>
<string name="universal_patches">Universal patches</string> <string name="universal_patches">Universal patches</string>
<string name="patch_selection_reset_toast">Patch selection and options has been reset to recommended defaults</string> <string name="patch_selection_reset_toast">Patch selection and options has been reset to recommended defaults</string>
@ -205,7 +204,7 @@
<string name="universal">Universal</string> <string name="universal">Universal</string>
<string name="unsupported">Unsupported</string> <string name="unsupported">Unsupported</string>
<string name="search_patches">Patch name</string> <string name="search_patches">Patch name</string>
<string name="app_not_supported">Some of the patches do not support this app version (%1$s). The patches only support the following version(s): %2$s.</string> <string name="app_not_supported">This patch is not compatible with the selected app version (%1$s).\n\nIt only supports the following version(s): %2$s.</string>
<string name="continue_with_version">Continue with this version?</string> <string name="continue_with_version">Continue with this version?</string>
<string name="version_not_supported">Not all patches support this version (%s). Do you want to continue anyway?</string> <string name="version_not_supported">Not all patches support this version (%s). Do you want to continue anyway?</string>
<string name="download_application">Download application?</string> <string name="download_application">Download application?</string>
@ -368,8 +367,9 @@
<string name="add_patch_bundle">Add patch bundle</string> <string name="add_patch_bundle">Add patch bundle</string>
<string name="bundle_url">Bundle URL</string> <string name="bundle_url">Bundle URL</string>
<string name="auto_update">Auto update</string> <string name="auto_update">Auto update</string>
<string name="unsupported_patches_dialog">These patches are not compatible with the selected app version (%1$s).\n\nClick on the patches to see more details.</string>
<string name="unsupported_patch">Unsupported patch</string>
<string name="never_show_again">Never show again</string> <string name="never_show_again">Never show again</string>
<string name="show_manager_update_dialog_on_launch">Show update message on launch</string> <string name="show_manager_update_dialog_on_launch">Show update message on launch</string>
<string name="show_manager_update_dialog_on_launch_description">Shows a popup notification whenever there is a new update available on launch.</string> <string name="show_manager_update_dialog_on_launch_description">Shows a popup notification whenever there is a new update available on launch.</string>
</resources> </resources>