diff --git a/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt b/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt index 57810a05e4..2b04bd41c7 100644 --- a/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt +++ b/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt @@ -56,7 +56,7 @@ class EditorContext(private val prefs: MutablePreferences) { abstract class Preference( private val dataStore: DataStore, - protected val default: T + val default: T ) { internal abstract fun Preferences.read(): T internal abstract fun MutablePreferences.write(value: T) diff --git a/app/src/main/java/app/revanced/manager/ui/component/settings/SafeguardBooleanItem.kt b/app/src/main/java/app/revanced/manager/ui/component/settings/SafeguardBooleanItem.kt new file mode 100644 index 0000000000..b48d80d1e8 --- /dev/null +++ b/app/src/main/java/app/revanced/manager/ui/component/settings/SafeguardBooleanItem.kt @@ -0,0 +1,54 @@ +package app.revanced.manager.ui.component.settings + +import androidx.annotation.StringRes +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import app.revanced.manager.domain.manager.base.Preference +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch + +@Composable +fun SafeguardBooleanItem( + modifier: Modifier = Modifier, + preference: Preference, + coroutineScope: CoroutineScope = rememberCoroutineScope(), + @StringRes headline: Int, + @StringRes description: Int, + @StringRes confirmationText: Int +) { + val value by preference.getAsState() + var showSafeguardWarning by rememberSaveable { + mutableStateOf(false) + } + + if (showSafeguardWarning) { + SafeguardConfirmationDialog( + onDismiss = { showSafeguardWarning = false }, + onConfirm = { + coroutineScope.launch { preference.update(!value) } + showSafeguardWarning = false + }, + body = stringResource(confirmationText) + ) + } + + BooleanItem( + modifier = modifier, + value = value, + onValueChange = { + if (it != preference.default) { + showSafeguardWarning = true + } else { + coroutineScope.launch { preference.update(it) } + } + }, + headline = headline, + description = description + ) +} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/manager/ui/component/settings/SafeguardConfirmationDialog.kt b/app/src/main/java/app/revanced/manager/ui/component/settings/SafeguardConfirmationDialog.kt new file mode 100644 index 0000000000..d3b6d0e818 --- /dev/null +++ b/app/src/main/java/app/revanced/manager/ui/component/settings/SafeguardConfirmationDialog.kt @@ -0,0 +1,46 @@ +package app.revanced.manager.ui.component.settings + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.WarningAmber +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import app.revanced.manager.R + +@Composable +fun SafeguardConfirmationDialog( + onDismiss: () -> Unit, + onConfirm: () -> Unit, + body: String, +) { + AlertDialog( + onDismissRequest = onDismiss, + confirmButton = { + TextButton(onClick = onConfirm) { + Text(stringResource(R.string.yes)) + } + }, + dismissButton = { + TextButton(onClick = onDismiss) { + Text(stringResource(R.string.no)) + } + }, + icon = { + Icon(Icons.Outlined.WarningAmber, null) + }, + title = { + Text( + text = stringResource(id = R.string.warning), + style = MaterialTheme.typography.headlineSmall.copy(textAlign = TextAlign.Center) + ) + }, + text = { + Text(body) + } + ) +} diff --git a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt index 4c3be2a400..7cfaf26715 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt @@ -39,6 +39,7 @@ import app.revanced.manager.ui.component.ColumnWithScrollbar import app.revanced.manager.ui.component.GroupHeader import app.revanced.manager.ui.component.settings.BooleanItem import app.revanced.manager.ui.component.settings.IntegerItem +import app.revanced.manager.ui.component.settings.SafeguardBooleanItem import app.revanced.manager.ui.component.settings.SettingsListItem import app.revanced.manager.ui.viewmodel.AdvancedSettingsViewModel import org.koin.androidx.compose.koinViewModel @@ -121,29 +122,33 @@ fun AdvancedSettingsScreen( ) GroupHeader(stringResource(R.string.safeguards)) - BooleanItem( + SafeguardBooleanItem( preference = vm.prefs.disablePatchVersionCompatCheck, coroutineScope = vm.viewModelScope, headline = R.string.patch_compat_check, - description = R.string.patch_compat_check_description + description = R.string.patch_compat_check_description, + confirmationText = R.string.patch_compat_check_confirmation ) - BooleanItem( + SafeguardBooleanItem( preference = vm.prefs.disableUniversalPatchWarning, coroutineScope = vm.viewModelScope, headline = R.string.universal_patches_safeguard, - description = R.string.universal_patches_safeguard_description + description = R.string.universal_patches_safeguard_description, + confirmationText = R.string.universal_patches_safeguard_confirmation ) - BooleanItem( + SafeguardBooleanItem( preference = vm.prefs.suggestedVersionSafeguard, coroutineScope = vm.viewModelScope, headline = R.string.suggested_version_safeguard, - description = R.string.suggested_version_safeguard_description + description = R.string.suggested_version_safeguard_description, + confirmationText = R.string.suggested_version_safeguard_confirmation ) - BooleanItem( + SafeguardBooleanItem( preference = vm.prefs.disableSelectionWarning, coroutineScope = vm.viewModelScope, headline = R.string.patch_selection_safeguard, - description = R.string.patch_selection_safeguard_description + description = R.string.patch_selection_safeguard_description, + confirmationText = R.string.patch_selection_safeguard_confirmation ) GroupHeader(stringResource(R.string.debugging)) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36cbea3aa8..733de07c2e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -74,12 +74,16 @@ Safeguards Disable version compatibility check The check restricts patches to supported app versions + The check restricts patches to supported app versions Require suggested app version Enforce selection of the suggested app version + Enforce selection of the suggested app version Allow changing patch selection Do not prevent selecting or deselecting patches + Do not prevent selecting or deselecting patches Disable universal patch warning Disables the warning that appears when you try to select universal patches + Disables the warning that appears when you try to select universal patches Import keystore Import a custom keystore Enter keystore credentials @@ -125,6 +129,8 @@ Options OK + Yes + No Edit Value Reset