Skip to content

Commit

Permalink
intermediate
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Nov 10, 2024
1 parent aaf29df commit 11efb05
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package edu.stanford.spezi.core.design

import androidx.compose.runtime.mutableStateOf

Check warning on line 3 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L3 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:3:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 3 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L3 <detekt.UnusedImports>

The import 'androidx.compose.runtime.mutableStateOf' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:3:1: warning: The import 'androidx.compose.runtime.mutableStateOf' is unused. (detekt.UnusedImports)
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText

Check warning on line 5 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L5 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:5:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 5 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L5 <detekt.UnusedImports>

The import 'androidx.compose.ui.test.onNodeWithText' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:5:1: warning: The import 'androidx.compose.ui.test.onNodeWithText' is unused. (detekt.UnusedImports)
import edu.stanford.spezi.core.design.composables.FocusValidationRules
import edu.stanford.spezi.core.design.simulator.FocusValidationRulesSimulator
import edu.stanford.spezi.core.design.views.validation.state.ValidationContext

Check warning on line 8 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L8 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:8:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 8 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L8 <detekt.UnusedImports>

The import 'edu.stanford.spezi.core.design.views.validation.state.ValidationContext' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:8:1: warning: The import 'edu.stanford.spezi.core.design.views.validation.state.ValidationContext' is unused. (detekt.UnusedImports)
import kotlinx.coroutines.delay

Check warning on line 9 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L9 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:9:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 9 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L9 <detekt.UnusedImports>

