feat: experimental patches setting

This commit is contained in:
Ax333l 2023-06-27 15:05:31 +02:00
parent f0edf35206
commit 47deee6438
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
5 changed files with 49 additions and 19 deletions

View File

@ -12,7 +12,8 @@ class PreferencesManager(
) : BasePreferenceManager(sharedPreferences) {
var dynamicColor by booleanPreference("dynamic_color", true)
var theme by enumPreference("theme", Theme.SYSTEM)
//var sentry by booleanPreference("sentry", true)
var allowExperimental by booleanPreference("allow_experimental", false)
var keystoreCommonName by stringPreference("keystore_cn", KeystoreManager.DEFAULT)
var keystorePass by stringPreference("keystore_pass", KeystoreManager.DEFAULT)

View File

@ -51,8 +51,6 @@ import app.revanced.manager.ui.viewmodel.PatchesSelectorViewModel.Companion.SHOW
import app.revanced.manager.util.PatchesSelection
import kotlinx.coroutines.launch
const val allowUnsupported = false
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun PatchesSelectorScreen(
@ -206,7 +204,7 @@ fun PatchesSelectorScreen(
patchList(
patches = bundle.unsupported,
filterFlag = SHOW_UNSUPPORTED,
supported = allowUnsupported
supported = vm.allowExperimental
) {
ListHeader(
title = stringResource(R.string.unsupported_patches),

View File

@ -1,6 +1,7 @@
package app.revanced.manager.ui.screen.settings
import android.os.Build
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
@ -65,24 +66,27 @@ fun GeneralSettingsScreen(
}
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ListItem(
modifier = Modifier.clickable { prefs.dynamicColor = !prefs.dynamicColor },
headlineContent = { Text(stringResource(R.string.dynamic_color)) },
supportingContent = { Text(stringResource(R.string.dynamic_color_description)) },
trailingContent = {
Switch(
checked = prefs.dynamicColor,
onCheckedChange = { prefs.dynamicColor = it })
}
BooleanItem(
value = prefs.dynamicColor,
onValueChange = { prefs.dynamicColor = it },
headline = R.string.dynamic_color,
description = R.string.dynamic_color_description
)
}
GroupHeader(stringResource(R.string.patcher))
BooleanItem(
value = prefs.allowExperimental,
onValueChange = { prefs.allowExperimental = it },
headline = R.string.experimental_patches,
description = R.string.experimental_patches_description
)
}
}
}
@Composable
fun ThemePicker(
private fun ThemePicker(
onDismiss: () -> Unit,
onConfirm: (Theme) -> Unit,
prefs: PreferencesManager = koinInject()
@ -96,10 +100,14 @@ fun ThemePicker(
Column {
Theme.values().forEach {
Row(
modifier = Modifier.fillMaxWidth().clickable { selectedTheme = it },
modifier = Modifier
.fillMaxWidth()
.clickable { selectedTheme = it },
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(selected = selectedTheme == it, onClick = { selectedTheme = it })
RadioButton(
selected = selectedTheme == it,
onClick = { selectedTheme = it })
Text(stringResource(it.displayName))
}
}
@ -114,4 +122,22 @@ fun ThemePicker(
}
}
)
}
}
@Composable
private fun BooleanItem(
value: Boolean,
onValueChange: (Boolean) -> Unit,
@StringRes headline: Int,
@StringRes description: Int
) = ListItem(
modifier = Modifier.clickable { onValueChange(!value) },
headlineContent = { Text(stringResource(headline)) },
supportingContent = { Text(stringResource(description)) },
trailingContent = {
Switch(
checked = value,
onCheckedChange = onValueChange,
)
}
)

View File

@ -8,10 +8,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.revanced.manager.domain.manager.PreferencesManager
import app.revanced.manager.domain.repository.PatchSelectionRepository
import app.revanced.manager.domain.repository.SourceRepository
import app.revanced.manager.patcher.patch.PatchInfo
import app.revanced.manager.ui.screen.allowUnsupported
import app.revanced.manager.util.AppInfo
import app.revanced.manager.util.PatchesSelection
import app.revanced.manager.util.SnapshotStateSet
@ -31,6 +31,8 @@ class PatchesSelectorViewModel(
val appInfo: AppInfo
) : ViewModel(), KoinComponent {
private val selectionRepository: PatchSelectionRepository = get()
private val prefs: PreferencesManager = get()
val allowExperimental get() = prefs.allowExperimental
val bundlesFlow = get<SourceRepository>().sources.flatMapLatestAndCombine(
combiner = { it }
@ -82,7 +84,7 @@ class PatchesSelectorViewModel(
selectedPatches.also {
selectionRepository.updateSelection(appInfo.packageName, it)
}.mapValues { it.value.toMutableList() }.apply {
if (allowUnsupported) {
if (allowExperimental) {
return@apply
}

View File

@ -28,6 +28,8 @@
<string name="dynamic_color_description">Adapt colors to the wallpaper</string>
<string name="theme">Theme</string>
<string name="theme_description">Choose between light or dark theme</string>
<string name="experimental_patches">Allow experimental patches</string>
<string name="experimental_patches_description">Allow patching incompatible patches with experimental versions, something may break</string>
<string name="import_keystore">Import keystore</string>
<string name="import_keystore_descripion">Import a custom keystore</string>
<string name="import_keystore_preset_default">Default</string>
@ -65,6 +67,7 @@
<string name="light">Light</string>
<string name="dark">Dark</string>
<string name="appearance">Appearance</string>
<string name="patching">Patching</string>
<string name="signing">Signing</string>
<string name="storage">Storage</string>
<string name="tab_apps">Apps</string>