Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add multi text check
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
Balcan committed Feb 22, 2024
1 parent 1b03ade commit 87f3abf
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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() {
26 changes: 26 additions & 0 deletions app/src/main/res/layout/development_activity.xml
Original file line number Diff line number Diff line change
@@ -185,6 +185,32 @@
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="UI Components" />


<TextView
style="@style/TextPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@color/primaryAlpha"
android:text="Force Multi text"
android:textColor="@color/colorAccent" />

<TextView
style="@style/TextSecondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Transforms TEXT data elements with option sets into MULTI TEXT."
android:textColor="@color/text_color" />

<com.google.android.material.button.MaterialButton
android:id="@+id/multitext"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="UPDATE" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -81,7 +81,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,

0 comments on commit 87f3abf

Please sign in to comment.