From c10b4e67b624e566bece7567fb42a299162875eb Mon Sep 17 00:00:00 2001 From: Ushie Date: Tue, 23 Jul 2024 05:28:17 +0300 Subject: [PATCH 1/5] feat: Add reset button to custom API Closes #2051 --- .../manager/base/BasePreferencesManager.kt | 1 + .../screen/settings/AdvancedSettingsScreen.kt | 37 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt b/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt index 57810a05e4..cea343ba29 100644 --- a/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt +++ b/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt @@ -64,6 +64,7 @@ abstract class Preference( val flow = dataStore.data.map { with(it) { read() } ?: default }.distinctUntilChanged() suspend fun get() = flow.first() + fun defaultValue() = default fun getBlocking() = runBlocking { get() } @Composable fun getAsState() = flow.collectAsStateWithLifecycle(initialValue = remember { diff --git a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt index 4c3be2a400..0bd359a983 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt @@ -11,20 +11,10 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding 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 +68,14 @@ fun AdvancedSettingsScreen( var showApiUrlDialog by rememberSaveable { mutableStateOf(false) } if (showApiUrlDialog) { - APIUrlDialog(apiUrl) { - showApiUrlDialog = false - it?.let(vm::setApiUrl) - } + APIUrlDialog( + currentUrl = apiUrl, + defaultUrl = vm.prefs.api.defaultValue(), + onSubmit = { + showApiUrlDialog = false + it?.let(vm::setApiUrl) + } + ) } SettingsListItem( headlineContent = stringResource(R.string.api_url), @@ -163,7 +157,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( @@ -209,7 +203,12 @@ private fun APIUrlDialog(currentUrl: String, onSubmit: (String?) -> Unit) { OutlinedTextField( 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, null) + } + } ) } } From 77a1feead0c59fc99c629da4ba5eed33d832e3fb Mon Sep 17 00:00:00 2001 From: Ushie Date: Wed, 24 Jul 2024 04:28:50 +0300 Subject: [PATCH 2/5] refactor: Expose `default` instead of creating defaultValue() --- .../manager/domain/manager/base/BasePreferencesManager.kt | 3 +-- .../manager/ui/screen/settings/AdvancedSettingsScreen.kt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt b/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt index cea343ba29..2b04bd41c7 100644 --- a/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt +++ b/app/src/main/java/app/revanced/manager/domain/manager/base/BasePreferencesManager.kt @@ -56,7 +56,7 @@ class EditorContext(private val prefs: MutablePreferences) { abstract class Preference( private val dataStore: DataStore, - protected val default: T + val default: T ) { internal abstract fun Preferences.read(): T internal abstract fun MutablePreferences.write(value: T) @@ -64,7 +64,6 @@ abstract class Preference( val flow = dataStore.data.map { with(it) { read() } ?: default }.distinctUntilChanged() suspend fun get() = flow.first() - fun defaultValue() = default fun getBlocking() = runBlocking { get() } @Composable fun getAsState() = flow.collectAsStateWithLifecycle(initialValue = remember { diff --git a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt index 0bd359a983..d664268407 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt @@ -70,7 +70,7 @@ fun AdvancedSettingsScreen( if (showApiUrlDialog) { APIUrlDialog( currentUrl = apiUrl, - defaultUrl = vm.prefs.api.defaultValue(), + defaultUrl = vm.prefs.api.default, onSubmit = { showApiUrlDialog = false it?.let(vm::setApiUrl) From 86ad80b42b59d1b06cb202c30acc4b32420b6886 Mon Sep 17 00:00:00 2001 From: Ushie Date: Fri, 26 Jul 2024 00:59:15 +0300 Subject: [PATCH 3/5] feat: Add `contentDescription` to Reset API URL --- .../manager/ui/screen/settings/AdvancedSettingsScreen.kt | 2 +- app/src/main/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt index d664268407..f3716e4949 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt @@ -206,7 +206,7 @@ private fun APIUrlDialog(currentUrl: String, defaultUrl: String, onSubmit: (Stri label = { Text(stringResource(R.string.api_url)) }, trailingIcon = { IconButton(onClick = { url = defaultUrl }) { - Icon(Icons.Outlined.Restore, null) + Icon(Icons.Outlined.Restore, stringResource(R.string.reset_api_url)) } } ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36cbea3aa8..0ef8222bee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -367,4 +367,5 @@ Add patch bundle Bundle URL Auto update + Reset API URL From 1ca64939bffc982863065397fa253de83202e41a Mon Sep 17 00:00:00 2001 From: Ushie Date: Sun, 28 Jul 2024 23:55:17 +0300 Subject: [PATCH 4/5] chore: Rename and move string appropiately --- .../manager/ui/screen/settings/AdvancedSettingsScreen.kt | 2 +- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt index f3716e4949..4fe91807a2 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt @@ -206,7 +206,7 @@ private fun APIUrlDialog(currentUrl: String, defaultUrl: String, onSubmit: (Stri label = { Text(stringResource(R.string.api_url)) }, trailingIcon = { IconButton(onClick = { url = defaultUrl }) { - Icon(Icons.Outlined.Restore, stringResource(R.string.reset_api_url)) + Icon(Icons.Outlined.Restore, stringResource(R.string.api_url_dialog_reset)) } } ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0ef8222bee..0fa8b485a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -161,6 +161,7 @@ Set the API URL of ReVanced Manager. ReVanced Manager uses the API to download patches and updates. ReVanced Manager connects to the API to download patches and updates. Make sure that you trust it. Set + Reset API URL Device Android version Model @@ -367,5 +368,4 @@ Add patch bundle Bundle URL Auto update - Reset API URL From c32e377dadf1cdcdd5cc8010c02c663fbe616959 Mon Sep 17 00:00:00 2001 From: Ushie Date: Mon, 29 Jul 2024 00:03:33 +0300 Subject: [PATCH 5/5] fix: Fill max width for the TextField --- .../manager/ui/screen/settings/AdvancedSettingsScreen.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt index 4fe91807a2..04a104fffc 100644 --- a/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt +++ b/app/src/main/java/app/revanced/manager/ui/screen/settings/AdvancedSettingsScreen.kt @@ -5,10 +5,7 @@ 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.material.icons.outlined.Restore @@ -201,6 +198,7 @@ private fun APIUrlDialog(currentUrl: String, defaultUrl: String, onSubmit: (Stri color = MaterialTheme.colorScheme.error ) OutlinedTextField( + modifier = Modifier.fillMaxWidth(), value = url, onValueChange = { url = it }, label = { Text(stringResource(R.string.api_url)) },