From 64d68029e417537bf481869d8f88b5174a2475aa Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 4 Dec 2018 10:40:03 +0100 Subject: [PATCH] - OptionSets with images saving name instead of codes fixed - v1.0.5 --- .../org/dhis2/data/forms/RulesRepository.java | 2 +- .../forms/dataentry/DataEntryPresenterImpl.java | 6 +++--- .../forms/dataentry/ProgramStageRepository.java | 5 +++-- .../forms/dataentry/fields/image/ImageHolder.java | 15 +++++++++++---- buildsystem/dependencies.gradle | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/dhis2/data/forms/RulesRepository.java b/app/src/main/java/org/dhis2/data/forms/RulesRepository.java index d5ae3aa639..affb802ff5 100644 --- a/app/src/main/java/org/dhis2/data/forms/RulesRepository.java +++ b/app/src/main/java/org/dhis2/data/forms/RulesRepository.java @@ -443,7 +443,7 @@ private static RuleAction create(@NonNull Cursor cursor) { return RuleActionHideSection.create(section); case ASSIGN: return RuleActionAssign.create(content, data, - isEmpty(attribute) ? dataElement : attribute, !isEmpty(attribute)); + isEmpty(attribute) ? dataElement : attribute); case SHOWWARNING: return RuleActionShowWarning.create(content, data, isEmpty(attribute) ? dataElement : attribute); diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/DataEntryPresenterImpl.java b/app/src/main/java/org/dhis2/data/forms/dataentry/DataEntryPresenterImpl.java index 7b7a2039fa..f3d8eb4938 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/DataEntryPresenterImpl.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/DataEntryPresenterImpl.java @@ -105,7 +105,7 @@ public void onAttach(@NonNull DataEntryView dataEntryView) { ); } - private void save(String uid, String value, Boolean isAttribute) { + private void save(String uid, String value) { CompositeDisposable saveDisposable = new CompositeDisposable(); saveDisposable.add( dataEntryStore.save(uid, value) @@ -214,12 +214,12 @@ private void applyRuleEffects(Map fieldViewModels, Resul RuleActionAssign assign = (RuleActionAssign) ruleAction; if (fieldViewModels.get(assign.field()) == null) - save(assign.field(), ruleEffect.data(),assign.isAttribute()); + save(assign.field(), ruleEffect.data()); else { String value = fieldViewModels.get(assign.field()).value(); if (value == null || !value.equals(ruleEffect.data())) { - save(assign.field(), ruleEffect.data(),assign.isAttribute()); + save(assign.field(), ruleEffect.data()); } fieldViewModels.put(assign.field(), fieldViewModels.get(assign.field()).withValue(ruleEffect.data())); diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/ProgramStageRepository.java b/app/src/main/java/org/dhis2/data/forms/dataentry/ProgramStageRepository.java index fd0c7dfd0a..c64229b6f6 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/ProgramStageRepository.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/ProgramStageRepository.java @@ -80,7 +80,7 @@ final class ProgramStageRepository implements DataEntryRepository { private static final String SECTION_RENDERING_TYPE = "SELECT ProgramStageSection.mobileRenderType FROM ProgramStageSection WHERE ProgramStageSection.uid = ?"; private static final String ACCESS_QUERY = "SELECT ProgramStage.accessDataWrite FROM ProgramStage JOIN Event ON Event.programStage = ProgramStage.uid WHERE Event.uid = ?"; private static final String PROGRAM_ACCESS_QUERY = "SELECT Program.accessDataWrite FROM Program JOIN Event ON Event.program = Program.uid WHERE Event.uid = ?"; - private static final String OPTIONS = "SELECT Option.uid, Option.displayName FROM Option WHERE Option.optionSet = ?"; + private static final String OPTIONS = "SELECT Option.uid, Option.displayName, Option.code FROM Option WHERE Option.optionSet = ?"; @NonNull private final BriteDatabase briteDatabase; @@ -150,9 +150,10 @@ private List checkRenderType(List fieldViewModel for (int i = 0; i < cursor.getCount(); i++) { String uid = cursor.getString(0); String displayName = cursor.getString(1); + String code = cursor.getString(2); renderList.add(fieldFactory.create( fieldViewModel.uid() + "." + uid, //fist - displayName, ValueType.TEXT, false, + displayName+"-"+code, ValueType.TEXT, false, fieldViewModel.optionSet(), fieldViewModel.value(), fieldViewModel.programStageSection(), fieldViewModel.allowFutureDate(), fieldViewModel.editable() == null ? false : fieldViewModel.editable(), renderingType, fieldViewModel.description())); diff --git a/app/src/main/java/org/dhis2/data/forms/dataentry/fields/image/ImageHolder.java b/app/src/main/java/org/dhis2/data/forms/dataentry/fields/image/ImageHolder.java index 76f91f1b18..5b27881833 100644 --- a/app/src/main/java/org/dhis2/data/forms/dataentry/fields/image/ImageHolder.java +++ b/app/src/main/java/org/dhis2/data/forms/dataentry/fields/image/ImageHolder.java @@ -54,9 +54,13 @@ public ImageHolder(FormImageBinding mBinding, FlowableProcessor proce itemView.setOnClickListener(v -> { if (isEditable) { - String value = null; + String value; String[] uids = model.uid().split("\\."); - value = model.label(); + String[] labelAndCode = model.label().split("-"); + String label = labelAndCode[0]; + String code = labelAndCode[1]; + + value =code; valuePendingUpdate = value; binding.frame.setVisibility(binding.frame.getVisibility() == View.GONE ? View.VISIBLE : View.GONE); if(binding.frame.getVisibility()==View.VISIBLE) { @@ -75,13 +79,16 @@ public void update(ImageViewModel viewModel) { this.isEditable = viewModel.editable(); descriptionText = viewModel.description(); - label = new StringBuilder(viewModel.label()); + String[] labelAndCode = model.label().split("-"); + String labelName = labelAndCode[0]; + String code = labelAndCode[1]; + label = new StringBuilder(labelName); if (viewModel.mandatory()) label.append("*"); binding.setLabel(label.toString()); String[] uids = viewModel.uid().split("\\."); Bindings.setObjectStyle(binding.icon, itemView, uids[1]); - if (viewModel.value() != null && viewModel.value().equals(viewModel.label())) + if (viewModel.value() != null && viewModel.value().equals(code)) binding.frame.setVisibility(View.VISIBLE); else binding.frame.setVisibility(View.GONE); diff --git a/buildsystem/dependencies.gradle b/buildsystem/dependencies.gradle index f147c32a0c..7abae8196a 100644 --- a/buildsystem/dependencies.gradle +++ b/buildsystem/dependencies.gradle @@ -3,8 +3,8 @@ ext { sdk : 28, tools : "28.0.3", minSdk: 19, - vCode: 35, - vName: "1.0.4" + vCode: 36, + vName: "1.0.5" ] libraries = [