Skip to content

Commit

Permalink
Merge branch 'master' of github.com:OpenSRP/opensrp-client-native-for…
Browse files Browse the repository at this point in the history
…m into feature/fix_popup_constraints
  • Loading branch information
dubdabasoduba committed Feb 14, 2019
2 parents 8b33b04 + 0b65b25 commit b80a4b8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ public static Map<String, View> createRadioButtonAndCheckBoxLabel(String stepNam
labelText.setTag(R.id.original_text, Html.fromHtml(combinedLabelText));
labelText.setTextSize(labelTextSize);
canvasIds.put(labelConstraintLayout.getId());
if (readOnly) {
editButton.setVisibility(View.VISIBLE);
}
labelConstraintLayout.setEnabled(!readOnly);
linearLayout.addView(labelConstraintLayout);
createdViewsMap.put(JsonFormConstants.EDIT_BUTTON, editButton);
Expand Down Expand Up @@ -363,8 +360,8 @@ public static void showInfoIcon(String stepName, JSONObject jsonObject, CommonLi
}
}

public static void showEditButton(JSONObject jsonObject, View editableView, ImageView editButton,
CommonListener listener) throws JSONException {
public static void setEditButtonAttributes(JSONObject jsonObject, View editableView, ImageView editButton,
CommonListener listener) throws JSONException {
editButton.setTag(R.id.editable_view, editableView);
editButton.setTag(R.id.key, jsonObject.getString(JsonFormConstants.KEY));
editButton.setTag(R.id.type, jsonObject.getString("type"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ private List<View> attachJson(String stepName, Context context, JSONObject jsonO
String openMrsEntityId = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_ID);

boolean readOnly = false;
boolean editable = false;

if (jsonObject.has(JsonFormConstants.READ_ONLY)) {
readOnly = jsonObject.getBoolean(JsonFormConstants.READ_ONLY);
}
if (jsonObject.has(JsonFormConstants.EDITABLE)) {
editable = jsonObject.getBoolean(JsonFormConstants.EDITABLE);
}

List<View> views = new ArrayList<>(1);
JSONArray canvasIds = new JSONArray();
Expand All @@ -90,6 +95,9 @@ private List<View> attachJson(String stepName, Context context, JSONObject jsonO
editButton = (ImageView) labelViews.get(JsonFormConstants.EDIT_BUTTON);
if (editButton != null) {
showEditButton(jsonObject, editableCheckBoxes, editButton, listener);
if(editable){
editButton.setVisibility(View.VISIBLE);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private List<View> attachJson(String stepName, Context context, JsonFormFragment
MaterialEditText editText = editTextLayout.findViewById(R.id.edit_text);
ImageView editButton = editTextLayout.findViewById(R.id.material_edit_text_edit_button);

FormUtils.showEditButton(jsonObject, editText, editButton, listener);
FormUtils.setEditButtonAttributes(jsonObject, editText, editButton, listener);

attachLayout(stepName, context, formFragment, jsonObject, editText, editButton);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private List<View> attachJson(String stepName, Context context, JsonFormFragment
getLayout(), null);
NativeEditText editText = rootLayout.findViewById(R.id.normal_edit_text);
ImageView editButton = rootLayout.findViewById(R.id.normal_edit_text_edit_button);
FormUtils.showEditButton(jsonObject, editText, editButton, listener);
FormUtils.setEditButtonAttributes(jsonObject, editText, editButton, listener);
makeFromJson(stepName, context, formFragment, jsonObject, editText, editButton);

addRequiredValidator(jsonObject, editText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.List;
import java.util.Map;

import static com.vijay.jsonwizard.utils.FormUtils.showEditButton;
import static com.vijay.jsonwizard.widgets.DatePickerFactory.DATE_FORMAT;


Expand Down Expand Up @@ -264,9 +263,13 @@ protected List<View> attachJson(String stepName, Context context, JsonFormFragme
this.canvasIds = canvasIds;

boolean readOnly = false;
boolean editable = false;
if (jsonObject.has(JsonFormConstants.READ_ONLY)) {
readOnly = jsonObject.getBoolean(JsonFormConstants.READ_ONLY);
}
if (jsonObject.has(JsonFormConstants.EDITABLE)) {
editable = jsonObject.getBoolean(JsonFormConstants.EDITABLE);
}
List<View> views = new ArrayList<>(1);
ImageView editButton;

Expand All @@ -282,9 +285,11 @@ protected List<View> attachJson(String stepName, Context context, JsonFormFragme
if (labelViews != null && labelViews.size() > 0) {
editButton = (ImageView) labelViews.get(JsonFormConstants.EDIT_BUTTON);
if (editButton != null) {
showEditButton(jsonObject, radioGroup, editButton, listener);
FormUtils.setEditButtonAttributes(jsonObject, radioGroup, editButton, listener);
if(editable){
editButton.setVisibility(View.VISIBLE);
}
}

}
rootLayout.setTag(R.id.extraPopup, popup);
views.add(rootLayout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay
MaterialSpinner spinner = spinnerRelativeLayout.findViewById(R.id.material_spinner);
ImageView spinnerInfoIconImageView = spinnerRelativeLayout.findViewById(R.id.spinner_info_icon);
ImageView editButton = spinnerRelativeLayout.findViewById(R.id.spinner_edit_button);
FormUtils.showEditButton(jsonObject, spinner, editButton, listener);
FormUtils.setEditButtonAttributes(jsonObject, spinner, editButton, listener);
String hint = jsonObject.optString(JsonFormConstants.HINT);
if (!TextUtils.isEmpty(hint)) {
spinner.setHint(jsonObject.getString(JsonFormConstants.HINT));
Expand Down
15 changes: 9 additions & 6 deletions sample/src/main/assets/json.form/single_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@
"openmrs_entity_parent": "",
"openmrs_entity": "person_attribute",
"openmrs_entity_id": "Child_Register_Card_Number",
"editable": true,
"read_only": false,
"read_only": true,
"value": "1891389133",
"type": "edit_text",
"hint": "Child's register card number"
Expand Down Expand Up @@ -635,6 +634,7 @@
"label_text_color": "#FF9800",
"hint": "Any delivery complications?",
"read_only": true,
"editable": true,
"exclusive": [
"none"
],
Expand Down Expand Up @@ -744,7 +744,7 @@
"label": "Any symptoms of severe pre-eclampsia?",
"label_text_style": "bold",
"text_color": "#000000",
"read_only": true,
"editable": true,
"exclusive": [
"none"
],
Expand Down Expand Up @@ -971,7 +971,8 @@
"value": true,
"err": "Please select where stock was issued"
}
},{
},
{
"key": "site_ipv_assess",
"openmrs_entity_parent": "",
"openmrs_entity": "",
Expand Down Expand Up @@ -1319,12 +1320,13 @@
"edit_type": "name",
"edit_text_style": "bordered",
"value": "1909319333",
"editable": true,
"v_required": {
"value": "true",
"err": "Please enter the last name"
},
"v_regex": {
"value": "[A-Za-z\\s\.\-]*",
"value": "[0-9]*",
"err": "Please enter a valid name"
}
},
Expand All @@ -1337,13 +1339,14 @@
"hint": "Guardians name *",
"edit_type": "name",
"read_only": true,
"editable": true,
"edit_text_style": "bordered",
"v_required": {
"value": "true",
"err": "Please enter the guardians name"
},
"v_regex": {
"value": "[A-Za-z\\s\.\-]*",
"value": "[A-Za-z\\s\\.\\-]*",
"err": "Please enter a valid name"
}
},
Expand Down

0 comments on commit b80a4b8

Please sign in to comment.