AddAccountIBAN.kt (5075B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2024 Taler Systems S.A. 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 package net.taler.wallet.deposit 18 19 import androidx.compose.foundation.layout.fillMaxWidth 20 import androidx.compose.foundation.layout.padding 21 import androidx.compose.foundation.text.KeyboardActions 22 import androidx.compose.foundation.text.KeyboardOptions 23 import androidx.compose.material3.MaterialTheme 24 import androidx.compose.material3.OutlinedTextField 25 import androidx.compose.material3.Text 26 import androidx.compose.runtime.Composable 27 import androidx.compose.ui.Modifier 28 import androidx.compose.ui.focus.FocusDirection 29 import androidx.compose.ui.graphics.Color 30 import androidx.compose.ui.platform.LocalFocusManager 31 import androidx.compose.ui.res.stringResource 32 import androidx.compose.ui.text.input.ImeAction 33 import androidx.compose.ui.unit.dp 34 import net.taler.wallet.R 35 36 @Composable 37 fun AddAccountIBAN( 38 name: String, 39 town: String?, 40 zip: String?, 41 iban: String, 42 ibanError: Boolean, 43 onFormEdited: (name: String, town: String?, zip: String?, iban: String) -> Unit 44 ) { 45 val focusManager = LocalFocusManager.current 46 OutlinedTextField( 47 modifier = Modifier 48 .padding( 49 bottom = 16.dp, 50 start = 16.dp, 51 end = 16.dp, 52 ).fillMaxWidth(), 53 value = name, 54 onValueChange = { input -> 55 onFormEdited(input, town, zip, iban) 56 }, 57 singleLine = true, 58 isError = name.isBlank(), 59 label = { 60 Text( 61 stringResource(R.string.send_deposit_name), 62 color = if (name.isBlank()) { 63 MaterialTheme.colorScheme.error 64 } else Color.Unspecified, 65 ) 66 }, 67 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), 68 keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }), 69 ) 70 71 OutlinedTextField( 72 modifier = Modifier 73 .padding(horizontal = 16.dp) 74 .fillMaxWidth(), 75 value = iban, 76 singleLine = true, 77 onValueChange = { input -> 78 onFormEdited(name, town, zip, input 79 .uppercase() 80 .replace(" ", "") 81 .replace("\n", "") 82 .replace("\t", "") 83 .trim()) 84 }, 85 isError = ibanError, 86 supportingText = { 87 if (ibanError) { 88 Text( 89 modifier = Modifier.fillMaxWidth(), 90 text = stringResource(R.string.send_deposit_iban_error), 91 color = MaterialTheme.colorScheme.error 92 ) 93 } 94 }, 95 label = { 96 Text( 97 text = stringResource(R.string.send_deposit_iban), 98 color = if (ibanError) { 99 MaterialTheme.colorScheme.error 100 } else Color.Unspecified, 101 ) 102 }, 103 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), 104 keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }), 105 ) 106 107 OutlinedTextField( 108 modifier = Modifier 109 .padding( 110 bottom = 16.dp, 111 start = 16.dp, 112 end = 16.dp, 113 ).fillMaxWidth(), 114 value = zip ?: "", 115 singleLine = true, 116 onValueChange = { input -> 117 onFormEdited(name, town, input.trim(), iban) 118 }, 119 isError = ibanError, 120 label = { 121 Text(stringResource(R.string.send_deposit_postal_code)) 122 }, 123 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), 124 keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }), 125 ) 126 127 OutlinedTextField( 128 modifier = Modifier 129 .padding( 130 bottom = 16.dp, 131 start = 16.dp, 132 end = 16.dp, 133 ).fillMaxWidth(), 134 value = town ?: "", 135 singleLine = true, 136 onValueChange = { input -> 137 onFormEdited(name, input.trim(), zip, iban) 138 }, 139 isError = ibanError, 140 label = { 141 Text(stringResource(R.string.send_deposit_town)) 142 }, 143 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), 144 keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }), 145 ) 146 }