The import 'kotlinx.coroutines.delay' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:9:1: warning: The import 'kotlinx.coroutines.delay' is unused. (detekt.UnusedImports)
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class ValidationTest {

@get:Rule
val composeTestRule = createComposeRule()

@Before
fun init() {
composeTestRule.setContent {
FocusValidationRules()
}
}

@Test
fun testValidationWithFocus() {
focusValidationRules {
assertHasEngines(true)
assertInputValid(false)
assertPasswordMessageExists(false)
assertEmptyMessageExists(false)
clickValidateButton()
assertLastState(false)
assertPasswordMessageExists(true)
// assertEmptyMessageExists(true)
}
}

private fun focusValidationRules(block: FocusValidationRulesSimulator.() -> Unit) {
FocusValidationRulesSimulator(composeTestRule).apply(block)
}

Check warning on line 43 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt#L43 <detekt.NoBlankLineBeforeRbrace>

Unexpected blank line(s) before "}"
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/ValidationTest.kt:43:1: warning: Unexpected blank line(s) before "}" (detekt.NoBlankLineBeforeRbrace)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package edu.stanford.spezi.core.design.composables

import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import edu.stanford.spezi.core.design.component.StringResource
import edu.stanford.spezi.core.design.views.validation.Validate
import edu.stanford.spezi.core.design.views.validation.ValidationRule
import edu.stanford.spezi.core.design.views.validation.asciiLettersOnly
import edu.stanford.spezi.core.design.views.validation.mediumPassword
import edu.stanford.spezi.core.design.views.validation.minimalEmail
import edu.stanford.spezi.core.design.views.validation.minimalPassword
import edu.stanford.spezi.core.design.views.validation.nonEmpty
import edu.stanford.spezi.core.design.views.validation.strongPassword
import edu.stanford.spezi.core.design.views.validation.unicodeLettersOnly
import edu.stanford.spezi.core.design.views.validation.views.VerifiableTextField

@Composable
fun DefaultValidationRules() {
val input = remember { mutableStateOf("") }
val rules = remember {
listOf(
ValidationRule.nonEmpty,
ValidationRule.unicodeLettersOnly,
ValidationRule.asciiLettersOnly,
ValidationRule.minimalEmail,
ValidationRule.minimalPassword,
ValidationRule.mediumPassword,
ValidationRule.strongPassword
)
}
Validate(input.value, rules) {
VerifiableTextField(
StringResource("Field"),
text = input
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package edu.stanford.spezi.core.design.composables

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Button
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope

Check warning on line 11 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/composables/FocusValidationRules.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/composables/FocusValidationRules.kt#L11 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/composables/FocusValidationRules.kt:11:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 11 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/composables/FocusValidationRules.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/composables/FocusValidationRules.kt#L11 <detekt.UnusedImports>

The import 'androidx.compose.runtime.rememberCoroutineScope' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/composables/FocusValidationRules.kt:11:1: warning: The import 'androidx.compose.runtime.rememberCoroutineScope' is unused. (detekt.UnusedImports)
import edu.stanford.spezi.core.design.component.StringResource
import edu.stanford.spezi.core.design.views.validation.Validate
import edu.stanford.spezi.core.design.views.validation.ValidationRule
import edu.stanford.spezi.core.design.views.validation.minimalPassword
import edu.stanford.spezi.core.design.views.validation.nonEmpty
import edu.stanford.spezi.core.design.views.validation.state.ReceiveValidation
import edu.stanford.spezi.core.design.views.validation.state.ValidationContext
import edu.stanford.spezi.core.design.views.validation.views.VerifiableTextField

enum class Field {
INPUT, NON_EMPTY_INPUT
}

@Composable
fun FocusValidationRules() {
val input = remember { mutableStateOf("") }
val nonEmptyInput = remember { mutableStateOf("") }
val validationContext = remember { mutableStateOf(ValidationContext()) }
val lastValid = remember { mutableStateOf<Boolean?>(null) }
val switchFocus = remember { mutableStateOf(false) }

ReceiveValidation(validationContext) {
Column {
Text("Has Engines: ${if (!validationContext.value.isEmpty) "Yes" else "No"}")
Text("Input Valid: ${if (validationContext.value.allInputValid) "Yes" else "No"}")
lastValid.value?.let { lastValid ->
Text("Last state: ${if (lastValid) "valid" else "invalid"}")
}
Button(
onClick = {
val newLastValid = validationContext.value
.validateHierarchy(switchFocus.value)
lastValid.value = newLastValid
}
) {
Text("Validate")
}
Row {
Text("Switch Focus")
Switch(switchFocus.value, onCheckedChange = { switchFocus.value = it })
}

Validate(input.value, rules = listOf(ValidationRule.minimalPassword)) {
VerifiableTextField(StringResource(Field.INPUT.name), input)
}

Validate(nonEmptyInput.value, rules = listOf(ValidationRule.nonEmpty)) {
VerifiableTextField(StringResource(Field.NON_EMPTY_INPUT.name), nonEmptyInput)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.stanford.spezi.core.design.simulator

import androidx.compose.ui.test.junit4.ComposeTestRule

class DefaultValidationRulesSimulator(

Check warning on line 5 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt#L5 <detekt.UseDataClass>

The class DefaultValidationRulesSimulator defines no functionality and only holds data. Consider converting it to a data class.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt:5:7: warning: The class DefaultValidationRulesSimulator defines no functionality and only holds data. Consider converting it to a data class. (detekt.UseDataClass)
private val composeTestRule: ComposeTestRule,
) {

Check warning on line 7 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt#L7 <detekt.EmptyClassBlock>

The class or object DefaultValidationRulesSimulator is empty.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt:7:3: warning: The class or object DefaultValidationRulesSimulator is empty. (detekt.EmptyClassBlock)

Check warning on line 7 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt#L7 <detekt.NoEmptyClassBody>

Unnecessary block ("{}")
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt:7:3: warning: Unnecessary block ("{}") (detekt.NoEmptyClassBody)

Check warning on line 8 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt#L8 <detekt.NoBlankLineBeforeRbrace>

Unexpected blank line(s) before "}"
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/DefaultValidationRulesSimulator.kt:8:1: warning: Unexpected blank line(s) before "}" (detekt.NoBlankLineBeforeRbrace)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package edu.stanford.spezi.core.design.simulator

import androidx.compose.material3.Text

Check warning on line 3 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt#L3 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt:3:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 3 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt#L3 <detekt.UnusedImports>

The import 'androidx.compose.material3.Text' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt:3:1: warning: The import 'androidx.compose.material3.Text' is unused. (detekt.UnusedImports)
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsOn

Check warning on line 5 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt#L5 <detekt.NoUnusedImports>

Unused import
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt:5:1: warning: Unused import (detekt.NoUnusedImports)

Check warning on line 5 in core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt

View workflow job for this annotation

GitHub Actions / detekt

[detekt] core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt#L5 <detekt.UnusedImports>

The import 'androidx.compose.ui.test.assertIsOn' is unused.
Raw output
/github/workspace/core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/simulator/FocusValidationRulesSimulator.kt:5:1: warning: The import 'androidx.compose.ui.test.assertIsOn' is unused. (detekt.UnusedImports)
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick

class FocusValidationRulesSimulator(
private val composeTestRule: ComposeTestRule,
) {
private val passwordMessage = "Your password must be at least 8 characters long."
private val emptyMessage = "This field cannot be empty."

fun assertHasEngines(hasEngines: Boolean) {
composeTestRule
.onNodeWithText("Has Engines: ${if (hasEngines) "Yes" else "No"}")
.assertExists()
}

fun assertInputValid(inputValid: Boolean) {
composeTestRule
.onNodeWithText("Input Valid: ${if (inputValid) "Yes" else "No"}")
.assertExists()
}

fun assertPasswordMessageExists(exists: Boolean) {
val node = composeTestRule.onNodeWithText(passwordMessage)
if (exists) node.assertExists() else node.assertDoesNotExist()
}

fun assertEmptyMessageExists(exists: Boolean) {
val node = composeTestRule.onNodeWithText(emptyMessage)
if (exists) node.assertExists() else node.assertDoesNotExist()
}

fun clickValidateButton() {
composeTestRule
.onNodeWithText("Validate")
.assertHasClickAction()
.performClick()
}

fun assertLastState(valid: Boolean) {
composeTestRule
.onNodeWithText("Last state: ${if (valid) "valid" else "invalid"}")
.assertExists()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import edu.stanford.spezi.core.design.component.ImageResource
import edu.stanford.spezi.core.design.component.ImageResourceComposable
import edu.stanford.spezi.core.design.theme.Colors
import edu.stanford.spezi.core.design.theme.lighten
import kotlin.math.min
Expand All @@ -28,9 +30,9 @@ import kotlin.math.min
fun UserProfileComposable(
modifier: Modifier = Modifier,
name: PersonNameComponents,
imageLoader: suspend () -> ImageVector? = { null }, // TODO: Use ImageResource instead!
imageLoader: suspend () -> ImageResource? = { null },
) {
val image = remember { mutableStateOf<ImageVector?>(null) }
val image = remember { mutableStateOf<ImageResource?>(null) }
val size = remember { mutableStateOf(IntSize.Zero) }

LaunchedEffect(Unit) {
Expand All @@ -41,9 +43,9 @@ fun UserProfileComposable(
val sideLength = min(size.value.height, size.value.width).dp
Box(modifier.size(sideLength, sideLength), contentAlignment = Alignment.Center) {
image.value?.let {
Image(
ImageResourceComposable(
it,
null,
"", // TODO: Add contentDescription to ImageResource directly?
Modifier
.clip(CircleShape)
.background(Colors.background, CircleShape)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package edu.stanford.spezi.core.design.views.personalInfo.fields

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.staggeredgrid.LazyHorizontalStaggeredGrid
import androidx.compose.material3.Divider
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.stanford.spezi.core.design.views.personalInfo.fields

import android.app.Person
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,69 @@
package edu.stanford.spezi.core.design.views.validation

import android.provider.Settings.Global
import androidx.compose.runtime.mutableStateOf
import edu.stanford.spezi.core.design.views.validation.configuration.DEFAULT_VALIDATION_DEBOUNCE_DURATION
import edu.stanford.spezi.core.design.views.validation.state.FailedValidationResult
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.util.EnumSet
import kotlin.time.Duration

typealias ValidationEngineConfiguration = EnumSet<ValidationEngine.ConfigurationOption>

class ValidationEngine(
val rules: List<ValidationRule>,
var debounceDuration: Duration = DEFAULT_VALIDATION_DEBOUNCE_DURATION,
var configuration: ValidationEngineConfiguration = ValidationEngineConfiguration.noneOf(ConfigurationOption::class.java),
) {
private enum class Source {
SUBMIT, MANUAL
}
internal typealias ValidationEngineConfiguration = EnumSet<ValidationEngine.ConfigurationOption>

interface ValidationEngine {
enum class ConfigurationOption {
HIDE_FAILED_VALIDATION_ON_EMPTY_SUBMIT,
CONSIDER_NO_INPUT_AS_VALID,
}

var validationResults: List<FailedValidationResult> = emptyList()
private set
val rules: List<ValidationRule>
val inputValid: Boolean
val validationResults: List<FailedValidationResult>
val isDisplayingValidationErrors: Boolean
val displayedValidationResults: List<FailedValidationResult>
var debounceDuration: Duration

fun submit(input: String, debounce: Boolean = false)
fun runValidation(input: String)
}

internal class ValidationEngineImpl(
override val rules: List<ValidationRule>,
override var debounceDuration: Duration = DEFAULT_VALIDATION_DEBOUNCE_DURATION,
var configuration: ValidationEngineConfiguration =
ValidationEngineConfiguration.noneOf(ValidationEngine.ConfigurationOption::class.java),
) : ValidationEngine {
private enum class Source {
SUBMIT, MANUAL
}

private var validationResultsState = mutableStateOf(emptyList<FailedValidationResult>())

override val validationResults get() = validationResultsState.value

private var computedInputValid: Boolean? = null

val inputValid: Boolean get() =
computedInputValid ?: configuration.contains(ConfigurationOption.CONSIDER_NO_INPUT_AS_VALID)
override val inputValid: Boolean get() =
computedInputValid ?: configuration.contains(ValidationEngine.ConfigurationOption.CONSIDER_NO_INPUT_AS_VALID)

private var source: Source? = null
private var inputWasEmpty = true

val isDisplayingValidationErrors: Boolean get() {
override val isDisplayingValidationErrors: Boolean get() {
val gotResults = validationResults.isNotEmpty()

if (configuration.contains(ConfigurationOption.HIDE_FAILED_VALIDATION_ON_EMPTY_SUBMIT)) {
if (configuration.contains(ValidationEngine.ConfigurationOption.HIDE_FAILED_VALIDATION_ON_EMPTY_SUBMIT)) {
return gotResults && (source == Source.MANUAL || !inputWasEmpty)
}

return gotResults
}

val displayedValidationResults: List<FailedValidationResult> get() =
override val displayedValidationResults: List<FailedValidationResult> get() =
if (isDisplayingValidationErrors) validationResults else emptyList()

private var debounceJob: Job? = null
Expand All @@ -75,11 +86,11 @@ class ValidationEngine(
this.source = source
this.inputWasEmpty = input.isEmpty()

this.validationResults = computeFailedValidations(input)
this.validationResultsState.value = computeFailedValidations(input)
this.computedInputValid = validationResults.isEmpty()
}

fun submit(input: String, debounce: Boolean = false) {
override fun submit(input: String, debounce: Boolean) {
if (!debounce || computedInputValid == false) {
computeValidation(input, Source.SUBMIT)
} else {
Expand All @@ -89,7 +100,7 @@ class ValidationEngine(
}
}

fun runValidation(input: String) {
override fun runValidation(input: String) {
computeValidation(input, Source.MANUAL)
}

Expand Down
Loading

0 comments on commit 11efb05

Please sign in to comment.