Skip to content

Commit

Permalink
feat: experimental patches setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Axelen123 committed Jun 27, 2023
1 parent 923ce74 commit 9dd74f1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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))
}
}
Expand All @@ -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,
)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down Expand Up @@ -82,7 +84,7 @@ class PatchesSelectorViewModel(
selectedPatches.also {
selectionRepository.updateSelection(appInfo.packageName, it)
}.mapValues { it.value.toMutableList() }.apply {
if (allowUnsupported) {
if (allowExperimental) {
return@apply
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 9dd74f1

Please sign in to comment.