feat: Add reset button to custom API (#2076)

Closes #2051
This commit is contained in:
Ushie 2024-07-29 13:14:13 +03:00 committed by GitHub
parent afc72ffd85
commit 4cbd480e84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 24 deletions

View File

@ -56,7 +56,7 @@ class EditorContext(private val prefs: MutablePreferences) {
abstract class Preference<T>(
private val dataStore: DataStore<Preferences>,
protected val default: T
val default: T
) {
internal abstract fun Preferences.read(): T
internal abstract fun MutablePreferences.write(value: T)

View File

@ -5,26 +5,13 @@ import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Api
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.material.icons.outlined.Restore
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
@ -78,10 +65,14 @@ fun AdvancedSettingsScreen(
var showApiUrlDialog by rememberSaveable { mutableStateOf(false) }
if (showApiUrlDialog) {
APIUrlDialog(apiUrl) {
APIUrlDialog(
currentUrl = apiUrl,
defaultUrl = vm.prefs.api.default,
onSubmit = {
showApiUrlDialog = false
it?.let(vm::setApiUrl)
}
)
}
SettingsListItem(
headlineContent = stringResource(R.string.api_url),
@ -163,7 +154,7 @@ fun AdvancedSettingsScreen(
}
@Composable
private fun APIUrlDialog(currentUrl: String, onSubmit: (String?) -> Unit) {
private fun APIUrlDialog(currentUrl: String, defaultUrl: String, onSubmit: (String?) -> Unit) {
var url by rememberSaveable(currentUrl) { mutableStateOf(currentUrl) }
AlertDialog(
@ -207,9 +198,15 @@ private fun APIUrlDialog(currentUrl: String, onSubmit: (String?) -> Unit) {
color = MaterialTheme.colorScheme.error
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = url,
onValueChange = { url = it },
label = { Text(stringResource(R.string.api_url)) }
label = { Text(stringResource(R.string.api_url)) },
trailingIcon = {
IconButton(onClick = { url = defaultUrl }) {
Icon(Icons.Outlined.Restore, stringResource(R.string.api_url_dialog_reset))
}
}
)
}
}

View File

@ -161,6 +161,7 @@
<string name="api_url_dialog_description">Set the API URL of ReVanced Manager. ReVanced Manager uses the API to download patches and updates.</string>
<string name="api_url_dialog_warning">ReVanced Manager connects to the API to download patches and updates. Make sure that you trust it.</string>
<string name="api_url_dialog_save">Set</string>
<string name="api_url_dialog_reset">Reset API URL</string>
<string name="device">Device</string>
<string name="device_android_version">Android version</string>
<string name="device_model">Model</string>