Enable confirmButton only when needed to respond to user input (#8848)
* Enable `confirmButton` when appropriate * Show error in dialog instead * Follow M3 guidelines
This commit is contained in:
@@ -275,10 +275,6 @@ object SettingsAdvancedScreen : SearchableSettings {
|
||||
pref = userAgentPref,
|
||||
title = stringResource(R.string.pref_user_agent_string),
|
||||
onValueChanged = {
|
||||
if (it.isBlank()) {
|
||||
context.toast(R.string.error_user_agent_string_blank)
|
||||
return@EditTextPreference false
|
||||
}
|
||||
try {
|
||||
// OkHttp checks for valid values internally
|
||||
Headers.Builder().add("User-Agent", it)
|
||||
|
||||
@@ -315,7 +315,10 @@ object SettingsLibraryScreen : SearchableSettings {
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onValueChanged(portraitValue, landscapeValue) }) {
|
||||
TextButton(
|
||||
enabled = portraitValue != initialPortrait || landscapeValue != initialLandscape,
|
||||
onClick = { onValueChanged(portraitValue, landscapeValue) },
|
||||
) {
|
||||
Text(text = stringResource(android.R.string.ok))
|
||||
}
|
||||
},
|
||||
|
||||
@@ -222,7 +222,7 @@ object SettingsTrackingScreen : SearchableSettings {
|
||||
label = { Text(text = stringResource(uNameStringRes)) },
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
|
||||
singleLine = true,
|
||||
isError = inputError && username.text.isEmpty(),
|
||||
isError = inputError && !processing,
|
||||
)
|
||||
|
||||
var hidePassword by remember { mutableStateOf(true) }
|
||||
@@ -253,21 +253,16 @@ object SettingsTrackingScreen : SearchableSettings {
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
singleLine = true,
|
||||
isError = inputError && password.text.isEmpty(),
|
||||
isError = inputError && !processing,
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
enabled = !processing,
|
||||
enabled = !processing && username.text.isNotBlank() && password.text.isNotBlank(),
|
||||
onClick = {
|
||||
if (username.text.isEmpty() || password.text.isEmpty()) {
|
||||
inputError = true
|
||||
return@Button
|
||||
}
|
||||
scope.launchIO {
|
||||
inputError = false
|
||||
processing = true
|
||||
val result = checkLogin(
|
||||
context = context,
|
||||
@@ -275,6 +270,7 @@ object SettingsTrackingScreen : SearchableSettings {
|
||||
username = username.text,
|
||||
password = password.text,
|
||||
)
|
||||
inputError = !result
|
||||
if (result) onDismissRequest()
|
||||
processing = false
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package eu.kanade.presentation.more.settings.widget
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Cancel
|
||||
import androidx.compose.material.icons.filled.Error
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
@@ -50,6 +55,16 @@ fun EditTextPreferenceWidget(
|
||||
OutlinedTextField(
|
||||
value = textFieldValue,
|
||||
onValueChange = { textFieldValue = it },
|
||||
trailingIcon = {
|
||||
if (textFieldValue.text.isBlank()) {
|
||||
Icon(imageVector = Icons.Filled.Error, contentDescription = null)
|
||||
} else {
|
||||
IconButton(onClick = { textFieldValue = TextFieldValue("") }) {
|
||||
Icon(imageVector = Icons.Filled.Cancel, contentDescription = null)
|
||||
}
|
||||
}
|
||||
},
|
||||
isError = textFieldValue.text.isBlank(),
|
||||
singleLine = true,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
@@ -59,6 +74,7 @@ fun EditTextPreferenceWidget(
|
||||
),
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
enabled = textFieldValue.text != value && textFieldValue.text.isNotBlank(),
|
||||
onClick = {
|
||||
scope.launch {
|
||||
if (onConfirm(textFieldValue.text)) {
|
||||
|
||||
Reference in New Issue
Block a user