Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add reset button to custom API #2076

Merged
merged 5 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.default,
onSubmit = {
showApiUrlDialog = false
it?.let(vm::setApiUrl)
}
)
}
SettingsListItem(
headlineContent = stringResource(R.string.api_url),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Ushie marked this conversation as resolved.
Show resolved Hide resolved
}
}
)
}
}
Expand Down