From 42ab0e1395e5e31d089d6b4dda630607fed6c060 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 23 Oct 2023 20:56:39 +0200 Subject: [PATCH] PIN : fix some pin setup related code --- .../lockscreen/impl/components/PinEntryTextField.kt | 6 +++--- .../features/lockscreen/impl/pin/model/PinEntry.kt | 4 ++-- .../features/lockscreen/impl/setup/SetupPinNode.kt | 2 +- .../features/lockscreen/impl/setup/SetupPinView.kt | 9 +++++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/components/PinEntryTextField.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/components/PinEntryTextField.kt index 91f6d435c5..a8e2b896f6 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/components/PinEntryTextField.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/components/PinEntryTextField.kt @@ -47,11 +47,11 @@ fun PinEntryTextField( ) { BasicTextField( modifier = modifier, - value = TextFieldValue(pinEntry.toText()), + value = pinEntry.toText(), onValueChange = { - onValueChange(it.text) + onValueChange(it) }, - keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword), decorationBox = { PinEntryRow(pinEntry = pinEntry) } diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntry.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntry.kt index eaca592de9..96c3bec3ad 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntry.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/model/PinEntry.kt @@ -41,9 +41,9 @@ data class PinEntry( * @return the new PinEntry */ fun fillWith(text: String): PinEntry { - val newDigits = digits.toMutableList() + val newDigits = MutableList(size) { PinDigit.Empty } text.forEachIndexed { index, char -> - if (index < size) { + if (index < size && char.isDigit()) { newDigits[index] = PinDigit.Filled(char) } } diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinNode.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinNode.kt index 7474289f1e..762b9b4bc8 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinNode.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinNode.kt @@ -38,7 +38,7 @@ class SetupPinNode @AssistedInject constructor( val state = presenter.present() SetupPinView( state = state, - onBackClicked = { }, + onBackClicked = this::navigateUp, modifier = modifier ) } diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinView.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinView.kt index b8f40b06d0..b2174d2233 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinView.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/setup/SetupPinView.kt @@ -29,8 +29,12 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Lock import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment 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.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp @@ -105,12 +109,17 @@ private fun SetupPinContent( state: SetupPinState, modifier: Modifier = Modifier, ) { + val focusRequester = remember { FocusRequester() } + LaunchedEffect(Unit) { + focusRequester.requestFocus() + } PinEntryTextField( state.activePinEntry, onValueChange = { state.eventSink(SetupPinEvents.OnPinEntryChanged(it)) }, modifier = modifier + .focusRequester(focusRequester) .padding(top = 36.dp) .fillMaxWidth() )