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.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import net.codinux.banking.ui.IOorDefault
|
||||||
import net.codinux.banking.ui.composables.BankIcon
|
import net.codinux.banking.ui.composables.BankIcon
|
||||||
import net.codinux.banking.ui.config.Colors
|
import net.codinux.banking.ui.config.Colors
|
||||||
import net.codinux.banking.ui.config.DI
|
import net.codinux.banking.ui.config.DI
|
||||||
|
@ -35,19 +36,11 @@ fun AddAccountDialog(
|
||||||
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
fun confirmCalled() {
|
||||||
BaseDialog(
|
|
||||||
title = "Bank Konto hinzufügen",
|
|
||||||
confirmButtonTitle = "Hinzufügen",
|
|
||||||
confirmButtonEnabled = isRequiredDataEntered && isAddingAccount == false,
|
|
||||||
showProgressIndicatorOnConfirmButton = isAddingAccount,
|
|
||||||
useMoreThanPlatformDefaultWidthOnMobile = true,
|
|
||||||
onDismiss = onDismiss,
|
|
||||||
onConfirm = {
|
|
||||||
selectedBank?.let {
|
selectedBank?.let {
|
||||||
isAddingAccount = true
|
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)
|
val successful = DI.bankingService.addAccount(selectedBank!!, loginName, password)
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
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 {
|
Column {
|
||||||
|
|
||||||
|
@ -102,7 +107,7 @@ fun AddAccountDialog(
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
PasswordTextField(password) { password = it }
|
PasswordTextField(password, onChange = { password = it }, onEnterPressed = { confirmCalled() })
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,14 +48,19 @@ fun EnterTanDialog(tanChallengeReceived: TanChallengeReceived, onDismiss: () ->
|
||||||
var enteredTan by remember { mutableStateOf("") }
|
var enteredTan by remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
|
||||||
|
fun confirmCalled() {
|
||||||
|
if (enteredTan.length > 2) {
|
||||||
|
tanChallengeReceived.callback(EnterTanResult(enteredTan))
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BaseDialog(
|
BaseDialog(
|
||||||
title = "TAN Eingabe",
|
title = "TAN Eingabe",
|
||||||
useMoreThanPlatformDefaultWidthOnMobile = true,
|
useMoreThanPlatformDefaultWidthOnMobile = true,
|
||||||
confirmButtonEnabled = enteredTan.length > 2,
|
confirmButtonEnabled = enteredTan.length > 2,
|
||||||
onConfirm = {
|
onConfirm = { confirmCalled() },
|
||||||
tanChallengeReceived.callback(EnterTanResult(enteredTan))
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
tanChallengeReceived.callback(EnterTanResult(null))
|
tanChallengeReceived.callback(EnterTanResult(null))
|
||||||
onDismiss()
|
onDismiss()
|
||||||
|
@ -177,7 +182,8 @@ fun EnterTanDialog(tanChallengeReceived: TanChallengeReceived, onDismiss: () ->
|
||||||
keyboardOptions = KeyboardOptions(
|
keyboardOptions = KeyboardOptions(
|
||||||
autoCorrect = false,
|
autoCorrect = false,
|
||||||
keyboardType = if (challenge.selectedTanMethod.allowedTanFormat == AllowedTanFormat.Numeric) KeyboardType.Number else KeyboardType.Text
|
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.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Shape
|
import androidx.compose.ui.graphics.Shape
|
||||||
|
import androidx.compose.ui.input.key.*
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
import net.codinux.banking.ui.config.Colors
|
import net.codinux.banking.ui.config.Colors
|
||||||
|
@ -35,6 +36,7 @@ fun OutlinedTextField(
|
||||||
minLines: Int = 1,
|
minLines: Int = 1,
|
||||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
shape: Shape = MaterialTheme.shapes.small,
|
shape: Shape = MaterialTheme.shapes.small,
|
||||||
|
onEnterPressed: (() -> Unit)? = null
|
||||||
// colors: TextFieldColors = TextFieldDefaults.outlinedTextFieldColors() // TODO: merge
|
// colors: TextFieldColors = TextFieldDefaults.outlinedTextFieldColors() // TODO: merge
|
||||||
) {
|
) {
|
||||||
val textFieldColors = TextFieldDefaults.outlinedTextFieldColors(
|
val textFieldColors = TextFieldDefaults.outlinedTextFieldColors(
|
||||||
|
@ -45,7 +47,14 @@ fun OutlinedTextField(
|
||||||
androidx.compose.material.OutlinedTextField(
|
androidx.compose.material.OutlinedTextField(
|
||||||
value = value,
|
value = value,
|
||||||
onValueChange = onValueChange,
|
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,
|
enabled = enabled,
|
||||||
readOnly = readOnly,
|
readOnly = readOnly,
|
||||||
textStyle = textStyle,
|
textStyle = textStyle,
|
||||||
|
|
|
@ -18,7 +18,7 @@ import bankmeister.composeapp.generated.resources.visibility_off
|
||||||
import org.jetbrains.compose.resources.imageResource
|
import org.jetbrains.compose.resources.imageResource
|
||||||
|
|
||||||
@Composable
|
@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) }
|
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 }
|
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