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.clickable
import androidx.compose.foundation.layout.Arrangement
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.layout.*
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyListState
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.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.outlined.FilterList
import androidx.compose.material.icons.outlined.Restore
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.material.icons.outlined.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
@ -157,11 +132,19 @@ fun PatchesSelectorScreen(
}
if (vm.compatibleVersions.isNotEmpty())
UnsupportedDialog(
UnsupportedPatchDialog(
appVersion = vm.appVersion,
supportedVersions = vm.compatibleVersions,
onDismissRequest = vm::dismissDialogs
)
var showUnsupportedPatchesDialog by rememberSaveable {
mutableStateOf(false)
}
if (showUnsupportedPatchesDialog)
UnsupportedPatchesDialog(
appVersion = vm.appVersion,
onDismissRequest = { showUnsupportedPatchesDialog = false }
)
vm.optionsDialog?.let { (bundle, patch) ->
OptionsDialog(
@ -214,12 +197,20 @@ fun PatchesSelectorScreen(
patch
),
onToggle = {
if (vm.selectionWarningEnabled) {
showSelectionWarning = true
} else if (vm.universalPatchWarningEnabled && patch.compatiblePackages == null) {
vm.pendingUniversalPatchAction = { vm.togglePatch(uid, patch) }
} else {
vm.togglePatch(uid, patch)
when {
// Open unsupported dialog if the patch is not supported
!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) }
}
// Toggle the patch otherwise
else -> vm.togglePatch(uid, patch)
}
},
supported = supported
@ -270,7 +261,7 @@ fun PatchesSelectorScreen(
) {
ListHeader(
title = stringResource(R.string.unsupported_patches),
onHelpClick = { vm.openUnsupportedDialog(bundle.unsupported) }
onHelpClick = { showUnsupportedPatchesDialog = true }
)
}
}
@ -377,7 +368,7 @@ fun PatchesSelectorScreen(
) {
ListHeader(
title = stringResource(R.string.unsupported_patches),
onHelpClick = { vm.openUnsupportedDialog(bundle.unsupported) }
onHelpClick = { showUnsupportedPatchesDialog = true }
)
}
}
@ -388,7 +379,7 @@ fun PatchesSelectorScreen(
}
@Composable
fun SelectionWarningDialog(onDismiss: () -> Unit) {
private fun SelectionWarningDialog(onDismiss: () -> Unit) {
SafeguardDialog(
onDismiss = onDismiss,
title = R.string.warning,
@ -397,7 +388,7 @@ fun SelectionWarningDialog(onDismiss: () -> Unit) {
}
@Composable
fun UniversalPatchWarningDialog(
private fun UniversalPatchWarningDialog(
onCancel: () -> Unit,
onConfirm: () -> Unit
) {
@ -429,7 +420,7 @@ fun UniversalPatchWarningDialog(
}
@Composable
fun PatchItem(
private fun PatchItem(
patch: PatchInfo,
onOptionsDialog: () -> Unit,
selected: Boolean,
@ -438,7 +429,7 @@ fun PatchItem(
) = ListItem(
modifier = Modifier
.let { if (!supported) it.alpha(0.5f) else it }
.clickable(enabled = supported, onClick = onToggle)
.clickable(onClick = onToggle)
.fillMaxSize(),
leadingContent = {
Checkbox(
@ -459,7 +450,7 @@ fun PatchItem(
)
@Composable
fun ListHeader(
private fun ListHeader(
title: String,
onHelpClick: (() -> Unit)? = null
) {
@ -485,18 +476,46 @@ fun ListHeader(
}
@Composable
fun UnsupportedDialog(
private fun UnsupportedPatchesDialog(
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_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(
stringResource(
@ -510,7 +529,7 @@ fun UnsupportedDialog(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun OptionsDialog(
private fun OptionsDialog(
patch: PatchInfo,
values: Map<String, Any?>?,
reset: () -> Unit,
@ -551,4 +570,4 @@ fun OptionsDialog(
}
}
}
}
}

View file

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

View file

@ -191,7 +191,6 @@
<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="bundles_selected">%s selected</string>
<string name="unsupported_app">Unsupported app</string>
<string name="unsupported_patches">Unsupported 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>
@ -205,7 +204,7 @@
<string name="universal">Universal</string>
<string name="unsupported">Unsupported</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="version_not_supported">Not all patches support this version (%s). Do you want to continue anyway?</string>
<string name="download_application">Download application?</string>
@ -368,8 +367,9 @@
<string name="add_patch_bundle">Add patch bundle</string>
<string name="bundle_url">Bundle URL</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="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>
</resources>