Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/show color by legend in data entry form #16

Merged
merged 7 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/assets/paperwork.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildTime":"2020-07-07 09:52","gitSha":"959f9e840"}
{"buildTime":"2020-07-17 16:45","gitSha":"effee437f"}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ class EnrollmentRepository(
programTrackedEntityAttribute.renderType()?.mobile(),
optionCount,
attribute.style(),
attribute.fieldMask()
attribute.fieldMask(),
null
)

return if (warning != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ FieldViewModel create(@NonNull String id,
@Nullable ValueTypeDeviceRendering fieldRendering,
@Nullable Integer optionCount,
@NonNull ObjectStyle objectStyle,
@Nullable String fieldMask);
@Nullable String fieldMask,
@Nullable String colorByLegend);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public FieldViewModelFactoryImpl(Map<ValueType, String> valueTypeHintMap) {
public FieldViewModel create(@NonNull String id, @NonNull String label, @NonNull ValueType type,
@NonNull Boolean mandatory, @Nullable String optionSet, @Nullable String value,
@Nullable String section, @Nullable Boolean allowFutureDates, @NonNull Boolean editable, @Nullable ProgramStageSectionRenderingType renderingType,
@Nullable String description, @Nullable ValueTypeDeviceRendering fieldRendering, @Nullable Integer optionCount, ObjectStyle objectStyle, @Nullable String fieldMask) {
@Nullable String description, @Nullable ValueTypeDeviceRendering fieldRendering, @Nullable Integer optionCount, ObjectStyle objectStyle, @Nullable String fieldMask,
@Nullable String colorByLegend) {
isNull(type, "type must be supplied");

if (!isEmpty(optionSet)) {
Expand All @@ -64,7 +65,7 @@ public FieldViewModel create(@NonNull String id, @NonNull String label, @NonNull
} else if (fieldRendering != null && type == ValueType.TEXT && optionSetTextRenderings.contains(fieldRendering.type())) {
return OptionSetViewModel.create(id, label, mandatory, optionSet, value, section, editable, description, objectStyle, fieldRendering);
} else {
return SpinnerViewModel.create(id, label, valueTypeHintMap.get(type), mandatory, optionSet, value, section, editable, description, optionCount, objectStyle);
return SpinnerViewModel.create(id, label, valueTypeHintMap.get(type), mandatory, optionSet, value, section, editable, description, optionCount, objectStyle, colorByLegend);
}
} else
return ImageViewModel.create(id, label, optionSet, value, section, editable, mandatory, description, objectStyle); //transforms option set into image option selector
Expand All @@ -89,7 +90,7 @@ public FieldViewModel create(@NonNull String id, @NonNull String label, @NonNull
if (fieldRendering != null && (fieldRendering.type().equals(ValueTypeRenderingType.QR_CODE) || fieldRendering.type().equals(ValueTypeRenderingType.BAR_CODE))) {
return ScanTextViewModel.create(id, label, mandatory, value, section, editable, optionSet, description, objectStyle, fieldRendering);
} else {
return EditTextViewModel.create(id, label, mandatory, value, valueTypeHintMap.get(type), 1, type, section, editable, description, fieldRendering, objectStyle, fieldMask);
return EditTextViewModel.create(id, label, mandatory, value, valueTypeHintMap.get(type), 1, type, section, editable, description, fieldRendering, objectStyle, fieldMask, colorByLegend);
}
case IMAGE:
return PictureViewModel.create(id, label, mandatory, value, section, editable, description, objectStyle);
Expand All @@ -110,7 +111,7 @@ public FieldViewModel create(@NonNull String id, @NonNull String label, @NonNull
case USERNAME:
return UnsupportedViewModel.create(id, label, mandatory, value, section, editable, description, objectStyle);
default:
return EditTextViewModel.create(id, label, mandatory, value, valueTypeHintMap.get(type), 1, type, section, editable, description, fieldRendering, objectStyle, fieldMask);
return EditTextViewModel.create(id, label, mandatory, value, valueTypeHintMap.get(type), 1, type, section, editable, description, fieldRendering, objectStyle, fieldMask, colorByLegend);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
Expand Down Expand Up @@ -101,6 +104,10 @@ public void update(@NonNull FieldViewModel model) {
this.editTextModel = (EditTextViewModel) model;
fieldUid = model.uid();

if (!isSearchMode) {
assignBackgroundColorByLegend();
}

binding.customEdittext.setValueType(editTextModel.valueType());

binding.customEdittext.setObjectStyle(model.objectStyle());
Expand Down Expand Up @@ -130,6 +137,15 @@ public void update(@NonNull FieldViewModel model) {
setLongClick();
}

private void assignBackgroundColorByLegend() {
if (editTextModel.colorByLegend() != null && editTextModel.colorByLegend() != ""){
binding.customEdittext.setBackgroundColor(Color.parseColor(editTextModel.colorByLegend()));
} else {
int color = ContextCompat.getColor(binding.customEdittext.getContext(), R.color.form_field_background);
binding.customEdittext.setBackgroundColor(color);
}
}

private void checkAutocompleteRendering() {
if (editTextModel.fieldRendering() != null &&
editTextModel.fieldRendering().type() == ValueTypeRenderingType.AUTOCOMPLETE &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ public abstract class EditTextViewModel extends EditTextModel<String> {
@Nullable
public abstract ValueTypeDeviceRendering fieldRendering();

@Nullable
public abstract String colorByLegend();

@NonNull
public static EditTextViewModel create(@NonNull String uid, @NonNull String label,
@NonNull Boolean mandatory, @Nullable String value, @NonNull String hint,
@NonNull Integer lines, @NonNull ValueType valueType, @Nullable String section,
@NonNull Boolean editable, @Nullable String description,
@Nullable ValueTypeDeviceRendering fieldRendering, ObjectStyle objectStyle, @Nullable String fieldMask) {
@Nullable ValueTypeDeviceRendering fieldRendering, ObjectStyle objectStyle, @Nullable String fieldMask,
@Nullable String colorByLegend) {
return new AutoValue_EditTextViewModel(uid, label, mandatory,
value, section, null, editable, null, description, objectStyle, fieldMask,hint, lines,
InputType.TYPE_CLASS_TEXT, valueType, null, null, fieldRendering);
InputType.TYPE_CLASS_TEXT, valueType, null, null, fieldRendering, colorByLegend);
}

@NonNull
@Override
public EditTextViewModel withWarning(@NonNull String warning) {
return new AutoValue_EditTextViewModel(uid(), label(), mandatory(),
value(), programStageSection(), null, editable(), null,
description(), objectStyle(), fieldMask(), hint(), maxLines(), inputType(), valueType(), warning, error(), fieldRendering());
description(), objectStyle(), fieldMask(), hint(), maxLines(), inputType(), valueType(), warning, error(), fieldRendering(), colorByLegend());
}

@NonNull
Expand All @@ -49,7 +53,7 @@ public EditTextViewModel withError(@NonNull String error) {
return new AutoValue_EditTextViewModel(uid(), label(), mandatory(),
value(), programStageSection(), null, true, null,
description(), objectStyle(), fieldMask(), hint(), maxLines(), inputType(), valueType(), warning(), error,
fieldRendering());
fieldRendering(), colorByLegend());
}

@NonNull
Expand All @@ -58,7 +62,7 @@ public FieldViewModel setMandatory() {
return new AutoValue_EditTextViewModel(uid(), label(), true,
value(), programStageSection(), null, editable(), null,
description(), objectStyle(), fieldMask(), hint(), maxLines(), InputType.TYPE_CLASS_TEXT, valueType(), warning(), error(),
fieldRendering());
fieldRendering(), colorByLegend());
}

@Nonnull
Expand All @@ -67,7 +71,7 @@ public FieldViewModel withValue(String data) {
return new AutoValue_EditTextViewModel(uid(), label(), mandatory(),
data, programStageSection(), null, false, null,
description(), objectStyle(), fieldMask(), hint(), maxLines(), InputType.TYPE_CLASS_TEXT, valueType(), warning(), error(),
fieldRendering());
fieldRendering(), colorByLegend());
}

@NonNull
Expand All @@ -76,5 +80,14 @@ public FieldViewModel withEditMode(boolean isEditable) {
return new AutoValue_EditTextViewModel(uid(), label(), mandatory(),
value(), programStageSection(), null, isEditable, null,
description(), objectStyle(), fieldMask(), hint(), maxLines(), InputType.TYPE_CLASS_TEXT, valueType(), warning(), error(),
fieldRendering()); }
fieldRendering(), colorByLegend());
}

@NonNull
public FieldViewModel withColorByLegend(String colorByLegend) {
return new AutoValue_EditTextViewModel(uid(), label(), mandatory(),
value(), programStageSection(), null, editable(), null,
description(), objectStyle(), fieldMask(), hint(), maxLines(), InputType.TYPE_CLASS_TEXT, valueType(), warning(), error(),
fieldRendering(), colorByLegend);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.dhis2.data.forms.dataentry.fields.spinner;

import android.graphics.Color;
import android.view.View;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.MutableLiveData;

import org.dhis2.R;
import org.dhis2.data.forms.dataentry.fields.FormViewHolder;
import org.dhis2.data.forms.dataentry.fields.RowAction;
import org.dhis2.databinding.FormOptionSetBinding;
Expand Down Expand Up @@ -58,6 +61,19 @@ public void update(SpinnerViewModel viewModel) {
binding.optionSetView.setOnClickListener(this);
label = new StringBuilder().append(viewModel.label());
initFieldFocus();

if(!isSearchMode){
assignBackgroundColorByLegend();
}
}

private void assignBackgroundColorByLegend() {
if (viewModel.colorByLegend() != null && viewModel.colorByLegend() != ""){
binding.optionSetView.setBackgroundColor(Color.parseColor(viewModel.colorByLegend()));
} else {
int color = ContextCompat.getColor(binding.optionSetView.getContext(), R.color.form_field_background);
binding.optionSetView.setBackgroundColor(color);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dhis2.data.forms.dataentry.fields.spinner;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.auto.value.AutoValue;

Expand All @@ -23,6 +24,9 @@ public abstract class SpinnerViewModel extends FieldViewModel {
private List<String> optionGroupsToHide;
private List<String> optionGroupsToShow = new ArrayList<>();

@Nullable
public abstract String colorByLegend();

@NonNull
public abstract String hint();

Expand All @@ -33,39 +37,46 @@ public abstract class SpinnerViewModel extends FieldViewModel {
public abstract Integer numberOfOptions();

public static SpinnerViewModel create(String id, String label, String hintFilterOptions, Boolean mandatory,
String optionSet, String value, String section, Boolean editable, String description, Integer numberOfOptions, ObjectStyle objectStyle) {
return new AutoValue_SpinnerViewModel(id, label, mandatory, value, section, null, editable, null, null, description, objectStyle, null, hintFilterOptions, optionSet, numberOfOptions == null ? 0 : numberOfOptions);
String optionSet, String value, String section, Boolean editable, String description, Integer numberOfOptions, ObjectStyle objectStyle, String colorByLegend) {
return new AutoValue_SpinnerViewModel(id, label, mandatory, value, section, null, editable, null, null, description, objectStyle, null, colorByLegend, hintFilterOptions, optionSet, numberOfOptions == null ? 0 : numberOfOptions);
}

@Override
public FieldViewModel setMandatory() {
return new AutoValue_SpinnerViewModel(uid(), label(), true, value(), programStageSection(), allowFutureDate(), editable(), warning(), error(), description(), objectStyle(), null, hint(), optionSet(), numberOfOptions());
return new AutoValue_SpinnerViewModel(uid(), label(), true, value(), programStageSection(), allowFutureDate(), editable(), warning(), error(), description(), objectStyle(), null, colorByLegend(), hint(), optionSet(), numberOfOptions());
}

@NonNull
@Override
public FieldViewModel withError(@NonNull String error) {
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), editable(), warning(), error, description(), objectStyle(), null, hint(), optionSet(), numberOfOptions());
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), editable(), warning(), error, description(), objectStyle(), null, colorByLegend(), hint(), optionSet(), numberOfOptions());
}

@NonNull
@Override
public FieldViewModel withWarning(@NonNull String warning) {
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), editable(), warning, error(), description(), objectStyle(), null, hint(), optionSet(), numberOfOptions());
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), editable(), warning, error(), description(), objectStyle(), null, colorByLegend(), hint(), optionSet(), numberOfOptions());
}

