mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Setup pin : let time for ui to refresh before switching to confirmation step
This commit is contained in:
+26
-15
@@ -17,6 +17,7 @@
|
|||||||
package io.element.android.features.lockscreen.impl.setup
|
package io.element.android.features.lockscreen.impl.setup
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -27,6 +28,7 @@ import io.element.android.features.lockscreen.impl.setup.validation.PinValidator
|
|||||||
import io.element.android.features.lockscreen.impl.setup.validation.SetupPinFailure
|
import io.element.android.features.lockscreen.impl.setup.validation.SetupPinFailure
|
||||||
import io.element.android.libraries.architecture.Presenter
|
import io.element.android.libraries.architecture.Presenter
|
||||||
import io.element.android.libraries.core.meta.BuildMeta
|
import io.element.android.libraries.core.meta.BuildMeta
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SetupPinPresenter @Inject constructor(
|
class SetupPinPresenter @Inject constructor(
|
||||||
@@ -48,29 +50,38 @@ class SetupPinPresenter @Inject constructor(
|
|||||||
var setupPinFailure by remember {
|
var setupPinFailure by remember {
|
||||||
mutableStateOf<SetupPinFailure?>(null)
|
mutableStateOf<SetupPinFailure?>(null)
|
||||||
}
|
}
|
||||||
|
LaunchedEffect(choosePinEntry) {
|
||||||
|
if (choosePinEntry.isComplete()) {
|
||||||
|
when (val pinValidationResult = pinValidator.isPinValid(choosePinEntry)) {
|
||||||
|
is PinValidator.Result.Invalid -> {
|
||||||
|
setupPinFailure = pinValidationResult.failure
|
||||||
|
}
|
||||||
|
PinValidator.Result.Valid -> {
|
||||||
|
// Leave some time for the ui to refresh before showing confirmation
|
||||||
|
delay(150)
|
||||||
|
isConfirmationStep = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(confirmPinEntry) {
|
||||||
|
if (confirmPinEntry.isComplete()) {
|
||||||
|
if (confirmPinEntry == choosePinEntry) {
|
||||||
|
//TODO save in db and navigate to next screen
|
||||||
|
} else {
|
||||||
|
setupPinFailure = SetupPinFailure.PinsDontMatch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun handleEvents(event: SetupPinEvents) {
|
fun handleEvents(event: SetupPinEvents) {
|
||||||
when (event) {
|
when (event) {
|
||||||
is SetupPinEvents.OnPinEntryChanged -> {
|
is SetupPinEvents.OnPinEntryChanged -> {
|
||||||
if (isConfirmationStep) {
|
if (isConfirmationStep) {
|
||||||
confirmPinEntry = confirmPinEntry.fillWith(event.entryAsText)
|
confirmPinEntry = confirmPinEntry.fillWith(event.entryAsText)
|
||||||
if (confirmPinEntry.isComplete()) {
|
|
||||||
if (confirmPinEntry == choosePinEntry) {
|
|
||||||
//TODO save in db and navigate to next screen
|
|
||||||
} else {
|
|
||||||
setupPinFailure = SetupPinFailure.PinsDontMatch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
choosePinEntry = choosePinEntry.fillWith(event.entryAsText)
|
choosePinEntry = choosePinEntry.fillWith(event.entryAsText)
|
||||||
if (choosePinEntry.isComplete()) {
|
|
||||||
when (val pinValidationResult = pinValidator.isPinValid(choosePinEntry)) {
|
|
||||||
is PinValidator.Result.Invalid -> {
|
|
||||||
setupPinFailure = pinValidationResult.failure
|
|
||||||
}
|
|
||||||
PinValidator.Result.Valid -> isConfirmationStep = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetupPinEvents.ClearFailure -> {
|
SetupPinEvents.ClearFailure -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user