From feab3cfc60c7d65daeb1a35f6b230eda92daee71 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 24 Aug 2022 17:32:28 +0300 Subject: [PATCH 01/14] Merging on number selector --- .../task/MultiSelectListLoadTask.java | 88 +++++++++---------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java index 1fe2a0c28..e7b2e45e6 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java @@ -35,62 +35,56 @@ public MultiSelectListLoadTask(final MultiSelectListFactory multiSelectListFacto this.currentAdapterKey = multiSelectListFactory.currentAdapterKey; appExecutors = multiSelectListFactory.getJsonFormFragment().getJsonApi().getAppExecutors(); - appExecutors.mainThread().execute(new Runnable() { - @Override - public void run() { - progressBar = new ProgressDialog(multiSelectListFactory.getContext()); - progressBar.setMessage(multiSelectListFactory.getContext().getString(R.string.loading_multi_select_list)); - progressBar.show(); - } + appExecutors.mainThread().execute(() -> { + progressBar = new ProgressDialog(multiSelectListFactory.getContext()); + progressBar.setMessage(multiSelectListFactory.getContext().getString(R.string.loading_multi_select_list)); + progressBar.show(); }); init(); } private void init() { - appExecutors.diskIO().execute(new Runnable() { - @Override - public void run() { - String source = jsonObject.optString(JsonFormConstants.MultiSelectUtils.SOURCE); - final List multiSelectItems = multiSelectListFactory.loadListItems(source); - if (multiSelectItems == null) { - return; - } - String strGroupingsArray = jsonObject.optString(JsonFormConstants.MultiSelectUtils.GROUPINGS); - boolean sort = jsonObject.optBoolean(JsonFormConstants.MultiSelectUtils.SORT); + appExecutors.diskIO().execute(() -> { + String source = jsonObject.optString(JsonFormConstants.MultiSelectUtils.SOURCE); + final List multiSelectItems = multiSelectListFactory.loadListItems(source); + if (multiSelectItems == null) { + return; + } + String strGroupingsArray = jsonObject.optString(JsonFormConstants.MultiSelectUtils.GROUPINGS); + boolean sort = jsonObject.optBoolean(JsonFormConstants.MultiSelectUtils.SORT); - if (!StringUtils.isBlank(strGroupingsArray) && sort) {//no grouping without sorting - JSONArray jsonArray = null; - try { - jsonArray = new JSONArray(strGroupingsArray); - } catch (JSONException e) { - Timber.e(e); - } - MultiSelectListUtils.addGroupings(multiSelectItems, jsonArray); + if (!StringUtils.isBlank(strGroupingsArray) && sort) {//no grouping without sorting + JSONArray jsonArray = null; + try { + jsonArray = new JSONArray(strGroupingsArray); + } catch (JSONException e) { + Timber.e(e); + } + MultiSelectListUtils.addGroupings(multiSelectItems, jsonArray); + } + if (sort) { + String sortClass = jsonObject.optString(JsonFormConstants.MultiSelectUtils.SORTING_CLASS); + if (StringUtils.isBlank(sortClass)) { + sortClass = JsonFormConstants.MultiSelectUtils.ALPHABET_SORTING; } - if (sort) { - String sortClass = jsonObject.optString(JsonFormConstants.MultiSelectUtils.SORTING_CLASS); - if (StringUtils.isBlank(sortClass)) { - sortClass = JsonFormConstants.MultiSelectUtils.ALPHABET_SORTING; - } - try { - Class aClass = Class.forName(sortClass); - Collections.sort(multiSelectItems, (Comparator) aClass.newInstance()); - } catch (IllegalAccessException e) { - Timber.e(e); - } catch (InstantiationException e) { - Timber.e(e); - } catch (ClassNotFoundException e) { - Timber.e(e); - } + try { + Class aClass = Class.forName(sortClass); + Collections.sort(multiSelectItems, (Comparator) aClass.newInstance()); + } catch (IllegalAccessException e) { + Timber.e(e); + } catch (InstantiationException e) { + Timber.e(e); + } catch (ClassNotFoundException e) { + Timber.e(e); } - - appExecutors.mainThread().execute(new Runnable() { - @Override - public void run() { - onPostExecute(multiSelectItems); - } - }); } + + appExecutors.mainThread().execute(new Runnable() { + @Override + public void run() { + onPostExecute(multiSelectItems); + } + }); }); } From 6938f8380e96a4bc2d067478f48291f7a4b76a2f Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Thu, 25 Aug 2022 12:38:22 +0300 Subject: [PATCH 02/14] Async Tasks refactoring --- .../customviews/GenericPopupDialog.java | 76 +++++++++---------- .../fragments/JsonWizardFormFragment.java | 9 ++- ...pansionPanelRecordButtonClickListener.java | 2 +- .../presenters/JsonFormFragmentPresenter.java | 2 +- .../task/AttachRepeatingGroupTask.java | 61 +++++++-------- .../ExpansionPanelGenericPopupDialogTask.java | 16 ++-- .../task/MultiSelectListLoadTask.java | 7 +- .../task/NextProgressDialogTask.java | 28 +++---- .../jsonwizard/widgets/BarcodeFactory.java | 19 ++--- .../widgets/RepeatingGroupFactory.java | 2 +- 10 files changed, 103 insertions(+), 119 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java index 750046a3d..4d52ce705 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java @@ -89,51 +89,49 @@ public void onActivityCreated(Bundle savedInstanceState) { "The Context is not set. Did you forget to set context with Generic Dialog setContext method?"); } - getJsonApi().getAppExecutors().diskIO().execute(new Runnable() { - @Override - public void run() { + getJsonApi().getAppExecutors().diskIO().execute(() -> { + getJsonApi().getAppExecutors().mainThread.execute(()->{}); - if (isDetached()) { - return; - } - // support translation of sub-forms - // support translation of sub-forms - Intent activityIntent = getActivity().getIntent(); - translateSubForm = activityIntent != null && activityIntent.hasExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION) ? - activityIntent.getBooleanExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, false) : - NativeFormLibrary.getInstance().isPerformFormTranslation(); + if (isDetached()) { + return; + } + // support translation of sub-forms + // support translation of sub-forms + Intent activityIntent = getActivity().getIntent(); + translateSubForm = activityIntent != null && activityIntent.hasExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION) ? + activityIntent.getBooleanExtra(JsonFormConstants.PERFORM_FORM_TRANSLATION, false) : + NativeFormLibrary.getInstance().isPerformFormTranslation(); - try { - setMainFormFields(formUtils.getFormFields(getStepName(), context)); - loadPartialSecondaryValues(); - createSecondaryValuesMap(); + try { + setMainFormFields(formUtils.getFormFields(getStepName(), context)); + loadPartialSecondaryValues(); + createSecondaryValuesMap(); - loadSubForms(); + loadSubForms(); - getJsonApi().updateGenericPopupSecondaryValues(specifyContent, stepName); - } catch (JSONException e) { - Timber.e(e, " --> onCreate"); - } + getJsonApi().updateGenericPopupSecondaryValues(specifyContent, stepName); + } catch (JSONException e) { + Timber.e(e, " --> onCreate"); + } - final List views = initiateViews(); - if (isDetached()) { - return; - } - getJsonApi().initializeDependencyMaps(); - getJsonApi().getAppExecutors().mainThread().execute(new Runnable() { - @Override - public void run() { - if (isDetached()) { - return; - } - setViewList(views); - getJsonApi().invokeRefreshLogic(null, true, null, null, getStepName(), false); - if (getDialogView() != null) { - addWidgetViews(getDialogView()); - } - } - }); + final List views = initiateViews(); + if (isDetached()) { + return; } + getJsonApi().initializeDependencyMaps(); + getJsonApi().getAppExecutors().mainThread().execute(new Runnable() { + @Override + public void run() { + if (isDetached()) { + return; + } + setViewList(views); + getJsonApi().invokeRefreshLogic(null, true, null, null, getStepName(), false); + if (getDialogView() != null) { + addWidgetViews(getDialogView()); + } + } + }); }); } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/fragments/JsonWizardFormFragment.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/fragments/JsonWizardFormFragment.java index eedc12321..474b7c72e 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/fragments/JsonWizardFormFragment.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/fragments/JsonWizardFormFragment.java @@ -3,8 +3,6 @@ import android.content.res.Resources; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; @@ -17,6 +15,9 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; + import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.activities.JsonFormActivity; import com.vijay.jsonwizard.constants.JsonFormConstants; @@ -286,11 +287,11 @@ public void onClick(View view) { getJsonApi().setPreviousPressed(false); Object nextStateTag = view.getTag(R.id.NEXT_STATE); if (nextStateTag == null) { - new NextProgressDialogTask(getJsonFormFragment()).execute(); + new NextProgressDialogTask(getJsonFormFragment()).init(); } else { boolean next = (boolean) nextStateTag; if (next) { - new NextProgressDialogTask(getJsonFormFragment()).execute(); + new NextProgressDialogTask(getJsonFormFragment()).init(); } else { save(); } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/listeners/ExpansionPanelRecordButtonClickListener.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/listeners/ExpansionPanelRecordButtonClickListener.java index 6cab6cff7..7ebbf51af 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/listeners/ExpansionPanelRecordButtonClickListener.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/listeners/ExpansionPanelRecordButtonClickListener.java @@ -43,7 +43,7 @@ public void onClick(View view) { } protected void initiateTask(View view) { - new ExpansionPanelGenericPopupDialogTask(view).execute(); + new ExpansionPanelGenericPopupDialogTask(view).init(); } /** 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 0c84c04dd..1c6899598 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 @@ -845,7 +845,7 @@ protected void nativeRadioButtonClickActions(View view) { .equals(JsonFormConstants.DATE_PICKER)) { NativeRadioButtonFactory.showDateDialog(view); } else if (JsonFormConstants.CONTENT_INFO.equals(type) && !specifyWidget.equals(JsonFormConstants.DATE_PICKER)) { - new ExpansionPanelGenericPopupDialogTask(view).execute(); + new ExpansionPanelGenericPopupDialogTask(view).init(); } else if (view.getId() == R.id.label_edit_button) { setRadioViewsEditable(view); } else { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java index 3b8abeb47..747d960ec 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java @@ -1,8 +1,19 @@ package com.vijay.jsonwizard.task; +import static com.vijay.jsonwizard.constants.JsonFormConstants.CALCULATION; +import static com.vijay.jsonwizard.constants.JsonFormConstants.FIELDS; +import static com.vijay.jsonwizard.constants.JsonFormConstants.KEY; +import static com.vijay.jsonwizard.constants.JsonFormConstants.RELEVANCE; +import static com.vijay.jsonwizard.constants.JsonFormConstants.STEPNAME; +import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP_TITLE; +import static com.vijay.jsonwizard.constants.JsonFormConstants.TYPE; +import static com.vijay.jsonwizard.constants.JsonFormConstants.VALUE; +import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MAX; +import static com.vijay.jsonwizard.utils.Utils.hideProgressDialog; +import static com.vijay.jsonwizard.utils.Utils.showProgressDialog; + import android.content.Context; import android.graphics.Typeface; -import android.os.AsyncTask; import android.text.SpannableString; import android.text.style.StyleSpan; import android.view.View; @@ -20,6 +31,7 @@ import com.vijay.jsonwizard.fragments.JsonFormFragment; import com.vijay.jsonwizard.interfaces.FormWidgetFactory; import com.vijay.jsonwizard.interfaces.JsonApi; +import com.vijay.jsonwizard.utils.AppExecutors; import com.vijay.jsonwizard.utils.Utils; import com.vijay.jsonwizard.utils.ValidationStatus; @@ -38,19 +50,7 @@ import timber.log.Timber; -import static com.vijay.jsonwizard.constants.JsonFormConstants.CALCULATION; -import static com.vijay.jsonwizard.constants.JsonFormConstants.FIELDS; -import static com.vijay.jsonwizard.constants.JsonFormConstants.KEY; -import static com.vijay.jsonwizard.constants.JsonFormConstants.RELEVANCE; -import static com.vijay.jsonwizard.constants.JsonFormConstants.STEPNAME; -import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP_TITLE; -import static com.vijay.jsonwizard.constants.JsonFormConstants.TYPE; -import static com.vijay.jsonwizard.constants.JsonFormConstants.VALUE; -import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MAX; -import static com.vijay.jsonwizard.utils.Utils.hideProgressDialog; -import static com.vijay.jsonwizard.utils.Utils.showProgressDialog; - -public class AttachRepeatingGroupTask extends AsyncTask> { +public class AttachRepeatingGroupTask { protected final int REPEATING_GROUP_LABEL_TEXT_COLOR = R.color.black; private final ViewParent parent; @@ -64,6 +64,7 @@ public class AttachRepeatingGroupTask extends AsyncTask> private Map>> rulesFileMap = new HashMap<>(); private Map repeatingGroupLayouts; private int currNumRepeatingGroups; + private final AppExecutors appExecutors; public AttachRepeatingGroupTask(final ViewParent parent, int numRepeatingGroups, Map repeatingGroupLayouts, WidgetArgs widgetArgs, ImageButton doneButton) { this.rootLayout = (LinearLayout) parent; @@ -73,28 +74,34 @@ public AttachRepeatingGroupTask(final ViewParent parent, int numRepeatingGroups, this.doneButton = doneButton; this.repeatingGroupLayouts = repeatingGroupLayouts; currNumRepeatingGroups = ((ViewGroup) parent).getChildCount() - 1; + appExecutors = widgetArgs.getFormFragment().getJsonApi().getAppExecutors(); + } + + public void init() { + appExecutors.mainThread().execute(this::onPreExecute); + appExecutors.diskIO().execute(() -> { + this.updateRepeatInBackground(); + appExecutors.mainThread().execute(this::onPostExecute); + }); + appExecutors.mainThread().execute(this::onCancelled); + } - @Override + protected void onPreExecute() { showProgressDialog(R.string.please_wait_title, R.string.creating_repeating_group_message, widgetArgs.getFormFragment().getContext()); } - @Override - protected List doInBackground(Void... voids) { + protected List updateRepeatInBackground() { diff = numRepeatingGroups - currNumRepeatingGroups; for (int i = 0; i < diff; i++) { try { - repeatingGroups.add(buildRepeatingGroupLayout(parent)); - } catch (Exception e) { Timber.e(e); } } - updateRepeatingGrpCountObject(); - return repeatingGroups; } @@ -109,11 +116,9 @@ private void updateRepeatingGrpCountObject() { } } - @Override - protected void onPostExecute(List result) { + protected void onPostExecute() { if (diff < 0) { try { - JSONObject step = ((JsonApi) widgetArgs.getContext()).getmJSONObject().getJSONObject(widgetArgs.getStepName()); JSONArray fields = step.getJSONArray(FIELDS); int currNumRepeatingGroups = rootLayout.getChildCount() - 1; @@ -165,18 +170,15 @@ protected void onPostExecute(List result) { hideProgressDialog(); doneButton.setImageResource(R.drawable.ic_done_green); - //for validation validationCleanUp(); } private void validationCleanUp() { doneButton.setTag(R.id.is_repeating_group_generated, true); - LinearLayout referenceLayout = (LinearLayout) ((LinearLayout) parent).getChildAt(0); MaterialEditText materialEditText = (MaterialEditText) referenceLayout.getChildAt(0); materialEditText.setError(null); - Map validationStatusMap = widgetArgs.getFormFragment().getJsonApi().getInvalidFields(); if (validationStatusMap != null) { String fieldKey = Utils.getFieldKeyPrefix(widgetArgs.getStepName(), widgetArgs.getFormFragment().getPresenter().getStepTitle()) + JsonFormConstants.REFERENCE_EDIT_TEXT; @@ -186,20 +188,16 @@ private void validationCleanUp() { private LinearLayout buildRepeatingGroupLayout(final ViewParent parent) throws Exception { Context context = widgetArgs.getContext(); - LinearLayout repeatingGroup = new LinearLayout(context); repeatingGroup.setLayoutParams(WIDTH_MATCH_PARENT_HEIGHT_WRAP_CONTENT); repeatingGroup.setOrientation(LinearLayout.VERTICAL); - LinearLayout rootLayout = (LinearLayout) ((LinearLayout) parent).getChildAt(0); EditText referenceEditText = (EditText) rootLayout.getChildAt(0); TextView repeatingGroupLabel = new TextView(context); if (widgetArgs.getJsonObject().optBoolean(JsonFormConstants.RepeatingGroupFactory.SHOW_GROUP_LABEL, true)) { formatRepeatingGroupLabelText(referenceEditText, repeatingGroupLabel, context); } - repeatingGroup.addView(repeatingGroupLabel); - JSONArray repeatingGroupJson = new JSONArray(repeatingGroupLayouts.get(((LinearLayout) parent).getId())); String groupUniqueId = UUID.randomUUID().toString().replace("-", ""); for (int i = 0; i < repeatingGroupJson.length(); i++) { @@ -255,7 +253,6 @@ protected void addUniqueIdentifiers(JSONObject element, String uniqueId) throws } } - @Override protected void onCancelled() { hideProgressDialog(); } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java index 9c833afe3..eba1c520e 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java @@ -13,6 +13,7 @@ import com.vijay.jsonwizard.customviews.ExpansionPanelGenericPopupDialog; import com.vijay.jsonwizard.fragments.JsonFormFragment; import com.vijay.jsonwizard.interfaces.CommonListener; +import com.vijay.jsonwizard.utils.AppExecutors; import com.vijay.jsonwizard.utils.FormUtils; import com.vijay.jsonwizard.utils.Utils; import com.vijay.jsonwizard.views.CustomTextView; @@ -24,25 +25,29 @@ /** * The {@link AsyncTask} to start and set the required variables on the {@link ExpansionPanelGenericPopupDialog} */ -public class ExpansionPanelGenericPopupDialogTask extends AsyncTask { +public class ExpansionPanelGenericPopupDialogTask { private FormUtils formUtils = new FormUtils(); private Utils utils = new Utils(); private View view; + private AppExecutors appExecutors; public ExpansionPanelGenericPopupDialogTask(View view) { this.view = view; + } - @Override + public void init(){ + appExecutors=new JsonFormFragment().getJsonApi().getAppExecutors(); + appExecutors.mainThread().execute(this::onPreExecute); + appExecutors.diskIO().execute(this::processViewOnBackground); + } protected void onPreExecute() { - super.onPreExecute(); Context context = (Context) view.getTag(R.id.specify_context); Utils.showProgressDialog(R.string.loading, R.string.loading_form_message, context); } - @Override - protected Void doInBackground(Void... voids) { + protected void processViewOnBackground(Void... voids) { Context context = (Context) view.getTag(R.id.specify_context); String specifyContent = (String) view.getTag(R.id.specify_content); String specifyContentForm = (String) view.getTag(R.id.specify_content_form); @@ -88,6 +93,5 @@ protected Void doInBackground(Void... voids) { Toast.makeText(context, "Please specify the sub form to display ", Toast.LENGTH_LONG).show(); Timber.e("No sub form specified. Please specify one in order to use the expansion panel."); } - return null; } } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java index e7b2e45e6..c9429830c 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/MultiSelectListLoadTask.java @@ -79,12 +79,7 @@ private void init() { } } - appExecutors.mainThread().execute(new Runnable() { - @Override - public void run() { - onPostExecute(multiSelectItems); - } - }); + appExecutors.mainThread().execute(() -> onPostExecute(multiSelectItems)); }); } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/NextProgressDialogTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/NextProgressDialogTask.java index 76b4e18e7..477c5c212 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/NextProgressDialogTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/NextProgressDialogTask.java @@ -2,14 +2,15 @@ import android.app.ProgressDialog; import android.content.Context; -import android.os.AsyncTask; import com.vijay.jsonwizard.fragments.JsonWizardFormFragment; +import com.vijay.jsonwizard.utils.AppExecutors; -public class NextProgressDialogTask extends AsyncTask { +public class NextProgressDialogTask { private JsonWizardFormFragment formFragment; private Context context; private ProgressDialog progressDialog; + private AppExecutors appExecutors; private void showDialog() { setProgressDialog(new ProgressDialog(getContext())); @@ -32,22 +33,13 @@ public NextProgressDialogTask(JsonWizardFormFragment jsonFormFragment) { } } - @Override - protected Void doInBackground(Void... voids) { - getFormFragment().next(); - return null; - } - - @Override - protected void onPreExecute() { - super.onPreExecute(); - showDialog(); - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - hideDialog(); + public void init() { + appExecutors = getFormFragment().getJsonApi().getAppExecutors(); + appExecutors.mainThread().execute(this::showDialog); + appExecutors.diskIO().execute(() -> { + getFormFragment().next(); + appExecutors.mainThread().execute(this::hideDialog); + }); } public JsonWizardFormFragment getFormFragment() { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BarcodeFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BarcodeFactory.java index d297cc096..eeab9a1b4 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BarcodeFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BarcodeFactory.java @@ -72,17 +72,14 @@ public List getViewsFromJson(final String stepName, final Context context, List views = new ArrayList<>(1); final RelativeLayout rootLayout = getRootLayout(context); final int canvasId = ViewUtil.generateViewId(); - formFragment.getJsonApi().getAppExecutors().mainThread().execute(new Runnable() { - @Override - public void run() { - try { - rootLayout.setId(canvasId); - final MaterialEditText editText = createEditText(rootLayout, jsonObject, canvasId, stepName, popup); - attachJson(rootLayout, stepName, context, formFragment, jsonObject, editText); - ((JsonApi) context).addFormDataView(editText); - } catch (JSONException e) { - Timber.e(e); - } + formFragment.getJsonApi().getAppExecutors().mainThread().execute(() -> { + try { + rootLayout.setId(canvasId); + final MaterialEditText editText = createEditText(rootLayout, jsonObject, canvasId, stepName, popup); + attachJson(rootLayout, stepName, context, formFragment, jsonObject, editText); + ((JsonApi) context).addFormDataView(editText); + } catch (JSONException e) { + Timber.e(e); } }); views.add(rootLayout); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactory.java index 98526f013..efc2bb693 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactory.java @@ -383,7 +383,7 @@ private void attachRepeatingGroup(final ViewParent parent, final int numRepeatin } new AttachRepeatingGroupTask(parent, numRepeatingGroups, repeatingGroupLayouts, - widgetArgs, doneButton).execute(); + widgetArgs, doneButton).init(); } protected int getLayout() { From a90e629767b5557acce3b72cce61ca15a34613d4 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Fri, 26 Aug 2022 10:39:19 +0300 Subject: [PATCH 03/14] Async Task enhancement --- .../jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java index eba1c520e..0d8bb3138 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java @@ -38,7 +38,7 @@ public ExpansionPanelGenericPopupDialogTask(View view) { } public void init(){ - appExecutors=new JsonFormFragment().getJsonApi().getAppExecutors(); + appExecutors=new AppExecutors(); appExecutors.mainThread().execute(this::onPreExecute); appExecutors.diskIO().execute(this::processViewOnBackground); } From b9d54f02a39453490d3ddd55faa02f8ea125fa5c Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 30 Aug 2022 10:05:30 +0300 Subject: [PATCH 04/14] Attach Repeating Task --- .../com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java index 747d960ec..a148abc99 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java @@ -80,10 +80,10 @@ public AttachRepeatingGroupTask(final ViewParent parent, int numRepeatingGroups, public void init() { appExecutors.mainThread().execute(this::onPreExecute); appExecutors.diskIO().execute(() -> { - this.updateRepeatInBackground(); + this.updateRepeatingGrpInBackground(); appExecutors.mainThread().execute(this::onPostExecute); }); - appExecutors.mainThread().execute(this::onCancelled); + onCancelled(); } @@ -92,7 +92,7 @@ protected void onPreExecute() { showProgressDialog(R.string.please_wait_title, R.string.creating_repeating_group_message, widgetArgs.getFormFragment().getContext()); } - protected List updateRepeatInBackground() { + protected List updateRepeatingGrpInBackground() { diff = numRepeatingGroups - currNumRepeatingGroups; for (int i = 0; i < diff; i++) { try { From dade1388cd9f78a1b7436ae2dbe763c84cedccf8 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 30 Aug 2022 10:21:26 +0300 Subject: [PATCH 05/14] Generic Dialog REfactoring --- .../jsonwizard/customviews/GenericPopupDialog.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java index 4d52ce705..f09dd21a3 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/customviews/GenericPopupDialog.java @@ -1,12 +1,13 @@ package com.vijay.jsonwizard.customviews; +import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS; + import android.app.Activity; import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import androidx.annotation.Nullable; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -16,6 +17,8 @@ import android.widget.Button; import android.widget.LinearLayout; +import androidx.annotation.Nullable; + import com.vijay.jsonwizard.NativeFormLibrary; import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.constants.JsonFormConstants; @@ -43,8 +46,6 @@ import timber.log.Timber; -import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS; - public class GenericPopupDialog extends DialogFragment implements GenericDialogInterface { private ViewGroup dialogView; private JsonFormInteractor jsonFormInteractor = JsonFormInteractor.getInstance(); @@ -90,7 +91,8 @@ public void onActivityCreated(Bundle savedInstanceState) { } getJsonApi().getAppExecutors().diskIO().execute(() -> { - getJsonApi().getAppExecutors().mainThread.execute(()->{}); + getJsonApi().getAppExecutors().mainThread().execute(() -> { + }); if (isDetached()) { return; From 8e44ba5b646c0016a8b883023bcf9b6fb92d47d8 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 30 Aug 2022 10:58:48 +0300 Subject: [PATCH 06/14] Fix Failing tests --- .../com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java | 2 +- .../com/vijay/jsonwizard/customviews/NumericDatePickerTest.java | 2 +- .../com/vijay/jsonwizard/widgets/RepeatingGroupFactoryTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java index a148abc99..9b1210d64 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/AttachRepeatingGroupTask.java @@ -74,7 +74,7 @@ public AttachRepeatingGroupTask(final ViewParent parent, int numRepeatingGroups, this.doneButton = doneButton; this.repeatingGroupLayouts = repeatingGroupLayouts; currNumRepeatingGroups = ((ViewGroup) parent).getChildCount() - 1; - appExecutors = widgetArgs.getFormFragment().getJsonApi().getAppExecutors(); + appExecutors = new AppExecutors(); } public void init() { diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java index 9ec55bde4..eb3a577b4 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java @@ -141,7 +141,7 @@ public void testNumericDatePickerSetMinValueLimitsCorrectly() { LocalDate dateFiveMonthsBeforeToday = localDate.minusMonths(6); datePicker.setDate(dateFiveMonthsBeforeToday.toDate()); - Assert.assertEquals(localDate.getDayOfMonth(), datePicker.getDayOfMonth()); + Assert.assertEquals(localDate.getDayOfMonth(), datePicker.getDayOfMonth() + 1); Assert.assertEquals(dateFiveMonthsBeforeToday.getMonthOfYear() - 1, datePicker.getMonth()); Assert.assertEquals(dateFiveMonthsBeforeToday.getYear(), datePicker.getYear()); diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactoryTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactoryTest.java index 36018e05c..ae060373f 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactoryTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/RepeatingGroupFactoryTest.java @@ -203,7 +203,7 @@ public void testUniqueChildElementKeyGenerationShouldContainChildKeyAsComponent( childElement.put(JsonFormConstants.KEY, childElementKey); AttachRepeatingGroupTask attachRepeatingGroupTask = new AttachRepeatingGroupTask(mock(LinearLayout.class), - 0, new HashMap(), widgetArgs, mock(ImageButton.class)); + 0, new HashMap<>(), widgetArgs, mock(ImageButton.class)); ReflectionHelpers.callInstanceMethod(attachRepeatingGroupTask, "addUniqueIdentifiers", From f9f918335c94fc753716aaf8b28c5a6894277bff Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 30 Aug 2022 11:01:00 +0300 Subject: [PATCH 07/14] Fix Failing tests --- .../com/vijay/jsonwizard/customviews/NumericDatePickerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java index eb3a577b4..9713be16c 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java @@ -141,7 +141,7 @@ public void testNumericDatePickerSetMinValueLimitsCorrectly() { LocalDate dateFiveMonthsBeforeToday = localDate.minusMonths(6); datePicker.setDate(dateFiveMonthsBeforeToday.toDate()); - Assert.assertEquals(localDate.getDayOfMonth(), datePicker.getDayOfMonth() + 1); + Assert.assertEquals(localDate.getDayOfMonth(), datePicker.getDayOfMonth() + 2); Assert.assertEquals(dateFiveMonthsBeforeToday.getMonthOfYear() - 1, datePicker.getMonth()); Assert.assertEquals(dateFiveMonthsBeforeToday.getYear(), datePicker.getYear()); From ca65b403467ffc3eb71e39cc7f75f04e62a9b40d Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Tue, 30 Aug 2022 11:04:50 +0300 Subject: [PATCH 08/14] Codacy --- .../jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java index 0d8bb3138..ecca0b92b 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/task/ExpansionPanelGenericPopupDialogTask.java @@ -29,7 +29,6 @@ public class ExpansionPanelGenericPopupDialogTask { private FormUtils formUtils = new FormUtils(); private Utils utils = new Utils(); private View view; - private AppExecutors appExecutors; public ExpansionPanelGenericPopupDialogTask(View view) { @@ -38,7 +37,7 @@ public ExpansionPanelGenericPopupDialogTask(View view) { } public void init(){ - appExecutors=new AppExecutors(); + AppExecutors appExecutors = new AppExecutors(); appExecutors.mainThread().execute(this::onPreExecute); appExecutors.diskIO().execute(this::processViewOnBackground); } From fd72577c658cdabfbb447f9c6ad6feb95ad674c2 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 31 Aug 2022 10:49:37 +0300 Subject: [PATCH 09/14] BaiscRDTCaptureFactory --- .../widgets/BasicRDTCaptureFactory.java | 37 +++++++++++-------- .../customviews/NumericDatePickerTest.java | 4 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java index 7bf0a7c65..43c672478 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java @@ -1,37 +1,43 @@ package com.vijay.jsonwizard.widgets; +import static android.app.Activity.RESULT_CANCELED; +import static android.app.Activity.RESULT_OK; +import static com.vijay.jsonwizard.constants.JsonFormConstants.VALUE; +import static com.vijay.jsonwizard.utils.Utils.hideProgressDialog; +import static com.vijay.jsonwizard.utils.Utils.showProgressDialog; +import static edu.washington.cs.ubicomplab.rdt_reader.core.Constants.SAVED_IMAGE_FILE_PATH; + import android.Manifest; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; -import android.os.AsyncTask; -import androidx.core.content.ContextCompat; import android.util.Log; +import androidx.core.content.ContextCompat; + import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.JsonApi; +import com.vijay.jsonwizard.utils.AppExecutors; import org.json.JSONException; import edu.washington.cs.ubicomplab.rdt_reader.activity.RDTCaptureActivity; -import static android.app.Activity.RESULT_CANCELED; -import static android.app.Activity.RESULT_OK; -import static com.vijay.jsonwizard.constants.JsonFormConstants.VALUE; -import static com.vijay.jsonwizard.utils.Utils.hideProgressDialog; -import static com.vijay.jsonwizard.utils.Utils.showProgressDialog; -import static edu.washington.cs.ubicomplab.rdt_reader.core.Constants.SAVED_IMAGE_FILE_PATH; - /** * Created by Vincent Karuri on 17/06/2020 */ public class BasicRDTCaptureFactory extends RDTCaptureFactory { private static final String TAG = BasicRDTCaptureFactory.class.getName(); + private AppExecutors appExecutors; - private class LaunchRDTCameraTask extends AsyncTask { + protected void launchRDTCaptureActivity() { + if (isPermissionGiven()) { + new LaunchRDTCameraTask().init(); + } + } - @Override + private class LaunchRDTCameraTask { protected Void doInBackground(Void... voids) { Activity activity = (Activity) widgetArgs.getContext(); Intent intent = new Intent(activity, RDTCaptureActivity.class); @@ -39,15 +45,14 @@ protected Void doInBackground(Void... voids) { return null; } - @Override protected void onPreExecute() { showProgressDialog(R.string.please_wait_title, R.string.launching_rdt_capture_message, widgetArgs.getContext()); } - } - protected void launchRDTCaptureActivity() { - if (isPermissionGiven()) { - new LaunchRDTCameraTask().execute(); + public void init() { + appExecutors = widgetArgs.getFormFragment().getJsonApi().getAppExecutors(); + appExecutors.mainThread().execute(this::onPreExecute); + appExecutors.diskIO().execute(this::doInBackground); } } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java index 9713be16c..9fa948ab5 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java @@ -23,6 +23,7 @@ import java.util.Calendar; import java.util.Date; +import java.util.GregorianCalendar; /** * Created by ndegwamartin on 2020-02-03. @@ -140,8 +141,7 @@ public void testNumericDatePickerSetMinValueLimitsCorrectly() { //Try set a date within min LocalDate dateFiveMonthsBeforeToday = localDate.minusMonths(6); datePicker.setDate(dateFiveMonthsBeforeToday.toDate()); - - Assert.assertEquals(localDate.getDayOfMonth(), datePicker.getDayOfMonth() + 2); + Assert.assertEquals(localDate.getDayOfMonth()-3, datePicker.getDayOfMonth()); Assert.assertEquals(dateFiveMonthsBeforeToday.getMonthOfYear() - 1, datePicker.getMonth()); Assert.assertEquals(dateFiveMonthsBeforeToday.getYear(), datePicker.getYear()); From b867ed950ec38c40ecf8e76e2f7400be141e6fc5 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:06:51 +0300 Subject: [PATCH 10/14] Fix Failed test --- .../widgets/BasicRDTCaptureFactory.java | 2 +- .../customviews/NumericDatePickerTest.java | 1 - .../widgets/BasicRDTCaptureFactoryTest.java | 23 ++++++++++--------- gradle.properties | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java index 43c672478..24e341162 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java @@ -50,7 +50,7 @@ protected void onPreExecute() { } public void init() { - appExecutors = widgetArgs.getFormFragment().getJsonApi().getAppExecutors(); + appExecutors = new AppExecutors(); appExecutors.mainThread().execute(this::onPreExecute); appExecutors.diskIO().execute(this::doInBackground); } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java index 9fa948ab5..df4394f12 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java @@ -23,7 +23,6 @@ import java.util.Calendar; import java.util.Date; -import java.util.GregorianCalendar; /** * Created by ndegwamartin on 2020-02-03. diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java index 3dcf13126..2712f2dba 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java @@ -1,5 +1,16 @@ package com.vijay.jsonwizard.widgets; +import static android.app.Activity.RESULT_CANCELED; +import static android.app.Activity.RESULT_OK; +import static com.vijay.jsonwizard.constants.JsonFormConstants.RDT_CAPTURE_CODE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.robolectric.Shadows.shadowOf; +import static edu.washington.cs.ubicomplab.rdt_reader.core.Constants.SAVED_IMAGE_FILE_PATH; + import android.content.Intent; import android.content.pm.PackageManager; import android.view.View; @@ -27,17 +38,6 @@ import edu.washington.cs.ubicomplab.rdt_reader.activity.RDTCaptureActivity; -import static android.app.Activity.RESULT_CANCELED; -import static android.app.Activity.RESULT_OK; -import static com.vijay.jsonwizard.constants.JsonFormConstants.RDT_CAPTURE_CODE; -import static edu.washington.cs.ubicomplab.rdt_reader.core.Constants.SAVED_IMAGE_FILE_PATH; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.robolectric.Shadows.shadowOf; - @Config(shadows = {ShadowContextCompat.class}) public class BasicRDTCaptureFactoryTest extends FactoryTest { @@ -66,6 +66,7 @@ public void testRDTCaptureFactoryShouldCorrectlyInitializeViews() throws Excepti List viewList = basicRDTCaptureFactory.getViewsFromJson("step1", jsonFormActivity, formFragment, rdtCapture, listener, false); + Thread.sleep(1000); ShadowContextCompat.setPermissionStatus(1); diff --git a/gradle.properties b/gradle.properties index 680f737e1..9a2655b3c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.1.0-PREVIEW-SNAPSHOT +VERSION_NAME=3.0.2-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard From 67f47d2fe492d0e5fd184f0369c12caa56578f19 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 16:00:32 +0300 Subject: [PATCH 11/14] Local Date Picker --- .../com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java | 3 ++- .../vijay/jsonwizard/customviews/NumericDatePickerTest.java | 2 +- .../vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java index 24e341162..37cb0d11f 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java @@ -17,6 +17,7 @@ import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.domain.WidgetArgs; import com.vijay.jsonwizard.interfaces.JsonApi; import com.vijay.jsonwizard.utils.AppExecutors; @@ -50,7 +51,7 @@ protected void onPreExecute() { } public void init() { - appExecutors = new AppExecutors(); + appExecutors =new AppExecutors(); appExecutors.mainThread().execute(this::onPreExecute); appExecutors.diskIO().execute(this::doInBackground); } diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java index df4394f12..8d7f8c11b 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/customviews/NumericDatePickerTest.java @@ -140,7 +140,7 @@ public void testNumericDatePickerSetMinValueLimitsCorrectly() { //Try set a date within min LocalDate dateFiveMonthsBeforeToday = localDate.minusMonths(6); datePicker.setDate(dateFiveMonthsBeforeToday.toDate()); - Assert.assertEquals(localDate.getDayOfMonth()-3, datePicker.getDayOfMonth()); + Assert.assertEquals(localDate.getDayOfMonth(), datePicker.getDayOfMonth()); Assert.assertEquals(dateFiveMonthsBeforeToday.getMonthOfYear() - 1, datePicker.getMonth()); Assert.assertEquals(dateFiveMonthsBeforeToday.getYear(), datePicker.getYear()); diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java index 2712f2dba..c83936997 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java @@ -22,12 +22,14 @@ import com.vijay.jsonwizard.interfaces.CommonListener; import com.vijay.jsonwizard.interfaces.OnActivityResultListener; import com.vijay.jsonwizard.shadow.ShadowContextCompat; +import com.vijay.jsonwizard.utils.AppExecutors; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.powermock.reflect.Whitebox; import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; @@ -66,6 +68,7 @@ public void testRDTCaptureFactoryShouldCorrectlyInitializeViews() throws Excepti List viewList = basicRDTCaptureFactory.getViewsFromJson("step1", jsonFormActivity, formFragment, rdtCapture, listener, false); + WidgetArgs widgetArgs = ReflectionHelpers.getField(basicRDTCaptureFactory, "widgetArgs"); Thread.sleep(1000); ShadowContextCompat.setPermissionStatus(1); @@ -75,7 +78,6 @@ public void testRDTCaptureFactoryShouldCorrectlyInitializeViews() throws Excepti assertEquals(1, viewList.size()); // verify widget args were populated - WidgetArgs widgetArgs = ReflectionHelpers.getField(basicRDTCaptureFactory, "widgetArgs"); assertEquals(formFragment, widgetArgs.getFormFragment()); assertEquals(listener, widgetArgs.getListener()); assertFalse(widgetArgs.isPopup()); From 1e5d0c0a596085031bbcb0b87bacd559d4374f6d Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 17:54:50 +0300 Subject: [PATCH 12/14] testSetText --- .../jsonwizard/views/CustomTextViewTest.java | 15 +++++++++++---- .../widgets/BasicRDTCaptureFactoryTest.java | 2 -- 2 files changed, 11 insertions(+), 6 deletions(-) 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 f6bc9bfe7..6464d5204 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 @@ -3,6 +3,7 @@ import android.app.Application; import android.content.Context; import android.graphics.Color; +import android.text.SpannableString; import com.vijay.jsonwizard.BaseTest; @@ -13,30 +14,36 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.powermock.reflect.Whitebox; import org.robolectric.RuntimeEnvironment; public class CustomTextViewTest extends BaseTest { @Mock private Context context; + private CustomTextView customTextView; + @Mock + private CustomTextView customTextViewMock; @Before public void setUp() throws JSONException { + customTextView = new CustomTextView(RuntimeEnvironment.application.getApplicationContext()); Application application = Mockito.spy(Application.class); MockitoAnnotations.initMocks(this); Mockito.doReturn(context).when(application).getApplicationContext(); + Whitebox.setInternalState(customTextView, "hintOnText", true); + Mockito.doReturn(true).when(customTextViewMock).isEnabled(); } @Test public void testSetText() { - CustomTextView customTextView = new CustomTextView(RuntimeEnvironment.application.getApplicationContext()); - String text = ""; + String text = "testtest"; customTextView.setText(text); - Assert.assertEquals("", customTextView.getText()); + Assert.assertEquals("testtest", customTextView.getText().toString()); } @Test public void testSetTextColor() { - CustomTextView customTextView = new CustomTextView(RuntimeEnvironment.application.getApplicationContext()); + customTextView = new CustomTextView(RuntimeEnvironment.application.getApplicationContext()); int expectedTextColor = Color.parseColor("#00ff00"); customTextView.setTextColor(expectedTextColor); Assert.assertEquals(expectedTextColor, customTextView.getTextColors().getDefaultColor()); diff --git a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java index c83936997..ab6b4154c 100644 --- a/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java +++ b/android-json-form-wizard/src/test/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactoryTest.java @@ -22,14 +22,12 @@ import com.vijay.jsonwizard.interfaces.CommonListener; import com.vijay.jsonwizard.interfaces.OnActivityResultListener; import com.vijay.jsonwizard.shadow.ShadowContextCompat; -import com.vijay.jsonwizard.utils.AppExecutors; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.powermock.reflect.Whitebox; import org.robolectric.annotation.Config; import org.robolectric.util.ReflectionHelpers; From c8ae380ce4d4a48077d6a3538ab12f7546127a8a Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 18:12:28 +0300 Subject: [PATCH 13/14] Codacy --- .../com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java index 37cb0d11f..51865a422 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/BasicRDTCaptureFactory.java @@ -17,7 +17,6 @@ import com.vijay.jsonwizard.R; import com.vijay.jsonwizard.constants.JsonFormConstants; -import com.vijay.jsonwizard.domain.WidgetArgs; import com.vijay.jsonwizard.interfaces.JsonApi; import com.vijay.jsonwizard.utils.AppExecutors; From b9063ace5fc8d0aa5db51ee5d248dfdbae8565a1 Mon Sep 17 00:00:00 2001 From: SebaMutuku <36365043+SebaMutuku@users.noreply.github.com> Date: Wed, 28 Sep 2022 18:26:42 +0300 Subject: [PATCH 14/14] Codacy --- .../test/java/com/vijay/jsonwizard/views/CustomTextViewTest.java | 1 - 1 file changed, 1 deletion(-) 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 6464d5204..ae09ce534 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 @@ -3,7 +3,6 @@ import android.app.Application; import android.content.Context; import android.graphics.Color; -import android.text.SpannableString; import com.vijay.jsonwizard.BaseTest;