From f78f2de3fb05ca57074435c838cf39fcf2ac5457 Mon Sep 17 00:00:00 2001 From: Kassim Sheghembe Date: Mon, 16 Jan 2023 09:28:46 +0300 Subject: [PATCH 1/3] :bug: Fix show errors of all invalid fields from all steps for multi-step form on save. --- .../presenters/JsonFormFragmentPresenter.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 2d2d569e0..6c9b894e6 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 @@ -520,11 +520,15 @@ public void validateAndWriteValues() { } //remove invalid fields not belonging to current step since formdata view are cleared when view is created - if (invalidFields != null && !invalidFields.isEmpty()) { - for (Map.Entry entry : invalidFields.entrySet()) { - String key = entry.getKey(); - if (StringUtils.isNotBlank(key) && !key.startsWith(mStepName)) { - invalidFields.remove(key); + final String nextStep = getFormFragment().getJsonApi().nextStep(); + // Check if this is the last step, then skip removing invalid fields from other steps, so that the final step has all invalid fields + if (StringUtils.isNotBlank(nextStep)) { + if (invalidFields != null && !invalidFields.isEmpty()) { + for (Map.Entry entry : invalidFields.entrySet()) { + String key = entry.getKey(); + if (StringUtils.isNotBlank(key) && !key.startsWith(mStepName)) { + invalidFields.remove(key); + } } } } From 3ee2a243687468c67bfcfe54bad3bf06d19415a4 Mon Sep 17 00:00:00 2001 From: Kassim Sheghembe Date: Tue, 24 Jan 2023 12:56:05 +0300 Subject: [PATCH 2/3] :fix: Codacy issue. --- .../presenters/JsonFormFragmentPresenter.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 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 6c9b894e6..d96f88492 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 @@ -13,6 +13,7 @@ import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; + import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.fragment.app.FragmentManager; @@ -22,6 +23,7 @@ import androidx.appcompat.widget.AppCompatRadioButton; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; + import android.text.TextUtils; import android.util.Log; import android.view.MenuItem; @@ -385,7 +387,7 @@ public boolean areFormViewsFilled() { } else if (childView instanceof MaterialEditText) { MaterialEditText editView = (MaterialEditText) childView; - boolean noValidation = (!childView.isEnabled() || !editView.hasValidators()); + boolean noValidation = (!childView.isEnabled() || !editView.hasValidators()); boolean valid = true; if (!noValidation && editView.getValidators() != null) { for (METValidator validator : editView.getValidators()) { @@ -522,13 +524,11 @@ public void validateAndWriteValues() { //remove invalid fields not belonging to current step since formdata view are cleared when view is created final String nextStep = getFormFragment().getJsonApi().nextStep(); // Check if this is the last step, then skip removing invalid fields from other steps, so that the final step has all invalid fields - if (StringUtils.isNotBlank(nextStep)) { - if (invalidFields != null && !invalidFields.isEmpty()) { - for (Map.Entry entry : invalidFields.entrySet()) { - String key = entry.getKey(); - if (StringUtils.isNotBlank(key) && !key.startsWith(mStepName)) { - invalidFields.remove(key); - } + if (StringUtils.isNotBlank(nextStep) && invalidFields != null && !invalidFields.isEmpty()) { + for (Map.Entry entry : invalidFields.entrySet()) { + String key = entry.getKey(); + if (StringUtils.isNotBlank(key) && !key.startsWith(mStepName)) { + invalidFields.remove(key); } } } @@ -539,7 +539,7 @@ public void validateAndWriteValues() { * Check if alarm is ringing and stop it if so */ public void checkAndStopCountdownAlarm() { - formFragment.getJsonApi().getAppExecutors().diskIO().execute(()->{ + formFragment.getJsonApi().getAppExecutors().diskIO().execute(() -> { try { JSONObject formJSONObject = new JSONObject(formFragment.getCurrentJsonState()); JSONArray fields = FormUtils.fields(formJSONObject, mStepName); @@ -1087,7 +1087,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { String.valueOf(compoundButton.isChecked()), openMrsEntityParent, openMrsEntity, openMrsEntityId, popup); } else if ((compoundButton instanceof AppCompatRadioButton || compoundButton instanceof RadioButton) - && isChecked) { + && isChecked) { String parentKey = (String) compoundButton.getTag(R.id.key); String openMrsEntityParent = (String) compoundButton.getTag(R.id.openmrs_entity_parent); String openMrsEntity = (String) compoundButton.getTag(R.id.openmrs_entity); @@ -1273,6 +1273,7 @@ private void addRules(JSONObject jsonObject, Set ruleFiles) { } } + public void cleanUp() { cleanupAndExit = true; mJsonFormInteractor.cleanUp(); From 2248026d262f7f8f3a1495313ba835c0f807c355 Mon Sep 17 00:00:00 2001 From: Kassim Sheghembe Date: Tue, 24 Jan 2023 14:21:07 +0300 Subject: [PATCH 3/3] Included test. --- .../java/com/vijay/jsonwizard/views/CustomTextViewTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/views/CustomTextViewTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/views/CustomTextViewTest.java index ae09ce534..5b5dc47e3 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/views/CustomTextViewTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/views/CustomTextViewTest.java @@ -47,4 +47,10 @@ public void testSetTextColor() { customTextView.setTextColor(expectedTextColor); Assert.assertEquals(expectedTextColor, customTextView.getTextColors().getDefaultColor()); } + + @Test + public void testIsHintOnText() { + boolean isHintOnText = customTextView.isHintOnText(); + Assert.assertTrue(isHintOnText); + } }