Skip to content

Commit

Permalink
Refactor: Allow users to scan QR codes even after exceeding max faile…
Browse files Browse the repository at this point in the history
…d attempts.

- Removed unnecessary functions that returned Flows in FormValidator.
- Introduced a new composable `PreMeasuredContentWithAnimatedVisibility` to pre-measure content height so that when we don't want to change the height of a layout (e.g. resulting in "pushing" the content up in a Column etc) when content with AnimatedVisibility shows/hides.
- Updated QR scanning screen to use the new composable for displaying informative text.
- Updated unit tests.
  • Loading branch information
gstamatop committed Sep 5, 2024
1 parent 67d2e8b commit 96fcf0d
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil
import eu.europa.ec.businesslogic.controller.log.LogController
import eu.europa.ec.businesslogic.util.safeLet
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.withContext

interface FormValidator {
fun validateFormFlow(form: Form): Flow<FormValidationResult>
fun validateFormsFlow(forms: List<Form>): Flow<FormsValidationResult>

suspend fun validateForm(form: Form): FormValidationResult
suspend fun validateForms(forms: List<Form>): FormsValidationResult
}
Expand All @@ -39,18 +33,6 @@ class FormValidatorImpl(
private val logController: LogController
) : FormValidator {

override fun validateFormFlow(form: Form): Flow<FormValidationResult> = flow {
form.inputs.forEach { (rules, value) ->
rules.forEach { rule ->
validateRule(rule, value)?.let {
emit(it)
return@flow
}
}
}
emit(FormValidationResult(isValid = true))
}.flowOn(Dispatchers.IO)

override suspend fun validateForm(form: Form): FormValidationResult =
withContext(Dispatchers.IO) {
for (input in form.inputs) {
Expand All @@ -64,22 +46,6 @@ class FormValidatorImpl(
return@withContext FormValidationResult(isValid = true)
}

override fun validateFormsFlow(forms: List<Form>): Flow<FormsValidationResult> = flow {
val errors = mutableListOf<String>()
var isValid = true
forms.forEach { form ->
form.inputs.forEach { (rules, value) ->
rules.forEach { rule ->
validateRule(rule, value)?.let {
isValid = false
errors.add(it.message)
}
}
}
}
emit(FormsValidationResult(isValid, errors))
}.flowOn(Dispatchers.IO)

override suspend fun validateForms(forms: List<Form>): FormsValidationResult =
withContext(Dispatchers.IO) {
val errorMessages = mutableListOf<String>()
Expand Down
Loading

0 comments on commit 96fcf0d

Please sign in to comment.