Skip to content

Commit

Permalink
add multi text check
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Feb 27, 2024
1 parent 55c9a02 commit 6580e86
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/layout/development_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6580e86

Please sign in to comment.