From d3faceb3fc9e3868221ee4cacdb5bc4888617833 Mon Sep 17 00:00:00 2001 From: Xavier Molloy <44061143+xavimolloy@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:38:50 +0100 Subject: [PATCH] [ANDROAPP-5952] input age prompt stays at beginning (#3543) * refactor custom icons Signed-off-by: Pablo * 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 Co-authored-by: Pablo --- .../ui/provider/inputfield/AgeProviderTest.kt | 7 +--- .../ui/provider/inputfield/AgeProvider.kt | 32 +++++++++++-------- gradle/libs.versions.toml | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt b/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt index 30584915fb..6160f1321d 100644 --- a/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt +++ b/form/src/androidTest/kotlin/org/dhis2/form/ui/provider/inputfield/AgeProviderTest.kt @@ -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() } @@ -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() @@ -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") diff --git a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt index fb3ea2ff92..78d23930f2 100644 --- a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt +++ b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/AgeProvider.kt @@ -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 @@ -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 @@ -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 -> { @@ -99,7 +105,7 @@ fun ProvideInputAge( saveValue( intentHandler, fieldUiModel.uid, - formatUIDateToStored(type.value), + formatUIDateToStored(type.value.text), fieldUiModel.valueType, fieldUiModel.allowFutureDates, ) @@ -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()) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 00a489d2fd..a05c87f984 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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"