From 90ae78379e3816f5cee20e17d966ba3884c78d02 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 22 Feb 2024 13:20:01 +0100 Subject: [PATCH] add multi text check Signed-off-by: Pablo --- .../development/DevelopmentActivity.java | 19 ++++++++++++++ .../main/res/layout/development_activity.xml | 26 +++++++++++++++++++ .../dhis2/commons/bindings/ValueExtensions.kt | 2 +- .../form/ui/FieldViewModelFactoryImpl.kt | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/development/DevelopmentActivity.java b/app/src/main/java/org/dhis2/usescases/development/DevelopmentActivity.java index 5bcf549f3a..3c8add8f6e 100644 --- a/app/src/main/java/org/dhis2/usescases/development/DevelopmentActivity.java +++ b/app/src/main/java/org/dhis2/usescases/development/DevelopmentActivity.java @@ -14,6 +14,7 @@ import org.dhis2.usescases.general.ActivityGlobalAbstract; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.D2Manager; +import org.hisp.dhis.android.core.common.ValueType; import java.io.BufferedReader; import java.io.IOException; @@ -39,6 +40,24 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { loadCrashControl(); loadFeatureConfig(); loadConflicts(); + loadMultiText(); + } + + private void loadMultiText() { + D2 d2 = D2Manager.getD2(); + boolean hasMultiText = !d2.dataElementModule().dataElements().byValueType().eq(ValueType.MULTI_TEXT).blockingIsEmpty(); + binding.multitext.setText(hasMultiText ? "REVERT" : "FORCE MULTITEXT"); + binding.multitext.setOnClickListener(view -> { + if (hasMultiText) { + d2.databaseAdapter().execSQL( + "UPDATE DataElement SET valueType = \"TEXT\" WHERE valueType = \"MULTI_TEXT\" AND optionSet IS NOT null" + ); + } else { + d2.databaseAdapter().execSQL( + "UPDATE DataElement SET valueType = \"MULTI_TEXT\" WHERE valueType = \"TEXT\" AND optionSet IS NOT null" + ); + } + }); } private void loadConflicts() { diff --git a/app/src/main/res/layout/development_activity.xml b/app/src/main/res/layout/development_activity.xml index a7a57ce5cc..212ff2bad1 100644 --- a/app/src/main/res/layout/development_activity.xml +++ b/app/src/main/res/layout/development_activity.xml @@ -185,6 +185,32 @@ android:layout_height="wrap_content" android:layout_gravity="end" android:text="UI Components" /> + + + + + + + diff --git a/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt b/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt index fff9e1d235..85c0602f01 100644 --- a/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt +++ b/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt @@ -191,7 +191,7 @@ fun TrackedEntityDataValueObjectRepository.blockingGetValueCheck( private fun check(d2: D2, valueType: ValueType?, optionSetUid: String?, value: String): Boolean { return when { - valueType!= ValueType.MULTI_TEXT && optionSetUid != null -> { + valueType != ValueType.MULTI_TEXT && optionSetUid != null -> { val optionByCodeExist = d2.optionModule().options().byOptionSetUid().eq(optionSetUid) .byCode().eq(value).one().blockingExists() val optionByNameExist = d2.optionModule().options().byOptionSetUid().eq(optionSetUid) diff --git a/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt b/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt index 4c098fcd81..0fd5c6ef65 100644 --- a/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt +++ b/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt @@ -76,7 +76,7 @@ class FieldViewModelFactoryImpl( description = description, valueType = if (optionSet != null && valueType == ValueType.TEXT) ValueType.MULTI_TEXT else valueType, legend = legendValueProvider.provideLegendValue(id, value), - optionSet = if(valueType == ValueType.MULTI_TEXT) null else optionSet, + optionSet = if (valueType == ValueType.MULTI_TEXT) null else optionSet, allowFutureDates = allowFutureDates, uiEventFactory = UiEventFactoryImpl( id,