From 5103b237bf779f272a13e27d8963dd66fab5ded2 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 09:13:31 +0300 Subject: [PATCH 1/6] Added alias support for Spinners --- .../constants/JsonFormConstants.java | 1 + .../presenters/JsonFormFragmentPresenter.java | 8 ++++++++ .../jsonwizard/widgets/SpinnerFactory.java | 7 +++++++ .../src/main/res/values/ids.xml | 1 + .../main/assets/json.form/single_form.json | 20 +++++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java index 075988781..20eb77978 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java @@ -43,6 +43,7 @@ public class JsonFormConstants { public static final String BEHAVIOUR = "behaviour"; public static final String RESULT = "result"; public static final String VALUE = "value"; + public static final String ALIAS = "alias"; public static final String SECOND_VALUE = "second_value"; public static final String OPENMRS_ENTITY_PARENT = "openmrs_entity_parent"; public static final String OPENMRS_ENTITY = "openmrs_entity"; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java index 3ddc93ab8..00feb9643 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java @@ -691,6 +691,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long String openMrsEntityParent = (String) parent.getTag(R.id.openmrs_entity_parent); String openMrsEntity = (String) parent.getTag(R.id.openmrs_entity); String openMrsEntityId = (String) parent.getTag(R.id.openmrs_entity_id); + JSONObject jsonObject = (JSONObject) parent.getTag(R.id.alias); CustomTextView customTextView = (CustomTextView) parent.getTag(R.id.number_selector_textview); Boolean popup = (Boolean) parent.getTag(R.id.extraPopup); if (popup == null) { @@ -698,6 +699,13 @@ public void onItemSelected(AdapterView parent, View view, int position, long } String value = parent.getItemAtPosition(position).toString(); + if(jsonObject != null && jsonObject.has(value)){ + try { + value = jsonObject.getString(value); + } catch (JSONException e) { + e.printStackTrace(); + } + } getView().writeValue(mStepName, parentKey, value, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup); if (JsonFormConstants.NUMBER_SELECTOR.equals(type)) { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java index 010c24952..df1444e47 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java @@ -29,7 +29,9 @@ import org.json.JSONObject; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Created by nipun on 30/05/15. @@ -103,6 +105,11 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay spinner.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT)); } + if (jsonObject.has(JsonFormConstants.ALIAS)) { + JSONObject aliasJson = jsonObject.getJSONObject(JsonFormConstants.ALIAS); + spinner.setTag(R.id.alias, aliasJson); + } + setViewTags(jsonObject, canvasIds, stepName, popup, openMrsEntityParent, openMrsEntity, openMrsEntityId, spinner); addSkipLogicTags(context, relevance, constraints, calculations, spinner); diff --git a/android-json-form-wizard/src/main/res/values/ids.xml b/android-json-form-wizard/src/main/res/values/ids.xml index c08f64b75..7bf103d85 100644 --- a/android-json-form-wizard/src/main/res/values/ids.xml +++ b/android-json-form-wizard/src/main/res/values/ids.xml @@ -19,6 +19,7 @@ + diff --git a/sample/src/main/assets/json.form/single_form.json b/sample/src/main/assets/json.form/single_form.json index 72b4d1e24..4e3ea407b 100644 --- a/sample/src/main/assets/json.form/single_form.json +++ b/sample/src/main/assets/json.form/single_form.json @@ -240,6 +240,26 @@ "err": "Please enter the sex" } }, + { + "key": "marital", + "openmrs_entity_parent": "", + "openmrs_entity": "person", + "openmrs_entity_id": "person_attribute", + "type": "spinner", + "hint": "Marital Status", + "values": [ + "Ame OA", + "Haja OA" + ], + "alias": { + "Ame OA": "Married", + "Haja OA": "Female" + }, + "v_required": { + "value": "true", + "err": "Please enter the sex" + } + }, { "key": "Date_Birth", "openmrs_entity_parent": "", From 6ac5de5cdd5aeb46a2c77136033b5794f7158f66 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 09:38:37 +0300 Subject: [PATCH 2/6] Spinner Factory Codacy Errors --- .../main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java index df1444e47..22080555e 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java @@ -29,9 +29,7 @@ import org.json.JSONObject; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * Created by nipun on 30/05/15. From ad38c0053974de8345d0edee36cdfe787fea5fce Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 11:11:27 +0300 Subject: [PATCH 3/6] Spinner - corrected read value for translated text --- .../java/com/vijay/jsonwizard/widgets/SpinnerFactory.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java index 22080555e..6be1e2d34 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java @@ -103,8 +103,9 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay spinner.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT)); } + JSONObject aliasJson = null; if (jsonObject.has(JsonFormConstants.ALIAS)) { - JSONObject aliasJson = jsonObject.getJSONObject(JsonFormConstants.ALIAS); + aliasJson = jsonObject.getJSONObject(JsonFormConstants.ALIAS); spinner.setTag(R.id.alias, aliasJson); } @@ -136,7 +137,9 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay values = new String[valuesJson.length()]; for (int i = 0; i < valuesJson.length(); i++) { values[i] = valuesJson.optString(i); - if (valueToSelect.equals(values[i])) { + if (aliasJson == null && valueToSelect.equals(values[i])) { + indexToSelect = i; + } else if (aliasJson != null && valueToSelect.equals(aliasJson.getString(values[i]))) { indexToSelect = i; } } From 46e06b1d37b8c3b45c0b4b372320e817d83e6f73 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 11:14:54 +0300 Subject: [PATCH 4/6] Updated example form for translated text with choice-ids --- sample/src/main/assets/json.form/single_form.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sample/src/main/assets/json.form/single_form.json b/sample/src/main/assets/json.form/single_form.json index 4e3ea407b..3c86e1b47 100644 --- a/sample/src/main/assets/json.form/single_form.json +++ b/sample/src/main/assets/json.form/single_form.json @@ -253,11 +253,15 @@ ], "alias": { "Ame OA": "Married", - "Haja OA": "Female" + "Haja OA": "Single" }, "v_required": { "value": "true", "err": "Please enter the sex" + }, + "openmrs_choice_ids": { + "Married": "1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "Single": "1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" } }, { From 66df34c767492e9da1c0421df21494c36e2269b5 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 12:56:54 +0300 Subject: [PATCH 5/6] Updated JSONObject to JSONArray in Spinner Alias --- .../jsonwizard/presenters/JsonFormFragmentPresenter.java | 6 +++--- .../java/com/vijay/jsonwizard/widgets/SpinnerFactory.java | 6 +++--- gradle.properties | 2 +- sample/src/main/assets/json.form/single_form.json | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java index 00feb9643..046a3f35e 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java @@ -691,7 +691,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long String openMrsEntityParent = (String) parent.getTag(R.id.openmrs_entity_parent); String openMrsEntity = (String) parent.getTag(R.id.openmrs_entity); String openMrsEntityId = (String) parent.getTag(R.id.openmrs_entity_id); - JSONObject jsonObject = (JSONObject) parent.getTag(R.id.alias); + JSONArray jsonArray = (JSONArray) parent.getTag(R.id.alias); CustomTextView customTextView = (CustomTextView) parent.getTag(R.id.number_selector_textview); Boolean popup = (Boolean) parent.getTag(R.id.extraPopup); if (popup == null) { @@ -699,9 +699,9 @@ public void onItemSelected(AdapterView parent, View view, int position, long } String value = parent.getItemAtPosition(position).toString(); - if(jsonObject != null && jsonObject.has(value)){ + if(jsonArray != null && position >0 && jsonArray.length() > 0){ try { - value = jsonObject.getString(value); + value = jsonArray.getString(position); } catch (JSONException e) { e.printStackTrace(); } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java index 6be1e2d34..0548a98dc 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java @@ -103,9 +103,9 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay spinner.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT)); } - JSONObject aliasJson = null; + JSONArray aliasJson = null; if (jsonObject.has(JsonFormConstants.ALIAS)) { - aliasJson = jsonObject.getJSONObject(JsonFormConstants.ALIAS); + aliasJson = jsonObject.getJSONArray(JsonFormConstants.ALIAS); spinner.setTag(R.id.alias, aliasJson); } @@ -139,7 +139,7 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay values[i] = valuesJson.optString(i); if (aliasJson == null && valueToSelect.equals(values[i])) { indexToSelect = i; - } else if (aliasJson != null && valueToSelect.equals(aliasJson.getString(values[i]))) { + } else if (aliasJson != null && valueToSelect.equals(aliasJson.optString(i))) { indexToSelect = i; } } diff --git a/gradle.properties b/gradle.properties index 538cf8f44..58bd09e0d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.6.1-SNAPSHOT +VERSION_NAME=1.6.3-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard diff --git a/sample/src/main/assets/json.form/single_form.json b/sample/src/main/assets/json.form/single_form.json index 3c86e1b47..9f4fa275b 100644 --- a/sample/src/main/assets/json.form/single_form.json +++ b/sample/src/main/assets/json.form/single_form.json @@ -251,10 +251,10 @@ "Ame OA", "Haja OA" ], - "alias": { - "Ame OA": "Married", - "Haja OA": "Single" - }, + "alias": [ + "Married", + "Single" + ], "v_required": { "value": "true", "err": "Please enter the sex" From 2d166f713fb5652fb02723597c087bcf5e398ff9 Mon Sep 17 00:00:00 2001 From: rkodev <43806892+rkodev@users.noreply.github.com> Date: Mon, 6 May 2019 15:40:33 +0300 Subject: [PATCH 6/6] Renamed Alias to Key. Fixed array error --- .../jsonwizard/constants/JsonFormConstants.java | 2 +- .../presenters/JsonFormFragmentPresenter.java | 10 +++++----- .../com/vijay/jsonwizard/widgets/SpinnerFactory.java | 12 ++++++------ android-json-form-wizard/src/main/res/values/ids.xml | 2 +- sample/src/main/assets/json.form/single_form.json | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java index 20eb77978..c1891119a 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java @@ -43,7 +43,7 @@ public class JsonFormConstants { public static final String BEHAVIOUR = "behaviour"; public static final String RESULT = "result"; public static final String VALUE = "value"; - public static final String ALIAS = "alias"; + public static final String KEYS = "keys"; public static final String SECOND_VALUE = "second_value"; public static final String OPENMRS_ENTITY_PARENT = "openmrs_entity_parent"; public static final String OPENMRS_ENTITY = "openmrs_entity"; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java index 046a3f35e..4a0c1b50d 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java @@ -189,7 +189,7 @@ public void addFormElements() { } - @SuppressLint ("ResourceAsColor") + @SuppressLint("ResourceAsColor") public void setUpToolBar() { getView().setActionBarTitle(mStepDetails.optString(JsonFormConstants.STEP_TITLE)); getView().setToolbarTitleColor(R.color.white); @@ -257,7 +257,7 @@ protected void launchErrorDialog() { errorFragment = new JsonFormErrorFragment(); } FragmentManager fm = ((JsonFormFragment) getView()).getChildFragmentManager(); - @SuppressLint ("CommitTransaction") FragmentTransaction ft = fm.beginTransaction(); + @SuppressLint("CommitTransaction") FragmentTransaction ft = fm.beginTransaction(); errorFragment.show(ft, JsonFormErrorFragment.TAG); } @@ -520,7 +520,7 @@ private void resetWidgetReadOnly(View view) { } } - @SuppressWarnings ({"unchecked"}) + @SuppressWarnings({"unchecked"}) private void setCheckboxesEditable(View editButton) { List checkboxLayouts = (ArrayList) editButton.getTag(R.id.editable_view); resetWidgetReadOnly(editButton); @@ -691,7 +691,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long String openMrsEntityParent = (String) parent.getTag(R.id.openmrs_entity_parent); String openMrsEntity = (String) parent.getTag(R.id.openmrs_entity); String openMrsEntityId = (String) parent.getTag(R.id.openmrs_entity_id); - JSONArray jsonArray = (JSONArray) parent.getTag(R.id.alias); + JSONArray jsonArray = (JSONArray) parent.getTag(R.id.keys); CustomTextView customTextView = (CustomTextView) parent.getTag(R.id.number_selector_textview); Boolean popup = (Boolean) parent.getTag(R.id.extraPopup); if (popup == null) { @@ -699,7 +699,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long } String value = parent.getItemAtPosition(position).toString(); - if(jsonArray != null && position >0 && jsonArray.length() > 0){ + if (jsonArray != null && position > -1 && jsonArray.length() > 0) { try { value = jsonArray.getString(position); } catch (JSONException e) { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java index 0548a98dc..c4eeb7808 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java @@ -103,10 +103,10 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay spinner.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT)); } - JSONArray aliasJson = null; - if (jsonObject.has(JsonFormConstants.ALIAS)) { - aliasJson = jsonObject.getJSONArray(JsonFormConstants.ALIAS); - spinner.setTag(R.id.alias, aliasJson); + JSONArray keysJson = null; + if (jsonObject.has(JsonFormConstants.KEYS)) { + keysJson = jsonObject.getJSONArray(JsonFormConstants.KEYS); + spinner.setTag(R.id.keys, keysJson); } setViewTags(jsonObject, canvasIds, stepName, popup, openMrsEntityParent, openMrsEntity, openMrsEntityId, spinner); @@ -137,9 +137,9 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay values = new String[valuesJson.length()]; for (int i = 0; i < valuesJson.length(); i++) { values[i] = valuesJson.optString(i); - if (aliasJson == null && valueToSelect.equals(values[i])) { + if (keysJson == null && valueToSelect.equals(values[i])) { indexToSelect = i; - } else if (aliasJson != null && valueToSelect.equals(aliasJson.optString(i))) { + } else if (keysJson != null && valueToSelect.equals(keysJson.optString(i))) { indexToSelect = i; } } diff --git a/android-json-form-wizard/src/main/res/values/ids.xml b/android-json-form-wizard/src/main/res/values/ids.xml index 7bf103d85..38f047882 100644 --- a/android-json-form-wizard/src/main/res/values/ids.xml +++ b/android-json-form-wizard/src/main/res/values/ids.xml @@ -19,7 +19,7 @@ - + diff --git a/sample/src/main/assets/json.form/single_form.json b/sample/src/main/assets/json.form/single_form.json index 9f4fa275b..f0097d60d 100644 --- a/sample/src/main/assets/json.form/single_form.json +++ b/sample/src/main/assets/json.form/single_form.json @@ -251,7 +251,7 @@ "Ame OA", "Haja OA" ], - "alias": [ + "keys": [ "Married", "Single" ],