From 258ab0ca3318740269e297defdc3353715d40b10 Mon Sep 17 00:00:00 2001 From: zzainulabidin <62241922+zzainulabidin@users.noreply.github.com> Date: Fri, 3 Jul 2020 13:27:13 +0500 Subject: [PATCH 1/6] Revert "Display date format option for date picker widget" --- .../com/vijay/jsonwizard/domain/Form.java | 10 -------- .../jsonwizard/widgets/DatePickerFactory.java | 23 +++++-------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java index 563ae743d..de768dd37 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java @@ -28,8 +28,6 @@ public class Form implements Serializable { private Set disabledFields; - private static String datePickerDisplayFormat; - public String getName() { return name; } @@ -141,12 +139,4 @@ public Set getDisabledFields() { public void setDisabledFields(Set disabledFields) { this.disabledFields = disabledFields; } - - public static String getDatePickerDisplayFormat() { - return datePickerDisplayFormat; - } - - public void setDatePickerDisplayFormat(String datePickerDisplayFormat) { - Form.datePickerDisplayFormat = datePickerDisplayFormat; - } } \ No newline at end of file diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java index 1f1a1d7b1..d3e6f45c4 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java @@ -21,7 +21,6 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.customviews.DatePickerDialog; import com.vijay.jsonwizard.customviews.GenericTextWatcher; -import com.vijay.jsonwizard.domain.Form; import com.vijay.jsonwizard.fragments.JsonFormFragment; import com.vijay.jsonwizard.interfaces.CommonListener; import com.vijay.jsonwizard.interfaces.FormWidgetFactory; @@ -85,8 +84,7 @@ private static void showDatePickerDialog(Activity context, DatePickerDialog date } } - @VisibleForTesting - protected void updateDateText(Context context, MaterialEditText editText, TextView duration, String date) { + private void updateDateText(Context context, MaterialEditText editText, TextView duration, String date) { editText.setText(date); String durationLabel = (String) duration.getTag(R.id.label); if (StringUtils.isNotBlank(durationLabel)) { @@ -97,6 +95,7 @@ protected void updateDateText(Context context, MaterialEditText editText, TextVi } duration.setText(durationText); } + } @NotNull @@ -277,7 +276,8 @@ private void addRefreshLogicView(Context context, MaterialEditText editText, Str private void updateEditText(MaterialEditText editText, JSONObject jsonObject, String stepName, Context context, TextView duration) throws JSONException { - SimpleDateFormat DATE_FORMAT_LOCALE = getSimpleDateFormat(context); + Locale locale = getCurrentLocale(context); + SimpleDateFormat DATE_FORMAT_LOCALE = new SimpleDateFormat("dd-MM-yyyy", locale); String openMrsEntityParent = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_PARENT); String openMrsEntity = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY); @@ -293,7 +293,6 @@ private void updateEditText(MaterialEditText editText, JSONObject jsonObject, St editText.setTag(R.id.openmrs_entity_id, openMrsEntityId); editText.setTag(R.id.address, stepName + ":" + jsonObject.getString(KEY.KEY)); editText.setTag(R.id.locale_independent_value, jsonObject.optString(KEY.VALUE)); - if (jsonObject.has(JsonFormConstants.V_REQUIRED)) { JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_REQUIRED); boolean requiredValue = requiredObject.getBoolean(KEY.VALUE); @@ -314,16 +313,6 @@ private void updateEditText(MaterialEditText editText, JSONObject jsonObject, St } } - @VisibleForTesting - protected SimpleDateFormat getSimpleDateFormat(Context context) { - Locale locale = getCurrentLocale(context); - - return StringUtils.isNoneEmpty(Form.getDatePickerDisplayFormat()) ? - new SimpleDateFormat(Form.getDatePickerDisplayFormat(), locale) : - new SimpleDateFormat("dd-MM-yyyy", locale); - - } - @VisibleForTesting protected Locale getCurrentLocale(Context context) { return context.getResources().getConfiguration().locale.getLanguage().equals("ar") ? Locale.ENGLISH : context.getResources().getConfiguration().locale;//Arabic should render normal numbers/numeric digits @@ -334,7 +323,8 @@ protected DatePickerDialog createDateDialog(final Context context, final TextVie final DatePickerDialog datePickerDialog = new DatePickerDialog(); datePickerDialog.setContext(context); - final SimpleDateFormat DATE_FORMAT = getSimpleDateFormat(context); + Locale locale = getCurrentLocale(context); + final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy", locale); datePickerDialog.setOnDateSetListener(new android.app.DatePickerDialog.OnDateSetListener() { @Override @@ -378,7 +368,6 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth return datePickerDialog; } - protected int getLayout() { return R.layout.native_form_item_date_picker; } From b9c2f68ffa4dabac29d9db82ec84f5158caeaf18 Mon Sep 17 00:00:00 2001 From: zainulabidin Date: Fri, 3 Jul 2020 14:26:06 +0500 Subject: [PATCH 2/6] format visual date for date picker widget --- .../java/com/vijay/jsonwizard/domain/Form.java | 10 ++++++++++ .../java/com/vijay/jsonwizard/utils/Utils.java | 16 ++++++++++++++++ .../jsonwizard/widgets/DatePickerFactory.java | 12 +++++++++--- .../com/vijay/jsonwizard/utils/UtilsTest.java | 12 ++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java index de768dd37..563ae743d 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/domain/Form.java @@ -28,6 +28,8 @@ public class Form implements Serializable { private Set disabledFields; + private static String datePickerDisplayFormat; + public String getName() { return name; } @@ -139,4 +141,12 @@ public Set getDisabledFields() { public void setDisabledFields(Set disabledFields) { this.disabledFields = disabledFields; } + + public static String getDatePickerDisplayFormat() { + return datePickerDisplayFormat; + } + + public void setDatePickerDisplayFormat(String datePickerDisplayFormat) { + Form.datePickerDisplayFormat = datePickerDisplayFormat; + } } \ No newline at end of file diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/Utils.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/Utils.java index 92010334d..20240f8ac 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/Utils.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/Utils.java @@ -45,6 +45,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -775,6 +777,20 @@ public static void removeGeneratedDynamicRules(JsonFormFragment formFragment) { } } } + + + public static String formatDateToPattern(String date, String inputFormat, String outputFormat) { + if (StringUtils.isEmpty(date)) return ""; + SimpleDateFormat format = new SimpleDateFormat(inputFormat); + Date newDate = null; + try { + newDate = format.parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } + format = new SimpleDateFormat(outputFormat); + return format.format(newDate); + } } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java index d3e6f45c4..93b513141 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java @@ -21,6 +21,7 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.customviews.DatePickerDialog; import com.vijay.jsonwizard.customviews.GenericTextWatcher; +import com.vijay.jsonwizard.domain.Form; import com.vijay.jsonwizard.fragments.JsonFormFragment; import com.vijay.jsonwizard.interfaces.CommonListener; import com.vijay.jsonwizard.interfaces.FormWidgetFactory; @@ -29,6 +30,7 @@ import com.vijay.jsonwizard.utils.FormUtils; import com.vijay.jsonwizard.utils.NativeFormLangUtils; import com.vijay.jsonwizard.utils.NativeFormsProperties; +import com.vijay.jsonwizard.utils.Utils; import com.vijay.jsonwizard.validators.edittext.RequiredValidator; import org.apache.commons.lang3.StringUtils; @@ -85,7 +87,9 @@ private static void showDatePickerDialog(Activity context, DatePickerDialog date } private void updateDateText(Context context, MaterialEditText editText, TextView duration, String date) { - editText.setText(date); + editText.setText(StringUtils.isNoneBlank(Form.getDatePickerDisplayFormat()) ? + Utils.formatDateToPattern(date, DATE_FORMAT.toPattern(), Form.getDatePickerDisplayFormat()) + : date); String durationLabel = (String) duration.getTag(R.id.label); if (StringUtils.isNotBlank(durationLabel)) { Locale locale = getSetLanguage(context); @@ -95,7 +99,6 @@ private void updateDateText(Context context, MaterialEditText editText, TextView } duration.setText(durationText); } - } @NotNull @@ -277,7 +280,7 @@ private void addRefreshLogicView(Context context, MaterialEditText editText, Str private void updateEditText(MaterialEditText editText, JSONObject jsonObject, String stepName, Context context, TextView duration) throws JSONException { Locale locale = getCurrentLocale(context); - SimpleDateFormat DATE_FORMAT_LOCALE = new SimpleDateFormat("dd-MM-yyyy", locale); + final SimpleDateFormat DATE_FORMAT_LOCALE = new SimpleDateFormat("dd-MM-yyyy", locale); String openMrsEntityParent = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_PARENT); String openMrsEntity = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY); @@ -293,6 +296,7 @@ private void updateEditText(MaterialEditText editText, JSONObject jsonObject, St editText.setTag(R.id.openmrs_entity_id, openMrsEntityId); editText.setTag(R.id.address, stepName + ":" + jsonObject.getString(KEY.KEY)); editText.setTag(R.id.locale_independent_value, jsonObject.optString(KEY.VALUE)); + if (jsonObject.has(JsonFormConstants.V_REQUIRED)) { JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_REQUIRED); boolean requiredValue = requiredObject.getBoolean(KEY.VALUE); @@ -313,6 +317,7 @@ private void updateEditText(MaterialEditText editText, JSONObject jsonObject, St } } + @VisibleForTesting protected Locale getCurrentLocale(Context context) { return context.getResources().getConfiguration().locale.getLanguage().equals("ar") ? Locale.ENGLISH : context.getResources().getConfiguration().locale;//Arabic should render normal numbers/numeric digits @@ -368,6 +373,7 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth return datePickerDialog; } + protected int getLayout() { return R.layout.native_form_item_date_picker; } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/UtilsTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/UtilsTest.java index c94e8893d..dab1b9f7b 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/UtilsTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/UtilsTest.java @@ -43,6 +43,9 @@ import java.util.Map; import java.util.Set; +import static com.vijay.jsonwizard.utils.Utils.formatDateToPattern; +import static org.junit.Assert.assertEquals; + public class UtilsTest extends BaseTest { @Mock @@ -344,4 +347,13 @@ public void testRemoveGeneratedDynamicRulesShouldRemoveRules() throws JSONExcept Utils.removeGeneratedDynamicRules(jsonFormFragment); Assert.assertFalse(form.optJSONObject(JsonFormConstants.STEP1).optJSONArray(JsonFormConstants.FIELDS).optJSONObject(0).has(JsonFormConstants.RELEVANCE)); } + + @Test + public void testFormatDateToPattern() { + String date = "5/29/2020"; + String inputFormat = "dd/MM/yyyy"; + String outputFormat = "dd MMM yyyy"; + String formattedDate = formatDateToPattern(date, inputFormat, outputFormat); + assertEquals("05 May 2022", formattedDate); + } } \ No newline at end of file From 065574e647ba00c248745078429513ed19b4fe53 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 3 Jul 2020 12:51:40 +0300 Subject: [PATCH 3/6] Improve form config FormUtil methods to automatically use the bootstrapped client-form-dao --- .../com/vijay/jsonwizard/utils/FormUtils.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java index 5565078b0..81c224af0 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java @@ -32,6 +32,7 @@ import com.rey.material.util.ViewUtil; import com.vijay.jsonwizard.BuildConfig; +import com.vijay.jsonwizard.NativeFormLibrary; import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.customviews.ExpansionPanelGenericPopupDialog; @@ -1782,11 +1783,24 @@ public String setValues(JSONArray jsonArray, String type) { return value.replaceAll(", $", ""); } + + @Nullable + public JSONObject getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull String formIdentity) { + ClientFormContract.Dao clientFormRepository = NativeFormLibrary.getInstance().getClientFormDao(); + return getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, null); + } + @Nullable public JSONObject getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity) { return getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, null); } + + public void getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull String formIdentity, @Nullable OnFormFetchedCallback onFormFetchedCallback) { + ClientFormContract.Dao clientFormRepository = NativeFormLibrary.getInstance().getClientFormDao(); + getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, onFormFetchedCallback); + } + public void getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity, @Nullable OnFormFetchedCallback onFormFetchedCallback) { getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, onFormFetchedCallback); } @@ -1829,7 +1843,7 @@ public void onFormFetched(@Nullable String form) { } Timber.d("============%s form loaded from Assets=============", formIdentity); - JSONObject jsonObject = getFormJson(context, clientFormRepository, formIdentity); + JSONObject jsonObject = getFormJson(context, formIdentity); if (onFormFetchedCallback != null) { onFormFetchedCallback.onFormFetched(jsonObject); @@ -1839,7 +1853,7 @@ public void onFormFetched(@Nullable String form) { } } - public JSONObject getFormJson(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, String formIdentity) { + public JSONObject getFormJson(@NonNull Context context, String formIdentity) { if (context != null) { try { String locale = context.getResources().getConfiguration().locale.getLanguage(); @@ -1889,6 +1903,11 @@ private ClientFormContract.Model getClientFormFromRepository(@NonNull Context c return clientForm; } + public void handleJsonFormOrRulesError(@NonNull Context context, @NonNull String formIdentity, @NonNull OnFormFetchedCallback onFormFetchedCallback) { + ClientFormContract.Dao clientFormRepository = NativeFormLibrary.getInstance().getClientFormDao(); + handleJsonFormOrRulesError(context, clientFormRepository, false, formIdentity, onFormFetchedCallback); + } + public void handleJsonFormOrRulesError(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity, @NonNull OnFormFetchedCallback onFormFetchedCallback) { handleJsonFormOrRulesError(context, clientFormRepository, false, formIdentity, onFormFetchedCallback); } @@ -1917,7 +1936,7 @@ public void onFormSelected(@NonNull ClientFormContract.Model selectedForm) { Timber.e(e); } } else { - JSONObject jsonObject = getFormJson(context, clientFormRepository, formIdentity); + JSONObject jsonObject = getFormJson(context, formIdentity); if (jsonObject != null) { clientForm.setJson(jsonObject.toString()); From ba4245c3926ac9ef05622cb5020d8e0c16539bd5 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 3 Jul 2020 12:52:02 +0300 Subject: [PATCH 4/6] :arrow-up: Increment version to 1.12.1-SNAPSHOT --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 236db2e40..d48c44001 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.12.0-SNAPSHOT +VERSION_NAME=1.12.1-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard From 29d4acd90463e3454dc89987347fa61a5551d503 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Fri, 3 Jul 2020 16:21:02 +0300 Subject: [PATCH 5/6] Add tests for FormUtils.getFormJson --- .../assets/json.form/test_basic_form.json | 553 ++++++++++++++++++ .../vijay/jsonwizard/utils/FormUtilsTest.java | 5 + 2 files changed, 558 insertions(+) create mode 100644 android-json-form-wizard/src/test/assets/json.form/test_basic_form.json diff --git a/android-json-form-wizard/src/test/assets/json.form/test_basic_form.json b/android-json-form-wizard/src/test/assets/json.form/test_basic_form.json new file mode 100644 index 000000000..f1ad04050 --- /dev/null +++ b/android-json-form-wizard/src/test/assets/json.form/test_basic_form.json @@ -0,0 +1,553 @@ +{ + "count": "3", + "encounter_type": "Test", + "entity_id": "", + "relational_id": "", + "validate_on_submit": true, + "show_errors_on_submit": true, + "metadata": { + "start": { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_data_type": "start", + "openmrs_entity_id": "163137AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "end": { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_data_type": "end", + "openmrs_entity_id": "163138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "today": { + "openmrs_entity_parent": "", + "openmrs_entity": "encounter", + "openmrs_entity_id": "encounter_date" + }, + "deviceid": { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_data_type": "deviceid", + "openmrs_entity_id": "163149AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "subscriberid": { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_data_type": "subscriberid", + "openmrs_entity_id": "163150AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "simserial": { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_data_type": "simserial", + "openmrs_entity_id": "163151AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "phonenumber": { + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_data_type": "phonenumber", + "openmrs_entity_id": "163152AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "encounter_location": "", + "look_up": { + "entity_id": "", + "value": "" + } + }, + "step1": { + "title": "Basic Form One", + "next": "step2", + "fields": [ + { + "key": "user_image", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "choose_image", + "uploadButtonText": "Take a photo of the child" + }, + { + "key": "finger_print", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "finger_print", + "project_id": "tZqJnw0ajK04LMYdZzyw", + "user_id": "test_user", + "module_id": "mpower", + "finger_print_option": "register", + "uploadButtonText": "Take finger print", + "image_file": "", + "relevance": { + "step1:user_first_name": { + "type": "string", + "ex": "equalTo(., \"test\")" + } + } + }, + { + "key": "finger_print", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "finger_print", + "project_id": "tZqJnw0ajK04LMYdZzyw", + "user_id": "test_user", + "module_id": "mpower", + "gu_id": "id", + "finger_print_option": "verify", + "uploadButtonText": "Verify finger print", + "image_file": "" + }, + { + "key": "user_first_name", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "edit_text", + "hint": "User First name", + "edit_type": "name", + "v_required": { + "value": "true", + "err": "Please enter the first name" + }, + "v_regex": { + "value": "[A-Za-z\\s\\.\\-]*", + "err": "Please enter a valid name" + } + }, + { + "key": "user_last_name", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "edit_text", + "hint": "User Last name", + "edit_type": "name", + "v_required": { + "value": "true", + "err": "Please enter the last name" + }, + "v_regex": { + "value": "[A-Za-z\\s\\.\\-]*", + "err": "Please enter a valid name" + }, + "relevance": { + "step1:user_first_name": { + "type": "string", + "ex": "equalTo(., \"test\")" + } + } + }, + { + "key": "user_qr_code", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "barcode", + "barcode_type": "qrcode", + "hint": "User ID", + "scanButtonText": "Scan QR Code", + "v_numeric": { + "value": "true", + "err": "Please enter a valid ID" + }, + "v_required": { + "value": false, + "err": "Please enter the user ID" + } + }, + { + "key": "user_age", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "edit_text", + "hint": "User age", + "edit_type": "name", + "v_required": { + "value": "true", + "err": "Please enter the last name" + }, + "v_regex": { + "value": "[A-Za-z\\s\\.\\-]*", + "err": "Please enter a valid name" + } + }, + { + "key": "user_gps", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "openmrs_data_type": "text", + "type": "gps" + }, + { + "key": "user_calculation_one", + "openmrs_entity_parent": "", + "openmrs_entity": "concept", + "openmrs_entity_id": "165260AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "type": "hidden" + } + ] + }, + "step2": { + "title": "Basic Form Two", + "next": "step3", + "fields": [ + { + "key": "user_select", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "native_radio", + "label": "Do you want to select anything", + "label_text_style": "bold", + "text_color": "#000000", + "label_info_text": "You can select every thing you want.", + "label_info_title": "User selection", + "options": [ + { + "key": "yes", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "text": "Yes" + }, + { + "key": "no", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "text": "No" + } + ] + }, + { + "key": "user_normal_edit_text", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "normal_edit_text", + "hint": "User Text ", + "edit_text_style": "bordered", + "v_required": { + "value": true, + "err": "Please enter the user ID" + } + }, + { + "key": "user_normal_edit_number", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "normal_edit_text", + "hint": "User number", + "edit_text_style": "bordered", + "edit_type": "number", + "v_required": { + "value": true, + "err": "Please enter the user ID" + } + }, + { + "key": "user_toaster_problem", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "User problem toaster", + "toaster_info_text": "Procedure:\n- This shows the user the problems.\n- Problem toaster.", + "toaster_type": "problem" + }, + { + "key": "user_toaster_warning", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "User warning toaster", + "toaster_info_text": "Procedure:\n- This shows the user the warning.\n- Warning toaster.", + "toaster_type": "warning" + }, + { + "key": "user_toaster_positive", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "User positive toaster", + "toaster_info_text": "Procedure:\n- This shows the user the positive.\n- Positive toaster.", + "toaster_type": "positive" + }, + { + "key": "user_toaster_info", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "toaster_notes", + "text": "User Info toaster", + "toaster_info_text": "Procedure:\n- This shows the user the info.\n- Info toaster.", + "toaster_type": "info" + } + ] + }, + "step3": { + "title": "Basic Form Threes", + "fields": [ + { + "key": "user_date", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "date_picker", + "hint": "User DOB", + "expanded": false, + "duration": { + "label": "Age" + }, + "default": "12-12-2015", + "min_date": "today-5y", + "max_date": "today", + "v_required": { + "value": "true", + "err": "Please enter the date of birth" + } + }, + { + "key": "user_time", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "time_picker", + "hint": "Birth Time", + "expanded": false, + "duration": { + "label": "Birth Time" + }, + "v_required": { + "value": true, + "err": "Please enter the time of birth" + } + }, + { + "key": "user_spinner", + "openmrs_entity": "openmrs_entity", + "openmrs_entity_id": "openmrs_entity_id", + "openmrs_entity_parent": "openmrs_entity_parent", + "type": "spinner", + "hint": "User Spinners", + "values": [ + "User Option One", + "User Option Two" + ], + "keys": [ + "user_option_one", + "user_option_two" + ], + "v_required": { + "value": "true", + "err": "Please enter the sex" + }, + "openmrs_choice_ids": { + "user_one": "1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "user_two": "1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "value": "user_one" + }, + { + "key": "response_spinner_with_options", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "spinner", + "hint": "Response Spinners", + "options": [ + { + "key": "yes", + "text": "Yes", + "openmrs_entity": "", + "openmrs_entity_id": "", + "openmrs_entity_parent": "" + }, + { + "key": "no", + "text": "No", + "openmrs_entity": "openmrs_entity", + "openmrs_entity_id": "openmrs_entity_id", + "openmrs_entity_parent": "openmrs_entity_parent" + }, + { + "key": "maybe", + "text": "Maybe", + "openmrs_entity": "openmrs_entity_2", + "openmrs_entity_id": "openmrs_entity_id_2", + "openmrs_entity_parent": "openmrs_entity_parent_2" + } + ], + "value": "maybe", + "v_required": { + "value": "true", + "err": "Please enter response" + } + }, + { + "key": "response_spinner_with_options", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "spinner", + "hint": "Response Spinners", + "options": [ + { + "key": "yes", + "text": "Yes", + "value": false, + "openmrs_entity": "", + "openmrs_entity_id": "" + }, + { + "key": "no", + "text": "No", + "value": false, + "openmrs_entity": "", + "openmrs_entity_id": "" + }, + { + "key": "maybe", + "text": "Maybe", + "value": false, + "openmrs_entity": "", + "openmrs_entity_id": "" + } + ], + "v_required": { + "value": "true", + "err": "Please enter response" + }, + "openmrs_choice_ids": { + "user_one": "1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "user_two": "1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + } + }, + { + "key": "spacer", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "spacer", + "type": "spacer", + "spacer_height": "20dp" + }, + { + "key": "user_form_labels", + "type": "label", + "label_text_style": "bold", + "text": "Number of labels", + "text_color": "#000000", + "v_required": { + "value": true + } + }, + { + "key": "user_form", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "numbers_selector", + "number_of_selectors": "5", + "start_number": "1", + "max_value": "15", + "text_size": "16px", + "text_color": "#000000", + "selected_text_color": "#ffffff", + "v_required": { + "value": true + } + }, + { + "key": "spacer", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "spacer", + "type": "spacer", + "spacer_height": "20dp" + }, + { + "key": "user_sub_form", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "type": "native_radio", + "label": "User sub forms?", + "label_text_style": "bold", + "text_color": "#000000", + "extra_rel": true, + "has_extra_rel": "yes", + "options": [ + { + "key": "yes", + "text": "Yes", + "value": false, + "openmrs_entity": "", + "openmrs_entity_id": "", + "specify_info": "User sub specify...", + "specify_widget": "normal_edit_text", + "specify_info_color": "#8C8C8C", + "secondary_suffix": "bpm", + "content_form": "user_native_sub_form" + }, + { + "key": "no", + "text": "No", + "value": false, + "openmrs_entity": "", + "openmrs_entity_id": "" + } + ], + "v_required": { + "value": true, + "err": "Please specify user native form." + } + }, + { + "key": "user_check_box", + "openmrs_entity_parent": "", + "openmrs_entity": "", + "openmrs_entity_id": "", + "openmrs_data_type": "select one", + "type": "check_box", + "label": "Do want to select any checkbox?", + "label_text_style": "bold", + "options": [ + { + "key": "None", + "text": "None", + "value": false, + "openmrs_choice_id": "" + }, + { + "key": "yes", + "text": "Yes", + "value": false, + "openmrs_choice_id": "" + }, + { + "key": "no", + "text": "No", + "value": false, + "openmrs_choice_id": "" + }, + { + "key": "other", + "text": "Other", + "value": false, + "openmrs_choice_id": "" + } + ], + "v_required": { + "value": "false" + }, + "value": "[yes]" + } + ] + } +} \ No newline at end of file diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java index cb60dc614..aa0c7047e 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/utils/FormUtilsTest.java @@ -437,4 +437,9 @@ public void isFormNewShouldReturnTrueWhenJSONObjectIsNewPropertyIsTrue() throws jsonObject.put(JsonFormConstants.Properties.IS_NEW, true); Assert.assertTrue(FormUtils.isFormNew(jsonObject)); } + + @Test + public void getFormJsonShouldReturnCorrectFormWithSameLength() { + Assert.assertEquals(10011, formUtils.getFormJson(RuntimeEnvironment.application, "test_basic_form").toString().length()); + } } From 01e76ff74e2507c34e47ef639469d296f21b175f Mon Sep 17 00:00:00 2001 From: zainulabidin Date: Sun, 5 Jul 2020 19:20:48 +0500 Subject: [PATCH 6/6] Fix bug for age calculation --- .../java/com/vijay/jsonwizard/widgets/DatePickerFactory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java index 93b513141..79ccabade 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/DatePickerFactory.java @@ -73,7 +73,9 @@ private static void showDatePickerDialog(Activity context, DatePickerDialog date context.getFragmentManager().executePendingTransactions(); String text = editText.getText().toString(); - Calendar date = FormUtils.getDate(text); + Calendar date = FormUtils.getDate(StringUtils.isNoneBlank(Form.getDatePickerDisplayFormat()) ? + Utils.formatDateToPattern(text, Form.getDatePickerDisplayFormat(), DATE_FORMAT.toPattern()) + : text); if (text.isEmpty()) { Object defaultValue = datePickerDialog.getArguments().get(JsonFormConstants.DEFAULT); if (defaultValue != null)