diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt index 5ad9846..2436ed4 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt @@ -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,6 +36,24 @@ fun AddAccountDialog( val coroutineScope = rememberCoroutineScope() + fun confirmCalled() { + selectedBank?.let { + isAddingAccount = true + + coroutineScope.launch(Dispatchers.IOorDefault) { + val successful = DI.bankingService.addAccount(selectedBank!!, loginName, password) + + withContext(Dispatchers.Main) { + isAddingAccount = false + + if (successful) { + onDismiss() + } + } + } + } + } + BaseDialog( title = "Bank Konto hinzufügen", @@ -44,21 +63,7 @@ fun AddAccountDialog( useMoreThanPlatformDefaultWidthOnMobile = true, onDismiss = onDismiss, onConfirm = { - selectedBank?.let { - isAddingAccount = true - - coroutineScope.launch { // TODO: launch on Dispatchers.IO where it is available - val successful = DI.bankingService.addAccount(selectedBank!!, loginName, password) - - withContext(Dispatchers.Main) { - isAddingAccount = false - - if (successful) { - onDismiss() - } - } - } - } + 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)) } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt index 567a4de..d1af010 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/EnterTanDialog.kt @@ -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() } ) } } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt index 62c372b..0a3ea2b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt @@ -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, diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/PasswordTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/PasswordTextField.kt index 2d84caf..b44974a 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/PasswordTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/PasswordTextField.kt @@ -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 ) } \ No newline at end of file