AddAccountTaler.kt (4998B)
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.DropdownMenuItem 24 import androidx.compose.material3.ExperimentalMaterial3Api 25 import androidx.compose.material3.ExposedDropdownMenuBox 26 import androidx.compose.material3.ExposedDropdownMenuDefaults 27 import androidx.compose.material3.MaterialTheme 28 import androidx.compose.material3.OutlinedTextField 29 import androidx.compose.material3.Text 30 import androidx.compose.runtime.Composable 31 import androidx.compose.runtime.getValue 32 import androidx.compose.runtime.mutableStateOf 33 import androidx.compose.runtime.remember 34 import androidx.compose.runtime.setValue 35 import androidx.compose.ui.Modifier 36 import androidx.compose.ui.focus.FocusDirection 37 import androidx.compose.ui.graphics.Color 38 import androidx.compose.ui.platform.LocalFocusManager 39 import androidx.compose.ui.res.stringResource 40 import androidx.compose.ui.text.input.ImeAction 41 import androidx.compose.ui.unit.dp 42 import net.taler.wallet.R 43 44 @OptIn(ExperimentalMaterial3Api::class) 45 @Composable 46 fun AddAccountTaler( 47 supportedHosts: List<String>, 48 name: String, 49 host: String, 50 account: String, 51 onFormEdited: (name: String, host: String, account: String) -> Unit 52 ) { 53 var expanded by remember { mutableStateOf(false) } 54 val focusManager = LocalFocusManager.current 55 56 ExposedDropdownMenuBox( 57 expanded = expanded, 58 onExpandedChange = { expanded = it }, 59 ) { 60 OutlinedTextField( 61 modifier = Modifier 62 .padding( 63 bottom = 16.dp, 64 start = 16.dp, 65 end = 16.dp, 66 ) 67 .fillMaxWidth() 68 .menuAnchor(), 69 readOnly = true, 70 value = host, 71 trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded) }, 72 onValueChange = {}, 73 label = { 74 Text( 75 stringResource(R.string.send_deposit_host), 76 color = if (host.isBlank()) { 77 MaterialTheme.colorScheme.error 78 } else Color.Unspecified, 79 ) 80 }, 81 ) 82 83 ExposedDropdownMenu( 84 expanded = expanded, 85 onDismissRequest = { expanded = false }, 86 ) { 87 supportedHosts.forEach { 88 DropdownMenuItem( 89 text = { Text(it) }, 90 onClick = { 91 onFormEdited(name, it, account) 92 expanded = false 93 }, 94 ) 95 } 96 } 97 } 98 99 OutlinedTextField( 100 modifier = Modifier 101 .padding(horizontal = 16.dp) 102 .fillMaxWidth(), 103 value = name, 104 onValueChange = { input -> 105 onFormEdited(input, host, account) 106 }, 107 singleLine = true, 108 isError = name.isBlank(), 109 label = { 110 Text( 111 stringResource(R.string.send_deposit_name), 112 color = if (name.isBlank()) { 113 MaterialTheme.colorScheme.error 114 } else Color.Unspecified, 115 ) 116 }, 117 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), 118 keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }), 119 ) 120 121 OutlinedTextField( 122 modifier = Modifier 123 .padding(16.dp) 124 .fillMaxWidth(), 125 value = account, 126 singleLine = true, 127 onValueChange = { input -> 128 onFormEdited(name, host, input) 129 }, 130 isError = account.isBlank(), 131 label = { 132 Text( 133 text = stringResource(R.string.send_deposit_account), 134 color = if (account.isBlank()) { 135 MaterialTheme.colorScheme.error 136 } else Color.Unspecified, 137 ) 138 }, 139 keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), 140 keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }), 141 ) 142 }