Remove unnecessary changes and deprecated code

This commit is contained in:
Ushie 2025-02-05 19:03:25 +03:00
parent bbfd625ac1
commit f4a2b06276
No known key found for this signature in database
GPG Key ID: B3AAD18842E34632
20 changed files with 125 additions and 139 deletions

View File

@ -47,6 +47,7 @@ android {
isPseudoLocalesEnabled = true isPseudoLocalesEnabled = true
} }
buildConfigField("long", "BUILD_ID", "0L") buildConfigField("long", "BUILD_ID", "0L")
} }
} }

View File

@ -44,11 +44,11 @@ import app.revanced.manager.ui.screen.SettingsScreen
import app.revanced.manager.ui.screen.UpdateScreen import app.revanced.manager.ui.screen.UpdateScreen
import app.revanced.manager.ui.screen.settings.AboutSettingsScreen import app.revanced.manager.ui.screen.settings.AboutSettingsScreen
import app.revanced.manager.ui.screen.settings.AdvancedSettingsScreen import app.revanced.manager.ui.screen.settings.AdvancedSettingsScreen
import app.revanced.manager.ui.screen.settings.BackupRestoreSettingsScreen
import app.revanced.manager.ui.screen.settings.ContributorScreen import app.revanced.manager.ui.screen.settings.ContributorScreen
import app.revanced.manager.ui.screen.settings.DeveloperOptionsScreen import app.revanced.manager.ui.screen.settings.DeveloperOptionsScreen
import app.revanced.manager.ui.screen.settings.DownloadsSettingsScreen import app.revanced.manager.ui.screen.settings.DownloadsSettingsScreen
import app.revanced.manager.ui.screen.settings.GeneralSettingsScreen import app.revanced.manager.ui.screen.settings.GeneralSettingsScreen
import app.revanced.manager.ui.screen.settings.BackupRestoreSettingsScreen
import app.revanced.manager.ui.screen.settings.LicensesScreen import app.revanced.manager.ui.screen.settings.LicensesScreen
import app.revanced.manager.ui.screen.settings.update.ChangelogsScreen import app.revanced.manager.ui.screen.settings.update.ChangelogsScreen
import app.revanced.manager.ui.theme.ReVancedManagerTheme import app.revanced.manager.ui.theme.ReVancedManagerTheme
@ -279,7 +279,6 @@ private fun ReVancedManager(vm: MainViewModel) {
AdvancedSettingsScreen(onBackClick = navController::popBackStack) AdvancedSettingsScreen(onBackClick = navController::popBackStack)
} }
composable<Settings.Downloads> { composable<Settings.Downloads> {
DownloadsSettingsScreen(onBackClick = navController::popBackStack) DownloadsSettingsScreen(onBackClick = navController::popBackStack)
} }

View File

@ -22,9 +22,10 @@ class PreferencesManager(
val managerAutoUpdates = booleanPreference("manager_auto_updates", false) val managerAutoUpdates = booleanPreference("manager_auto_updates", false)
val showManagerUpdateDialogOnLaunch = booleanPreference("show_manager_update_dialog_on_launch", true) val showManagerUpdateDialogOnLaunch = booleanPreference("show_manager_update_dialog_on_launch", true)
val allowIncompatibleMixing = booleanPreference("allow_incompatible_mixing", false) val disablePatchVersionCompatCheck = booleanPreference("disable_patch_version_compatibility_check", false)
val allowChangingPatchSelection = booleanPreference("allow_changing_patch_selection", false) val disableSelectionWarning = booleanPreference("disable_selection_warning", false)
val allowUniversalPatch = booleanPreference("allow_universal_patch", false) val disableUniversalPatchWarning = booleanPreference("disable_universal_patch_warning", false)
val suggestedVersionSafeguard = booleanPreference("suggested_version_safeguard", true)
val acknowledgedDownloaderPlugins = stringSetPreference("acknowledged_downloader_plugins", emptySet()) val acknowledgedDownloaderPlugins = stringSetPreference("acknowledged_downloader_plugins", emptySet())
} }

View File

