Skip to content

Commit

Permalink
[ANDROAPP-5952] input age prompt stays at beginning (#3543)
Browse files Browse the repository at this point in the history
* refactor custom icons

Signed-off-by: Pablo <[email protected]>

* fix: [ANDROAPP-5930] update design system and adapt input for textfieldValue

* fix: [ANDROAPP-5930] add null checks for value format

* fix: [ANDROAPP-5952] correct test

* fix: [ANDROAPP-5952] amend rebase conflic resolution update design system

---------

Signed-off-by: Pablo <[email protected]>
Co-authored-by: Pablo <[email protected]>
  • Loading branch information
xavimolloy and Balcan authored Mar 18, 2024
1 parent ba76cb4 commit d3faceb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class AgeProviderTest {
resources = resourceManager,
)
}
composeTestRule.onNodeWithTag(INPUT_AGE)
composeTestRule.onNodeWithTag(INPUT_AGE_MODE_SELECTOR)
composeTestRule.onNodeWithTag(INPUT_AGE_MODE_SELECTOR).assertIsDisplayed()

}

Expand All @@ -95,8 +94,6 @@ class AgeProviderTest {
resources = resourceManager,
)
}
composeTestRule.onNodeWithTag(INPUT_AGE)
composeTestRule.onNodeWithTag(INPUT_AGE_MODE_SELECTOR)
composeTestRule.onNodeWithText(DATE_OF_BIRTH).performClick()
composeTestRule.onNodeWithTag(INPUT_AGE_OPEN_CALENDAR_BUTTON).assertIsDisplayed()

Expand Down Expand Up @@ -138,8 +135,6 @@ class AgeProviderTest {
resources = resourceManager,
)
}
composeTestRule.onNodeWithTag(INPUT_AGE)
composeTestRule.onNodeWithTag(INPUT_AGE_MODE_SELECTOR)
composeTestRule.onNodeWithText(AGE_BUTTON_TEXT).performClick()
composeTestRule.onNodeWithTag(INPUT_AGE_TIME_UNIT_SELECTOR).assertIsDisplayed()
composeTestRule.onNodeWithTag(INPUT_AGE_TEXT_FIELD).performTextInput("6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.form.R
import org.dhis2.form.extensions.inputState
Expand Down Expand Up @@ -36,7 +38,7 @@ fun ProvideInputAge(
mutableStateOf(
if (!fieldUiModel.value.isNullOrEmpty()) {
formatStoredDateToUI(fieldUiModel.value!!).let {
AgeInputType.DateOfBirth(it)
AgeInputType.DateOfBirth(TextFieldValue(it, TextRange(it.length)))
}
} else {
AgeInputType.None
Expand All @@ -47,16 +49,20 @@ fun ProvideInputAge(
DisposableEffect(fieldUiModel.value) {
when (inputType) {
is AgeInputType.Age ->
calculateAgeFromDate(
fieldUiModel.value!!,
(inputType as AgeInputType.Age).unit,
)?.let {
(inputType as AgeInputType.Age).copy(value = it)
} ?: AgeInputType.None
if (!fieldUiModel.value.isNullOrEmpty()) {
calculateAgeFromDate(
fieldUiModel.value!!,
(inputType as AgeInputType.Age).unit,
)?.let {
(inputType as AgeInputType.Age).copy(value = TextFieldValue(it, TextRange(it.length)))
} ?: AgeInputType.None
}

is AgeInputType.DateOfBirth ->
formatStoredDateToUI(fieldUiModel.value!!).let {
(inputType as AgeInputType.DateOfBirth).copy(value = it)
if (!fieldUiModel.value.isNullOrEmpty()) {
formatStoredDateToUI(fieldUiModel.value!!).let {
(inputType as AgeInputType.DateOfBirth).copy(value = TextFieldValue(it, TextRange(it.length)))
}
}

AgeInputType.None -> {
Expand Down Expand Up @@ -99,7 +105,7 @@ fun ProvideInputAge(
saveValue(
intentHandler,
fieldUiModel.uid,
formatUIDateToStored(type.value),
formatUIDateToStored(type.value.text),
fieldUiModel.valueType,
fieldUiModel.allowFutureDates,
)
Expand Down Expand Up @@ -167,9 +173,9 @@ private fun calculateDateFromAge(age: AgeInputType.Age): String? {
val calendar = Calendar.getInstance()
return try {
when (age.unit) {
TimeUnitValues.YEARS -> calendar.add(Calendar.YEAR, -age.value.toInt())
TimeUnitValues.MONTHS -> calendar.add(Calendar.MONTH, -age.value.toInt())
TimeUnitValues.DAYS -> calendar.add(Calendar.DAY_OF_MONTH, -age.value.toInt())
TimeUnitValues.YEARS -> calendar.add(Calendar.YEAR, -age.value.text.toInt())
TimeUnitValues.MONTHS -> calendar.add(Calendar.MONTH, -age.value.text.toInt())
TimeUnitValues.DAYS -> calendar.add(Calendar.DAY_OF_MONTH, -age.value.text.toInt())
}

val dateFormat = SimpleDateFormat(DB_FORMAT, Locale.getDefault())
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kotlin = '1.9.21'
hilt = '2.47'
hiltCompiler = '1.0.0'
jacoco = '0.8.10'
designSystem = "0.2-20240313.110151-41"
designSystem = "0.2-20240314.101140-42"
dhis2sdk = "1.10.0-20240313.084114-35"
ruleEngine = "3.0.0-20240119.134348-12"
expressionParser = "1.1.0-20240219.115041-14"
Expand Down

0 comments on commit d3faceb

Please sign in to comment.