fix: cleanup advanced settings screen

This commit is contained in:
Ax333l 2024-07-05 19:41:27 +02:00
parent 7c7fb7b343
commit e6e043f168
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
9 changed files with 105 additions and 46 deletions

View File

@ -18,6 +18,7 @@ val viewModelModule = module {
viewModelOf(::ChangelogsViewModel)
viewModelOf(::ImportExportViewModel)
viewModelOf(::AboutViewModel)
viewModelOf(::DeveloperOptionsViewModel)
viewModelOf(::ContributorViewModel)
viewModelOf(::DownloadsViewModel)
viewModelOf(::InstalledAppsViewModel)

View File

@ -6,35 +6,38 @@ import kotlinx.parcelize.Parcelize
sealed interface SettingsDestination : Parcelable {
@Parcelize
object Settings : SettingsDestination
data object Settings : SettingsDestination
@Parcelize
object General : SettingsDestination
data object General : SettingsDestination
@Parcelize
object Advanced : SettingsDestination
data object Advanced : SettingsDestination
@Parcelize
object Updates : SettingsDestination
data object Updates : SettingsDestination
@Parcelize
object Downloads : SettingsDestination
data object Downloads : SettingsDestination
@Parcelize
object ImportExport : SettingsDestination
data object ImportExport : SettingsDestination
@Parcelize
object About : SettingsDestination
data object About : SettingsDestination
@Parcelize
data class Update(val downloadOnScreenEntry: Boolean = false) : SettingsDestination
@Parcelize
object Changelogs : SettingsDestination
data object Changelogs : SettingsDestination
@Parcelize
object Contributors: SettingsDestination
data object Contributors: SettingsDestination
@Parcelize
object Licenses: SettingsDestination
data object Licenses: SettingsDestination
@Parcelize
data object DeveloperOptions: SettingsDestination
}

View File

@ -122,7 +122,8 @@ fun SettingsScreen(
is SettingsDestination.About -> AboutSettingsScreen(
onBackClick = backClick,
onContributorsClick = { navController.navigate(SettingsDestination.Contributors) },
onLicensesClick = { navController.navigate(SettingsDestination.Licenses) }
onDeveloperOptionsClick = { navController.navigate(SettingsDestination.DeveloperOptions) },
onLicensesClick = { navController.navigate(SettingsDestination.Licenses) },
)
is SettingsDestination.Update -> UpdateScreen(
@ -146,6 +147,8 @@ fun SettingsScreen(
onBackClick = backClick,
)
is SettingsDestination.DeveloperOptions -> DeveloperOptionsScreen(onBackClick = backClick)
is SettingsDestination.Settings -> {
Scaffold(
topBar = {

View File

@ -39,7 +39,6 @@ import app.revanced.manager.ui.component.ColumnWithScrollbar
import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.viewmodel.AboutViewModel
import app.revanced.manager.ui.viewmodel.AboutViewModel.Companion.getSocialIcon
import app.revanced.manager.util.isDebuggable
import app.revanced.manager.util.openUrl
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import org.koin.androidx.compose.koinViewModel
@ -50,6 +49,7 @@ fun AboutSettingsScreen(
onBackClick: () -> Unit,
onContributorsClick: () -> Unit,
onLicensesClick: () -> Unit,
onDeveloperOptionsClick: () -> Unit,
viewModel: AboutViewModel = koinViewModel()
) {
val context = LocalContext.current
@ -116,9 +116,11 @@ fun AboutSettingsScreen(
stringResource(R.string.contributors_description),
third = onContributorsClick
),
Triple(stringResource(R.string.developer_options),
Triple(
stringResource(R.string.developer_options),
stringResource(R.string.developer_options_description),
third = { /*TODO*/ }).takeIf { context.isDebuggable },
third = onDeveloperOptionsClick
),
Triple(
stringResource(R.string.opensource_licenses),
stringResource(R.string.opensource_licenses_description),

View File

@ -71,6 +71,8 @@ fun AdvancedSettingsScreen(
.fillMaxSize()
.padding(paddingValues)
) {
GroupHeader(stringResource(R.string.manager))
val apiUrl by vm.prefs.api.getAsState()
var showApiUrlDialog by rememberSaveable { mutableStateOf(false) }
@ -110,6 +112,14 @@ fun AdvancedSettingsScreen(
headline = R.string.process_runtime_memory_limit,
description = R.string.process_runtime_memory_limit_description,
)
BooleanItem(
preference = vm.prefs.multithreadingDexFileWriter,
coroutineScope = vm.viewModelScope,
headline = R.string.multithreaded_dex_file_writer,
description = R.string.multithreaded_dex_file_writer_description,
)
GroupHeader(stringResource(R.string.safeguards))
BooleanItem(
preference = vm.prefs.disablePatchVersionCompatCheck,
coroutineScope = vm.viewModelScope,
@ -122,26 +132,6 @@ fun AdvancedSettingsScreen(
headline = R.string.suggested_version_safeguard,
description = R.string.suggested_version_safeguard_description
)
BooleanItem(
preference = vm.prefs.multithreadingDexFileWriter,
coroutineScope = vm.viewModelScope,
headline = R.string.multithreaded_dex_file_writer,
description = R.string.multithreaded_dex_file_writer_description,
)
GroupHeader(stringResource(R.string.patch_bundles_section))
SettingsListItem(
headlineContent = stringResource(R.string.patch_bundles_redownload),
modifier = Modifier.clickable {
vm.redownloadBundles()
}
)
SettingsListItem(
headlineContent = stringResource(R.string.patch_bundles_reset),
modifier = Modifier.clickable {
vm.resetBundles()
}
)
GroupHeader(stringResource(R.string.device))
SettingsListItem(

View File

@ -0,0 +1,44 @@
package app.revanced.manager.ui.screen.settings
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import app.revanced.manager.R
import app.revanced.manager.ui.component.AppTopBar
import app.revanced.manager.ui.component.GroupHeader
import app.revanced.manager.ui.component.settings.SettingsListItem
import app.revanced.manager.ui.viewmodel.DeveloperOptionsViewModel
import org.koin.androidx.compose.koinViewModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DeveloperOptionsScreen(
onBackClick: () -> Unit,
vm: DeveloperOptionsViewModel = koinViewModel()
) {
Scaffold(
topBar = {
AppTopBar(
title = stringResource(R.string.developer_options),
onBackClick = onBackClick
)
}
) { paddingValues ->
Column(modifier = Modifier.padding(paddingValues)) {
GroupHeader(stringResource(R.string.patch_bundles_section))
SettingsListItem(
headlineContent = stringResource(R.string.patch_bundles_redownload),
modifier = Modifier.clickable(onClick = vm::redownloadBundles)
)
SettingsListItem(
headlineContent = stringResource(R.string.patch_bundles_reset),
modifier = Modifier.clickable(onClick = vm::redownloadBundles)
)
}
}
}

View File

@ -6,12 +6,10 @@ import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.revanced.manager.R
import app.revanced.manager.domain.bundles.RemotePatchBundle
import app.revanced.manager.domain.manager.PreferencesManager
import app.revanced.manager.domain.repository.PatchBundleRepository
import app.revanced.manager.util.tag
import app.revanced.manager.util.toast
import app.revanced.manager.util.uiSafe
import com.github.pgreze.process.Redirect
import com.github.pgreze.process.process
import kotlinx.coroutines.CancellationException
@ -43,16 +41,6 @@ class AdvancedSettingsViewModel(
patchBundleRepository.reloadApiBundles()
}
fun redownloadBundles() = viewModelScope.launch {
uiSafe(app, R.string.source_download_fail, RemotePatchBundle.updateFailMsg) {
patchBundleRepository.redownloadRemoteBundles()
}
}
fun resetBundles() = viewModelScope.launch {
patchBundleRepository.reset()
}
fun exportDebugLogs(target: Uri) = viewModelScope.launch {
val exitCode = try {
withContext(Dispatchers.IO) {

View File

@ -0,0 +1,27 @@
package app.revanced.manager.ui.viewmodel
import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.revanced.manager.R
import app.revanced.manager.domain.bundles.RemotePatchBundle
import app.revanced.manager.domain.manager.PreferencesManager
import app.revanced.manager.domain.repository.PatchBundleRepository
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.launch
class DeveloperOptionsViewModel(
val prefs: PreferencesManager,
private val app: Application,
private val patchBundleRepository: PatchBundleRepository
) : ViewModel() {
fun redownloadBundles() = viewModelScope.launch {
uiSafe(app, R.string.source_download_fail, RemotePatchBundle.updateFailMsg) {
patchBundleRepository.redownloadRemoteBundles()
}
}
fun resetBundles() = viewModelScope.launch {
patchBundleRepository.reset()
}
}

View File

@ -71,6 +71,7 @@
<string name="theme_description">Choose between light or dark theme</string>
<string name="multithreaded_dex_file_writer">Multi-threaded DEX file writer</string>
<string name="multithreaded_dex_file_writer_description">Use multiple cores to write DEX files. This is faster, but uses more memory</string>
<string name="safeguards">Safeguards</string>
<string name="patch_compat_check">Disable version compatibility check</string>
<string name="patch_compat_check_description">The check restricts patches to supported app versions</string>
<string name="suggested_version_safeguard">Require suggested app version</string>