@ -76,7 +76,7 @@ class PatchBundleRepository(
suspend fun isVersionAllowed(packageName: String, version: String) = suspend fun isVersionAllowed(packageName: String, version: String) =
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
if (!prefs.allowIncompatibleMixing.get()) return@withContext true if (!prefs.suggestedVersionSafeguard.get()) return@withContext true
val suggestedVersion = suggestedVersions.first()[packageName] ?: return@withContext true val suggestedVersion = suggestedVersions.first()[packageName] ?: return@withContext true
suggestedVersion == version suggestedVersion == version

View File

@ -70,9 +70,6 @@ object Settings {
@Serializable @Serializable
data object Advanced : Destination data object Advanced : Destination
@Serializable
data object Updates : Destination
@Serializable @Serializable
data object Downloads : Destination data object Downloads : Destination

View File

@ -66,7 +66,7 @@ fun SelectedAppInfoScreen(
val version = vm.selectedApp.version val version = vm.selectedApp.version
val bundles by vm.bundleInfoFlow.collectAsStateWithLifecycle(emptyList()) val bundles by vm.bundleInfoFlow.collectAsStateWithLifecycle(emptyList())
val allowIncompatiblePatches by vm.prefs.allowIncompatibleMixing.getAsState() val allowIncompatiblePatches by vm.prefs.disablePatchVersionCompatCheck.getAsState()
val patches = remember(bundles, allowIncompatiblePatches) { val patches = remember(bundles, allowIncompatiblePatches) {
vm.getPatches(bundles, allowIncompatiblePatches) vm.getPatches(bundles, allowIncompatiblePatches)
} }

View File

@ -4,8 +4,14 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.* import androidx.compose.material.icons.outlined.Download
import androidx.compose.material3.* import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.SwapVert
import androidx.compose.material.icons.outlined.Tune
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource

View File

@ -53,7 +53,7 @@ fun AboutSettingsScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
onChangelogClick: () -> Unit, onChangelogClick: () -> Unit,
navigate: (Settings.Destination) -> Unit, navigate: (Settings.Destination) -> Unit,
vm: AboutViewModel = koinViewModel() viewModel: AboutViewModel = koinViewModel()
) { ) {
val context = LocalContext.current val context = LocalContext.current
// painterResource() is broken on release builds for some reason. // painterResource() is broken on release builds for some reason.
@ -61,11 +61,11 @@ fun AboutSettingsScreen(
AppCompatResources.getDrawable(context, R.drawable.ic_logo_ring) AppCompatResources.getDrawable(context, R.drawable.ic_logo_ring)
}) })
val (preferredSocials, socials) = remember(vm.socials) { val (preferredSocials, socials) = remember(viewModel.socials) {
vm.socials.partition(ReVancedSocial::preferred) viewModel.socials.partition(ReVancedSocial::preferred)
} }
val preferredSocialButtons = remember(preferredSocials, vm.donate, vm.contact) { val preferredSocialButtons = remember(preferredSocials, viewModel.donate, viewModel.contact) {
preferredSocials.map { preferredSocials.map {
Triple( Triple(
getSocialIcon(it.name), getSocialIcon(it.name),
@ -75,7 +75,7 @@ fun AboutSettingsScreen(
} }
) )
} + listOfNotNull( } + listOfNotNull(
vm.donate?.let { viewModel.donate?.let {
Triple( Triple(
Icons.Outlined.FavoriteBorder, Icons.Outlined.FavoriteBorder,
context.getString(R.string.donate), context.getString(R.string.donate),
@ -84,7 +84,7 @@ fun AboutSettingsScreen(
} }
) )
}, },
vm.contact?.let { viewModel.contact?.let {
Triple( Triple(
Icons.Outlined.MailOutline, Icons.Outlined.MailOutline,
context.getString(R.string.contact), context.getString(R.string.contact),
@ -114,13 +114,11 @@ fun AboutSettingsScreen(
stringResource(R.string.changelog_description), stringResource(R.string.changelog_description),
third = { onChangelogClick } third = { onChangelogClick }
), ),
Triple( Triple(stringResource(R.string.submit_feedback),
stringResource(R.string.submit_feedback),
stringResource(R.string.submit_feedback_description), stringResource(R.string.submit_feedback_description),
third = { third = {
context.openUrl("https://github.com/ReVanced/revanced-manager/issues/new/choose") context.openUrl("https://github.com/ReVanced/revanced-manager/issues/new/choose")
}, }),
),
Triple( Triple(
stringResource(R.string.contributors), stringResource(R.string.contributors),
stringResource(R.string.contributors_description), stringResource(R.string.contributors_description),

View File

@ -90,37 +90,45 @@ fun AdvancedSettingsScreen(
.fillMaxSize() .fillMaxSize()
.padding(paddingValues) .padding(paddingValues)
) { ) {
val apiSource by vm.prefs.api.getAsState() GroupHeader(stringResource(R.string.manager))
var showApiSourceDialog by rememberSaveable { mutableStateOf(false) }
if (showApiSourceDialog) { val apiUrl by vm.prefs.api.getAsState()
APISourceDialog( var showApiUrlDialog by rememberSaveable { mutableStateOf(false) }
currentUrl = apiSource,
if (showApiUrlDialog) {
APIUrlDialog(
currentUrl = apiUrl,
defaultUrl = vm.prefs.api.default, defaultUrl = vm.prefs.api.default,
onSubmit = { onSubmit = {
showApiSourceDialog = false showApiUrlDialog = false
it?.let(vm::setApiSource) it?.let(vm::setApiSource)
} }
) )
} }
GroupHeader(stringResource(R.string.revanced_patcher)) GroupHeader(stringResource(R.string.patcher))
BooleanItem(
preference = vm.prefs.useProcessRuntime,
coroutineScope = vm.viewModelScope,
headline = R.string.process_runtime,
description = R.string.process_runtime_description,
)
IntegerItem( IntegerItem(
preference = vm.prefs.patcherProcessMemoryLimit, preference = vm.prefs.patcherProcessMemoryLimit,
coroutineScope = vm.viewModelScope, coroutineScope = vm.viewModelScope,
headline = R.string.process_runtime_memory_limit, headline = R.string.process_runtime_memory_limit,
description = vm.prefs.patcherProcessMemoryLimit.getAsState().value, description = R.string.process_runtime_memory_limit_description,
) )
GroupHeader(stringResource(R.string.manager)) GroupHeader(stringResource(R.string.manager))
SettingsListItem( SettingsListItem(
headlineContent = stringResource(R.string.api_source), headlineContent = stringResource(R.string.api_source),
supportingContent = apiSource, supportingContent = apiUrl,
modifier = Modifier.clickable { modifier = Modifier.clickable {
showApiSourceDialog = true showApiUrlDialog = true
}, },
trailingContent = { trailingContent = {
IconButton(onClick = { showApiSourceDialog = true }) { IconButton(onClick = { showApiUrlDialog = true }) {
Icon( Icon(
Icons.Outlined.Edit, Icons.Outlined.Edit,
contentDescription = stringResource(R.string.edit) contentDescription = stringResource(R.string.edit)
@ -129,21 +137,21 @@ fun AdvancedSettingsScreen(
} }
) )
SafeguardBooleanItem( SafeguardBooleanItem(
preference = vm.prefs.allowIncompatibleMixing, preference = vm.prefs.disablePatchVersionCompatCheck,
coroutineScope = vm.viewModelScope, coroutineScope = vm.viewModelScope,
headline = R.string.allow_compatibility_mixing, headline = R.string.allow_compatibility_mixing,
description = R.string.allow_compatibility_mixing_description, description = R.string.allow_compatibility_mixing_description,
confirmationText = R.string.allow_compatibility_mixing_confirmation confirmationText = R.string.allow_compatibility_mixing_confirmation
) )
SafeguardBooleanItem( SafeguardBooleanItem(
preference = vm.prefs.allowUniversalPatch, preference = vm.prefs.disableUniversalPatchWarning,
coroutineScope = vm.viewModelScope, coroutineScope = vm.viewModelScope,
headline = R.string.universal_patches_safeguard, 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 confirmationText = R.string.universal_patches_safeguard_confirmation
) )
SafeguardBooleanItem( SafeguardBooleanItem(
preference = vm.prefs.allowChangingPatchSelection, preference = vm.prefs.disableSelectionWarning,
coroutineScope = vm.viewModelScope, coroutineScope = vm.viewModelScope,
headline = R.string.patch_selection_safeguard, headline = R.string.patch_selection_safeguard,
description = R.string.patch_selection_safeguard_description, description = R.string.patch_selection_safeguard_description,
@ -152,7 +160,7 @@ fun AdvancedSettingsScreen(
GroupHeader(stringResource(R.string.update)) GroupHeader(stringResource(R.string.update))
BooleanItem( BooleanItem(
preference = vm.showManagerUpdateDialogOnLaunch, preference = vm.prefs.showManagerUpdateDialogOnLaunch,
headline = R.string.show_manager_update_dialog_on_launch, headline = R.string.show_manager_update_dialog_on_launch,
description = R.string.check_for_update_auto_description description = R.string.check_for_update_auto_description
) )
@ -176,10 +184,11 @@ fun AdvancedSettingsScreen(
) )
val clipboard = remember { context.getSystemService<ClipboardManager>()!! } val clipboard = remember { context.getSystemService<ClipboardManager>()!! }
val deviceContent = """ val deviceContent = """
Version: ${BuildConfig.VERSION_NAME}, ${BuildConfig.BUILD_TYPE} (${BuildConfig.VERSION_CODE}) Version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})
Build type: ${BuildConfig.BUILD_TYPE}
Model: ${Build.MODEL} Model: ${Build.MODEL}
Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT}) Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})
Preferred Architectures: ${Build.SUPPORTED_ABIS.joinToString(", ")} Supported Archs: ${Build.SUPPORTED_ABIS.joinToString(", ")}
Memory limit: $memoryLimit Memory limit: $memoryLimit
""".trimIndent() """.trimIndent()
SettingsListItem( SettingsListItem(
@ -202,15 +211,15 @@ fun AdvancedSettingsScreen(
} }
@Composable @Composable
private fun APISourceDialog(currentUrl: String, defaultUrl: String, onSubmit: (String?) -> Unit) { private fun APIUrlDialog(currentUrl: String, defaultUrl: String, onSubmit: (String?) -> Unit) {
var source by rememberSaveable(currentUrl) { mutableStateOf(currentUrl) } var url by rememberSaveable(currentUrl) { mutableStateOf(currentUrl) }
AlertDialog( AlertDialog(
onDismissRequest = { onSubmit(null) }, onDismissRequest = { onSubmit(null) },
confirmButton = { confirmButton = {
TextButton( TextButton(
onClick = { onClick = {
onSubmit(source) onSubmit(url)
} }
) { ) {
Text(stringResource(R.string.api_source_dialog_save)) Text(stringResource(R.string.api_source_dialog_save))
@ -247,11 +256,11 @@ private fun APISourceDialog(currentUrl: String, defaultUrl: String, onSubmit: (S
) )
OutlinedTextField( OutlinedTextField(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
value = source, value = url,
onValueChange = { source = it }, onValueChange = { url = it },
label = { Text(stringResource(R.string.api_source)) }, label = { Text(stringResource(R.string.api_source)) },
trailingIcon = { trailingIcon = {
IconButton(onClick = { source = defaultUrl }) { IconButton(onClick = { url = defaultUrl }) {
Icon(Icons.Outlined.Restore, stringResource(R.string.api_source_dialog_reset)) Icon(Icons.Outlined.Restore, stringResource(R.string.api_source_dialog_reset))
} }
} }

View File

@ -32,7 +32,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -57,50 +56,50 @@ import org.koin.androidx.compose.koinViewModel
@Composable @Composable
fun BackupRestoreSettingsScreen( fun BackupRestoreSettingsScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
vm: ImportExportViewModel = koinViewModel() viewModel: ImportExportViewModel = koinViewModel()
) { ) {
val context = LocalContext.current val context = LocalContext.current
val importKeystoreLauncher = val importKeystoreLauncher =
rememberLauncherForActivityResult(contract = ActivityResultContracts.GetContent()) { rememberLauncherForActivityResult(contract = ActivityResultContracts.GetContent()) {
it?.let { uri -> vm.startKeystoreImport(uri) } it?.let { uri -> viewModel.startKeystoreImport(uri) }
} }
val exportKeystoreLauncher = val exportKeystoreLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("*/*")) { rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("*/*")) {
it?.let(vm::exportKeystore) it?.let(viewModel::exportKeystore)
} }
val patchBundles by vm.patchBundles.collectAsStateWithLifecycle(initialValue = emptyList()) val patchBundles by viewModel.patchBundles.collectAsStateWithLifecycle(initialValue = emptyList())
val packagesWithOptions by vm.packagesWithOptions.collectAsStateWithLifecycle(initialValue = emptySet()) val packagesWithOptions by viewModel.packagesWithOptions.collectAsStateWithLifecycle(initialValue = emptySet())
vm.selectionAction?.let { action -> viewModel.selectionAction?.let { action ->
val launcher = rememberLauncherForActivityResult(action.activityContract) { uri -> val launcher = rememberLauncherForActivityResult(action.activityContract) { uri ->
if (uri == null) { if (uri == null) {
vm.clearSelectionAction() viewModel.clearSelectionAction()
} else { } else {
vm.executeSelectionAction(uri) viewModel.executeSelectionAction(uri)
} }
} }
if (vm.selectedBundle == null) { if (viewModel.selectedBundle == null) {
BundleSelector(patchBundles) { BundleSelector(patchBundles) {
if (it == null) { if (it == null) {
vm.clearSelectionAction() viewModel.clearSelectionAction()
} else { } else {
vm.selectBundle(it) viewModel.selectBundle(it)
launcher.launch(action.activityArg) launcher.launch(action.activityArg)
} }
} }
} }
} }
if (vm.showCredentialsDialog) { if (viewModel.showCredentialsDialog) {
KeystoreCredentialsDialog( KeystoreCredentialsDialog(
onDismissRequest = vm::cancelKeystoreImport, onDismissRequest = viewModel::cancelKeystoreImport,
onSubmit = { cn, pass -> onSubmit = { cn, pass ->
vm.viewModelScope.launch { viewModel.viewModelScope.launch {
uiSafe(context, R.string.failed_to_import_keystore, "Failed to import keystore") { uiSafe(context, R.string.failed_to_import_keystore, "Failed to import keystore") {
val result = vm.tryKeystoreImport(cn, pass) val result = viewModel.tryKeystoreImport(cn, pass)
if (!result) context.toast(context.getString(R.string.restore_keystore_wrong_credentials)) if (!result) context.toast(context.getString(R.string.restore_keystore_wrong_credentials))
} }
} }
@ -134,7 +133,7 @@ fun BackupRestoreSettingsScreen(
if (showPackageSelector) { if (showPackageSelector) {
PackageSelector(packages = packagesWithOptions) { selected -> PackageSelector(packages = packagesWithOptions) { selected ->
selected?.let(vm::resetOptionsForPackage) selected?.let(viewModel::resetOptionsForPackage)
showPackageSelector = false showPackageSelector = false
} }
@ -142,7 +141,7 @@ fun BackupRestoreSettingsScreen(
if (showBundleSelector) { if (showBundleSelector) {
BundleSelector(bundles = patchBundles) { bundle -> BundleSelector(bundles = patchBundles) { bundle ->
bundle?.let(vm::clearOptionsForBundle) bundle?.let(viewModel::clearOptionsForBundle)
showBundleSelector = false showBundleSelector = false
} }
@ -151,7 +150,7 @@ fun BackupRestoreSettingsScreen(
GroupHeader(stringResource(R.string.keystore)) GroupHeader(stringResource(R.string.keystore))
GroupItem( GroupItem(
onClick = { onClick = {
if (!vm.canExport()) { if (!viewModel.canExport()) {
context.toast(context.getString(R.string.backup_keystore_unavailable)) context.toast(context.getString(R.string.backup_keystore_unavailable))
return@GroupItem return@GroupItem
} }
@ -168,7 +167,7 @@ fun BackupRestoreSettingsScreen(
description = R.string.restore_keystore_description description = R.string.restore_keystore_description
) )
GroupItem( GroupItem(
onClick = vm::regenerateKeystore, onClick = viewModel::regenerateKeystore,
headline = { headline = {
Text( Text(
stringResource(R.string.regenerate_keystore), stringResource(R.string.regenerate_keystore),
@ -180,17 +179,17 @@ fun BackupRestoreSettingsScreen(
GroupHeader(stringResource(R.string.patch_selection)) GroupHeader(stringResource(R.string.patch_selection))
GroupItem( GroupItem(
onClick = vm::exportSelection, onClick = viewModel::exportSelection,
headline = R.string.backup, headline = R.string.backup,
description = R.string.restore_patch_selection_description description = R.string.restore_patch_selection_description
) )
GroupItem( GroupItem(
onClick = vm::importSelection, onClick = viewModel::importSelection,
headline = R.string.restore, headline = R.string.restore,
description = R.string.backup_patch_selection_description description = R.string.backup_patch_selection_description
) )
GroupItem( GroupItem(
onClick = vm::resetSelection, // TODO: allow resetting selection for specific bundle or package name. onClick = viewModel::resetSelection, // TODO: allow resetting selection for specific bundle or package name.
headline = { headline = {
Text( Text(
stringResource(R.string.reset), stringResource(R.string.reset),
@ -203,7 +202,7 @@ fun BackupRestoreSettingsScreen(
GroupHeader(stringResource(R.string.patch_options)) GroupHeader(stringResource(R.string.patch_options))
// TODO: patch options import/export. // TODO: patch options import/export.
GroupItem( GroupItem(
onClick = vm::resetOptions, onClick = viewModel::resetOptions,
headline = { headline = {
Text( Text(
stringResource(R.string.reset), stringResource(R.string.reset),

View File

@ -53,9 +53,9 @@ import org.koin.androidx.compose.koinViewModel
@Composable @Composable
fun ContributorScreen( fun ContributorScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
vm: ContributorViewModel = koinViewModel() viewModel: ContributorViewModel = koinViewModel()
) { ) {
val repositories = vm.repositories val repositories = viewModel.repositories
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
Scaffold( Scaffold(

View File

@ -53,11 +53,11 @@ import java.security.MessageDigest
@Composable @Composable
fun DownloadsSettingsScreen( fun DownloadsSettingsScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
vm: DownloadsViewModel = koinViewModel() viewModel: DownloadsViewModel = koinViewModel()
) { ) {
val pullRefreshState = rememberPullToRefreshState() val pullRefreshState = rememberPullToRefreshState()
val downloadedApps by vm.downloadedApps.collectAsStateWithLifecycle(emptyList()) val downloadedApps by viewModel.downloadedApps.collectAsStateWithLifecycle(emptyList())
val pluginStates by vm.downloaderPluginStates.collectAsStateWithLifecycle() val pluginStates by viewModel.downloaderPluginStates.collectAsStateWithLifecycle()
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
Scaffold( Scaffold(
@ -67,8 +67,8 @@ fun DownloadsSettingsScreen(
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
onBackClick = onBackClick, onBackClick = onBackClick,
actions = { actions = {
if (vm.appSelection.isNotEmpty()) { if (viewModel.appSelection.isNotEmpty()) {
IconButton(onClick = { vm.deleteApps() }) { IconButton(onClick = { viewModel.deleteApps() }) {
Icon(Icons.Default.Delete, stringResource(R.string.delete)) Icon(Icons.Default.Delete, stringResource(R.string.delete))
} }
} }
@ -86,7 +86,7 @@ fun DownloadsSettingsScreen(
) { ) {
PullToRefreshDefaults.Indicator( PullToRefreshDefaults.Indicator(
state = pullRefreshState, state = pullRefreshState,
isRefreshing = vm.isRefreshingPlugins isRefreshing = viewModel.isRefreshingPlugins
) )
} }
@ -95,9 +95,9 @@ fun DownloadsSettingsScreen(
.fillMaxSize() .fillMaxSize()
.padding(paddingValues) .padding(paddingValues)
.pullToRefresh( .pullToRefresh(
isRefreshing = vm.isRefreshingPlugins, isRefreshing = viewModel.isRefreshingPlugins,
state = pullRefreshState, state = pullRefreshState,
onRefresh = vm::refreshPlugins onRefresh = viewModel::refreshPlugins
) )
) { ) {
item { item {
@ -115,7 +115,7 @@ fun DownloadsSettingsScreen(
val packageInfo = val packageInfo =
remember(packageName) { remember(packageName) {
vm.pm.getPackageInfo( viewModel.pm.getPackageInfo(
packageName packageName
) )
} ?: return@item } ?: return@item
@ -124,7 +124,7 @@ fun DownloadsSettingsScreen(
val signature = val signature =
remember(packageName) { remember(packageName) {
val androidSignature = val androidSignature =
vm.pm.getSignature(packageName) viewModel.pm.getSignature(packageName)
val hash = MessageDigest.getInstance("SHA-256") val hash = MessageDigest.getInstance("SHA-256")
.digest(androidSignature.toByteArray()) .digest(androidSignature.toByteArray())
hash.toHexString(format = HexFormat.UpperCase) hash.toHexString(format = HexFormat.UpperCase)
@ -140,7 +140,7 @@ fun DownloadsSettingsScreen(
), ),
onDismiss = ::dismiss, onDismiss = ::dismiss,
onConfirm = { onConfirm = {
vm.revokePluginTrust(packageName) viewModel.revokePluginTrust(packageName)
dismiss() dismiss()
} }
) )
@ -161,7 +161,7 @@ fun DownloadsSettingsScreen(
), ),
onDismiss = ::dismiss, onDismiss = ::dismiss,
onConfirm = { onConfirm = {
vm.trustPlugin(packageName) viewModel.trustPlugin(packageName)
dismiss() dismiss()
} }
) )
@ -201,17 +201,17 @@ fun DownloadsSettingsScreen(
GroupHeader(stringResource(R.string.downloaded_apps)) GroupHeader(stringResource(R.string.downloaded_apps))
} }
items(downloadedApps, key = { it.packageName to it.version }) { app -> items(downloadedApps, key = { it.packageName to it.version }) { app ->
val selected = app in vm.appSelection val selected = app in viewModel.appSelection
SettingsListItem( SettingsListItem(
modifier = Modifier.clickable { vm.toggleApp(app) }, modifier = Modifier.clickable { viewModel.toggleApp(app) },
headlineContent = app.packageName, headlineContent = app.packageName,
leadingContent = (@Composable { leadingContent = (@Composable {
HapticCheckbox( HapticCheckbox(
checked = selected, checked = selected,
onCheckedChange = { vm.toggleApp(app) } onCheckedChange = { viewModel.toggleApp(app) }
) )
}).takeIf { vm.appSelection.isNotEmpty() }, }).takeIf { viewModel.appSelection.isNotEmpty() },
supportingContent = app.version, supportingContent = app.version,
tonalElevation = if (selected) 8.dp else 0.dp tonalElevation = if (selected) 8.dp else 0.dp
) )

View File

@ -36,7 +36,6 @@ import app.revanced.manager.ui.component.settings.BooleanItem
import app.revanced.manager.ui.component.settings.SettingsListItem import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.theme.Theme import app.revanced.manager.ui.theme.Theme
import app.revanced.manager.ui.viewmodel.GeneralSettingsViewModel import app.revanced.manager.ui.viewmodel.GeneralSettingsViewModel
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel import org.koin.androidx.compose.koinViewModel
import org.koin.compose.koinInject import org.koin.compose.koinInject
@ -44,17 +43,17 @@ import org.koin.compose.koinInject
@Composable @Composable
fun GeneralSettingsScreen( fun GeneralSettingsScreen(
onBackClick: () -> Unit, onBackClick: () -> Unit,
vm: GeneralSettingsViewModel = koinViewModel(),
onUpdateClick: () -> Unit, onUpdateClick: () -> Unit,
viewModel: GeneralSettingsViewModel = koinViewModel()
) { ) {
val prefs = vm.prefs val prefs = viewModel.prefs
val coroutineScope = vm.viewModelScope val coroutineScope = viewModel.viewModelScope
var showThemePicker by rememberSaveable { mutableStateOf(false) } var showThemePicker by rememberSaveable { mutableStateOf(false) }
if (showThemePicker) { if (showThemePicker) {
ThemePicker( ThemePicker(
onDismiss = { showThemePicker = false }, onDismiss = { showThemePicker = false },
onConfirm = { vm.setTheme(it) } onConfirm = { viewModel.setTheme(it) }
) )
} }
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
@ -82,7 +81,7 @@ fun GeneralSettingsScreen(
headlineContent = stringResource(R.string.theme_mode), headlineContent = stringResource(R.string.theme_mode),
supportingContent = stringResource(R.string.theme_mode_description), supportingContent = stringResource(R.string.theme_mode_description),
trailingContent = { trailingContent = {
Button ( Button(
onClick = { onClick = {
showThemePicker = true showThemePicker = true
} }
@ -99,10 +98,11 @@ fun GeneralSettingsScreen(
description = R.string.personalized_color_description description = R.string.personalized_color_description
) )
} }
}
GroupHeader(stringResource(R.string.update)) GroupHeader(stringResource(R.string.update))
BooleanItem( BooleanItem(
preference = vm.managerAutoUpdates, preference = prefs.managerAutoUpdates,
headline = R.string.check_for_update, headline = R.string.check_for_update,
description = R.string.check_for_update_auto_description description = R.string.check_for_update_auto_description
) )
@ -113,7 +113,6 @@ fun GeneralSettingsScreen(
Text(stringResource(R.string.check_for_update)) Text(stringResource(R.string.check_for_update))
} }
} }
}
} }
@Composable @Composable

View File

@ -27,7 +27,6 @@ class AdvancedSettingsViewModel(
private val app: Application, private val app: Application,
private val patchBundleRepository: PatchBundleRepository private val patchBundleRepository: PatchBundleRepository
) : ViewModel() { ) : ViewModel() {
val showManagerUpdateDialogOnLaunch = prefs.showManagerUpdateDialogOnLaunch
val debugLogFileName: String val debugLogFileName: String
get() { get() {
val time = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now()) val time = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now())

View File

@ -26,8 +26,8 @@ class DeveloperOptionsViewModel(
} }
fun disableSafeguard() = viewModelScope.launch { fun disableSafeguard() = viewModelScope.launch {
prefs.allowIncompatibleMixing.update(true) prefs.disablePatchVersionCompatCheck.update(true)
prefs.allowChangingPatchSelection.update(true) prefs.disableSelectionWarning.update(true)
prefs.allowUniversalPatch.update(true) prefs.disableUniversalPatchWarning.update(true)
} }
} }

View File

@ -1,38 +1,15 @@
package app.revanced.manager.ui.viewmodel package app.revanced.manager.ui.viewmodel
import android.app.Application
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import app.revanced.manager.R
import app.revanced.manager.domain.manager.PreferencesManager import app.revanced.manager.domain.manager.PreferencesManager
import app.revanced.manager.network.api.ReVancedAPI
import app.revanced.manager.ui.theme.Theme import app.revanced.manager.ui.theme.Theme
import app.revanced.manager.util.toast
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class GeneralSettingsViewModel( class GeneralSettingsViewModel(
val prefs: PreferencesManager, val prefs: PreferencesManager
private val app: Application,
private val reVancedAPI: ReVancedAPI,
) : ViewModel() { ) : ViewModel() {
fun setTheme(theme: Theme) = viewModelScope.launch { fun setTheme(theme: Theme) = viewModelScope.launch {
prefs.theme.update(theme) prefs.theme.update(theme)
} }
val managerAutoUpdates = prefs.managerAutoUpdates
val showManagerUpdateDialogOnLaunch = prefs.showManagerUpdateDialogOnLaunch
suspend fun checkForUpdates(): Boolean {
uiSafe(app, R.string.failed_to_check_updates, "Failed to check for updates") {
app.toast(app.getString(R.string.update_check))
if (reVancedAPI.getAppUpdate() == null)
app.toast(app.getString(R.string.no_update_available))
else
return true
}
return false
}
} }

View File

@ -124,7 +124,7 @@ class MainViewModel(
prefs.api.update(api.removeSuffix("/")) prefs.api.update(api.removeSuffix("/"))
} }
settings.experimentalPatchesEnabled?.let { allowExperimental -> settings.experimentalPatchesEnabled?.let { allowExperimental ->
prefs.allowIncompatibleMixing.update(allowExperimental) prefs.disablePatchVersionCompatCheck.update(allowExperimental)
} }
settings.patchesAutoUpdate?.let { autoUpdate -> settings.patchesAutoUpdate?.let { autoUpdate ->
with(patchBundleRepository) { with(patchBundleRepository) {

View File

@ -58,13 +58,13 @@ class PatchesSelectorViewModel(input: SelectedApplicationInfo.PatchesSelector.Vi
private set private set
val allowIncompatiblePatches = val allowIncompatiblePatches =
get<PreferencesManager>().allowIncompatibleMixing.getBlocking() get<PreferencesManager>().disablePatchVersionCompatCheck.getBlocking()
val bundlesFlow = val bundlesFlow =
get<PatchBundleRepository>().bundleInfoFlow(packageName, input.app.version) get<PatchBundleRepository>().bundleInfoFlow(packageName, input.app.version)
init { init {
viewModelScope.launch { viewModelScope.launch {
universalPatchWarningEnabled = !prefs.allowUniversalPatch.get() universalPatchWarningEnabled = !prefs.disableUniversalPatchWarning.get()
if (prefs.allowChangingPatchSelection.get()) { if (prefs.allowChangingPatchSelection.get()) {
selectionWarningEnabled = false selectionWarningEnabled = false

View File

@ -30,6 +30,7 @@ import app.revanced.manager.domain.repository.PatchOptionsRepository
import app.revanced.manager.domain.repository.PatchSelectionRepository import app.revanced.manager.domain.repository.PatchSelectionRepository
import app.revanced.manager.network.downloader.LoadedDownloaderPlugin import app.revanced.manager.network.downloader.LoadedDownloaderPlugin
import app.revanced.manager.network.downloader.ParceledDownloaderData import app.revanced.manager.network.downloader.ParceledDownloaderData
import app.revanced.manager.patcher.patch.PatchInfo
import app.revanced.manager.plugin.downloader.GetScope import app.revanced.manager.plugin.downloader.GetScope
import app.revanced.manager.plugin.downloader.PluginHostApi import app.revanced.manager.plugin.downloader.PluginHostApi
import app.revanced.manager.plugin.downloader.UserInteractionException import app.revanced.manager.plugin.downloader.UserInteractionException
@ -117,7 +118,7 @@ class SelectedAppInfoViewModel(
} }
val requiredVersion = combine( val requiredVersion = combine(
prefs.allowIncompatibleMixing.flow, prefs.suggestedVersionSafeguard.flow,
bundleRepository.suggestedVersions bundleRepository.suggestedVersions
) { suggestedVersionSafeguard, suggestedVersions -> ) { suggestedVersionSafeguard, suggestedVersions ->
if (!suggestedVersionSafeguard) return@combine null if (!suggestedVersionSafeguard) return@combine null
@ -274,7 +275,7 @@ class SelectedAppInfoViewModel(
) )
suspend fun getPatcherParams(): Patcher.ViewModelParams { suspend fun getPatcherParams(): Patcher.ViewModelParams {
val allowUnsupported = prefs.allowIncompatibleMixing.get() val allowUnsupported = prefs.disablePatchVersionCompatCheck.get()
val bundles = bundleInfoFlow.first() val bundles = bundleInfoFlow.first()
return Patcher.ViewModelParams( return Patcher.ViewModelParams(
selectedApp, selectedApp,