@Nonnull
@Override
public FieldViewModel withValue(String data) {
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), data, programStageSection(), allowFutureDate(), false, warning(), error(), description(), objectStyle(), null, hint(), optionSet(), numberOfOptions());
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), data, programStageSection(), allowFutureDate(), false, warning(), error(), description(), objectStyle(), null, colorByLegend(), hint(), optionSet(), numberOfOptions());
}

@NonNull
@Override
public FieldViewModel withEditMode(boolean isEditable) {
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), isEditable, warning(), error(), description(), objectStyle(), null, hint(), optionSet(), numberOfOptions());
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), isEditable, warning(), error(), description(), objectStyle(), null, colorByLegend(), hint(), optionSet(), numberOfOptions());
}

@NonNull
public FieldViewModel withColorByLegend(String colorByLegend) {
return new AutoValue_SpinnerViewModel(uid(), label(), mandatory(), value(), programStageSection(), allowFutureDate(), editable(), warning(), error(), description(), objectStyle(), null, colorByLegend, hint(), optionSet(), numberOfOptions());

}


public void setOptionsToHide(List<String> optionsToHide, List<String> optionsGroupsToHide) {
this.optionGroupsToHide = new ArrayList<>();
this.optionsToHide = new ArrayList<>();
Expand Down
Loading