PIN : fix some pin setup related code
This commit is contained in:
parent
cf4ac261a9
commit
6ee1c2eb4c
4 changed files with 15 additions and 6 deletions
|
|
@ -47,11 +47,11 @@ fun PinEntryTextField(
|
||||||
) {
|
) {
|
||||||
BasicTextField(
|
BasicTextField(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
value = TextFieldValue(pinEntry.toText()),
|
value = pinEntry.toText(),
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
onValueChange(it.text)
|
onValueChange(it)
|
||||||
},
|
},
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
|
||||||
decorationBox = {
|
decorationBox = {
|
||||||
PinEntryRow(pinEntry = pinEntry)
|
PinEntryRow(pinEntry = pinEntry)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ data class PinEntry(
|
||||||
* @return the new PinEntry
|
* @return the new PinEntry
|
||||||
*/
|
*/
|
||||||
fun fillWith(text: String): PinEntry {
|
fun fillWith(text: String): PinEntry {
|
||||||
val newDigits = digits.toMutableList()
|
val newDigits = MutableList<PinDigit>(size) { PinDigit.Empty }
|
||||||
text.forEachIndexed { index, char ->
|
text.forEachIndexed { index, char ->
|
||||||
if (index < size) {
|
if (index < size && char.isDigit()) {
|
||||||
newDigits[index] = PinDigit.Filled(char)
|
newDigits[index] = PinDigit.Filled(char)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class SetupPinNode @AssistedInject constructor(
|
||||||
val state = presenter.present()
|
val state = presenter.present()
|
||||||
SetupPinView(
|
SetupPinView(
|
||||||
state = state,
|
state = state,
|
||||||
onBackClicked = { },
|
onBackClicked = this::navigateUp,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,12 @@ import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Lock
|
import androidx.compose.material.icons.filled.Lock
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
@ -105,12 +109,17 @@ private fun SetupPinContent(
|
||||||
state: SetupPinState,
|
state: SetupPinState,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
}
|
||||||
PinEntryTextField(
|
PinEntryTextField(
|
||||||
state.activePinEntry,
|
state.activePinEntry,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
state.eventSink(SetupPinEvents.OnPinEntryChanged(it))
|
state.eventSink(SetupPinEvents.OnPinEntryChanged(it))
|
||||||
},
|
},
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
|
.focusRequester(focusRequester)
|
||||||
.padding(top = 36.dp)
|
.padding(top = 36.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue