Implemented confirming a dialog by pressing enter in one of its TextFields
This commit is contained in:
parent
e292b24eca
commit
362675cb12
|
@ -10,6 +10,7 @@ import androidx.compose.ui.unit.dp
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import net.codinux.banking.ui.IOorDefault
|
||||
import net.codinux.banking.ui.composables.BankIcon
|
||||
import net.codinux.banking.ui.config.Colors
|
||||
import net.codinux.banking.ui.config.DI
|
||||
|
@ -35,19 +36,11 @@ fun AddAccountDialog(
|
|||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
|
||||
BaseDialog(
|
||||
title = "Bank Konto hinzufügen",
|
||||
confirmButtonTitle = "Hinzufügen",
|
||||
confirmButtonEnabled = isRequiredDataEntered && isAddingAccount == false,
|
||||
showProgressIndicatorOnConfirmButton = isAddingAccount,
|
||||
useMoreThanPlatformDefaultWidthOnMobile = true,
|
||||
onDismiss = onDismiss,
|
||||
onConfirm = {
|
||||
fun confirmCalled() {
|
||||
selectedBank?.let {
|
||||
isAddingAccount = true
|
||||
|
||||
coroutineScope.launch { // TODO: launch on Dispatchers.IO where it is available
|
||||
coroutineScope.launch(Dispatchers.IOorDefault) {
|
||||
val successful = DI.bankingService.addAccount(selectedBank!!, loginName, password)
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
|
@ -60,6 +53,18 @@ fun AddAccountDialog(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BaseDialog(
|
||||
title = "Bank Konto hinzufügen",
|
||||
confirmButtonTitle = "Hinzufügen",
|
||||
confirmButtonEnabled = isRequiredDataEntered && isAddingAccount == false,
|
||||
showProgressIndicatorOnConfirmButton = isAddingAccount,
|
||||
useMoreThanPlatformDefaultWidthOnMobile = true,
|
||||
onDismiss = onDismiss,
|
||||
onConfirm = {
|
||||
confirmCalled()
|
||||
}
|
||||
) {
|
||||
Column {
|
||||
|
||||
|
@ -102,7 +107,7 @@ fun AddAccountDialog(
|
|||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
PasswordTextField(password) { password = it }
|
||||
PasswordTextField(password, onChange = { password = it }, onEnterPressed = { confirmCalled() })
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
|
|
|
@ -48,14 +48,19 @@ fun EnterTanDialog(tanChallengeReceived: TanChallengeReceived, onDismiss: () ->
|
|||
var enteredTan by remember { mutableStateOf("") }
|
||||
|
||||
|
||||
fun confirmCalled() {
|
||||
if (enteredTan.length > 2) {
|
||||
tanChallengeReceived.callback(EnterTanResult(enteredTan))
|
||||
onDismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BaseDialog(
|
||||
title = "TAN Eingabe",
|
||||
useMoreThanPlatformDefaultWidthOnMobile = true,
|
||||
confirmButtonEnabled = enteredTan.length > 2,
|
||||
onConfirm = {
|
||||
tanChallengeReceived.callback(EnterTanResult(enteredTan))
|
||||
onDismiss()
|
||||
},
|
||||
onConfirm = { confirmCalled() },
|
||||
onDismiss = {
|
||||
tanChallengeReceived.callback(EnterTanResult(null))
|
||||
onDismiss()
|
||||
|
@ -177,7 +182,8 @@ fun EnterTanDialog(tanChallengeReceived: TanChallengeReceived, onDismiss: () ->
|
|||
keyboardOptions = KeyboardOptions(
|
||||
autoCorrect = false,
|
||||
keyboardType = if (challenge.selectedTanMethod.allowedTanFormat == AllowedTanFormat.Numeric) KeyboardType.Number else KeyboardType.Text
|
||||
)
|
||||
),
|
||||
onEnterPressed = { confirmCalled() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.input.key.*
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import net.codinux.banking.ui.config.Colors
|
||||
|
@ -35,6 +36,7 @@ fun OutlinedTextField(
|
|||
minLines: Int = 1,
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
shape: Shape = MaterialTheme.shapes.small,
|
||||
onEnterPressed: (() -> Unit)? = null
|
||||
// colors: TextFieldColors = TextFieldDefaults.outlinedTextFieldColors() // TODO: merge
|
||||
) {
|
||||
val textFieldColors = TextFieldDefaults.outlinedTextFieldColors(
|
||||
|
@ -45,7 +47,14 @@ fun OutlinedTextField(
|
|||
androidx.compose.material.OutlinedTextField(
|
||||
value = value,
|
||||
onValueChange = onValueChange,
|
||||
modifier = modifier,
|
||||
modifier = modifier.onKeyEvent { event ->
|
||||
if (onEnterPressed != null && event.type == KeyEventType.KeyUp && (event.key == Key.Enter || event.key == Key.NumPadEnter)) {
|
||||
onEnterPressed()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
enabled = enabled,
|
||||
readOnly = readOnly,
|
||||
textStyle = textStyle,
|
||||
|
|
|
@ -18,7 +18,7 @@ import bankmeister.composeapp.generated.resources.visibility_off
|
|||
import org.jetbrains.compose.resources.imageResource
|
||||
|
||||
@Composable
|
||||
fun PasswordTextField(password: String = "", label: String = "Passwort", onChange: (String) -> Unit) {
|
||||
fun PasswordTextField(password: String = "", label: String = "Passwort", onEnterPressed: (() -> Unit)? = null, onChange: (String) -> Unit) {
|
||||
|
||||
var passwordVisible by remember { mutableStateOf(false) }
|
||||
|
||||
|
@ -40,6 +40,7 @@ fun PasswordTextField(password: String = "", label: String = "Passwort", onChang
|
|||
modifier = Modifier.size(24.dp).clickable { passwordVisible = !passwordVisible }
|
||||
)
|
||||
},
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
||||
onEnterPressed = onEnterPressed
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue