diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/NativeFormLibrary.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/NativeFormLibrary.java index 88edd2ef0..ac87f02b9 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/NativeFormLibrary.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/NativeFormLibrary.java @@ -2,7 +2,7 @@ import android.support.annotation.NonNull; -import org.smartregister.client.utils.contract.ClientFormDao; +import org.smartregister.client.utils.contract.ClientFormContract; /** * Created by Ephraim Kigamba - nek.eam@gmail.com on 29-06-2020. @@ -18,7 +18,7 @@ public static final boolean init() { return false; } - public ClientFormDao getClientFormDao() { + public ClientFormContract.Dao getClientFormDao() { return null; } } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivity.java index 21fa9b701..3af09c003 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonFormActivity.java @@ -17,8 +17,6 @@ import org.json.JSONException; import org.json.JSONObject; -import org.smartregister.client.utils.contract.ClientFormContract; -import org.smartregister.client.utils.contract.JsonSubFormAndRulesLoader; import java.io.BufferedReader; import java.io.IOException; @@ -29,7 +27,7 @@ /** * Created by Ephraim Kigamba - nek.eam@gmail.com on 29-06-2020. */ -public class FormConfigurationJsonFormActivity extends JsonFormActivity implements ClientFormContract.View { +public class FormConfigurationJsonFormActivity extends JsonFormActivity { private FormUtils formUtils; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormBaseActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormBaseActivity.java index 234b91b67..b149df98b 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormBaseActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonFormBaseActivity.java @@ -27,7 +27,7 @@ import org.json.JSONException; import org.json.JSONObject; -import org.smartregister.client.utils.contract.JsonSubFormAndRulesLoader; +import org.smartregister.client.utils.contract.ClientFormContract; import java.io.BufferedReader; import java.io.IOException; @@ -44,7 +44,7 @@ import static com.vijay.jsonwizard.utils.NativeFormLangUtils.getTranslatedString; -abstract class JsonFormBaseActivity extends MultiLanguageActivity implements OnFieldsInvalid, JsonSubFormAndRulesLoader { +abstract class JsonFormBaseActivity extends MultiLanguageActivity implements OnFieldsInvalid, ClientFormContract.View { protected static final String TAG = JsonFormActivity.class.getSimpleName(); protected static final String JSON_STATE = "jsonState"; protected static final String FORM_STATE = "formState"; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/JsonApi.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/JsonApi.java index 4ae42d509..f774d4c6a 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/JsonApi.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/JsonApi.java @@ -9,6 +9,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.smartregister.client.utils.contract.ClientFormContract; import org.smartregister.client.utils.contract.JsonSubFormAndRulesLoader; import java.util.Collection; @@ -17,7 +18,7 @@ /** * Created by vijay on 5/16/15. */ -public interface JsonApi extends JsonSubFormAndRulesLoader { +public interface JsonApi extends ClientFormContract.View { JSONObject getStep(String stepName); void writeValue(String stepName, String key, String value, String openMrsEntityParent, diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/RollbackDialogCallback.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/RollbackDialogCallback.java index 122018f76..88b9b8522 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/RollbackDialogCallback.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/interfaces/RollbackDialogCallback.java @@ -2,14 +2,14 @@ import android.support.annotation.NonNull; -import org.smartregister.client.utils.contract.ClientFormDao; +import org.smartregister.client.utils.contract.ClientFormContract; /** * Created by Ephraim Kigamba - nek.eam@gmail.com on 21-05-2020. */ public interface RollbackDialogCallback { - void onFormSelected(@NonNull ClientFormDao.ClientFormModel selectedForm); + void onFormSelected(@NonNull ClientFormContract.Model selectedForm); void onCancelClicked(); } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java index 6a6f681ae..c3df795ff 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/rules/RulesEngineFactory.java @@ -5,7 +5,6 @@ import com.google.gson.Gson; import com.vijay.jsonwizard.constants.JsonFormConstants; -import com.vijay.jsonwizard.interfaces.JsonSubFormAndRulesLoader; import com.vijay.jsonwizard.utils.Utils; import org.jeasy.rules.api.Facts; @@ -19,6 +18,7 @@ import org.jeasy.rules.mvel.MVELRuleFactory; import org.json.JSONArray; import org.json.JSONObject; +import org.smartregister.client.utils.contract.ClientFormContract; import java.io.BufferedReader; import java.io.IOException; @@ -144,8 +144,8 @@ private Rules getRulesFromAsset(String fileName) { if (!ruleMap.containsKey(fileName)) { BufferedReader bufferedReader; boolean loadedFromDb = false; - if (context instanceof JsonSubFormAndRulesLoader) { - bufferedReader = ((JsonSubFormAndRulesLoader) context).getRules(context, fileName); + if (context instanceof ClientFormContract.View) { + bufferedReader = ((ClientFormContract.View) context).getRules(context, fileName); loadedFromDb = true; } else { bufferedReader = new BufferedReader(new InputStreamReader(context.getAssets().open(fileName))); @@ -158,7 +158,7 @@ private Rules getRulesFromAsset(String fileName) { Timber.e(ex); if (loadedFromDb) { - ((JsonSubFormAndRulesLoader) context).handleFormError(true, fileName); + ((ClientFormContract.View) context).handleFormError(true, fileName); } return null; diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtil.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtil.java index b5adf3b60..99c65cc66 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtil.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormRollbackDialogUtil.java @@ -12,8 +12,7 @@ import com.vijay.jsonwizard.constants.JsonFormConstants; import com.vijay.jsonwizard.interfaces.RollbackDialogCallback; -import org.smartregister.client.utils.contract.ClientFormDao; -import org.smartregister.client.utils.contract.JsonSubFormAndRulesLoader; +import org.smartregister.client.utils.contract.ClientFormContract; import java.util.List; @@ -23,9 +22,9 @@ public class FormRollbackDialogUtil { public static AlertDialog showAvailableRollbackFormsDialog(@NonNull final Context context - , @NonNull final ClientFormDao clientFormRepository - , @NonNull final List clientFormList - , @NonNull final ClientFormDao.ClientFormModel currentClientForm + , @NonNull final ClientFormContract.Dao clientFormRepository + , @NonNull final List clientFormList + , @NonNull final ClientFormContract.Model currentClientForm , final @NonNull RollbackDialogCallback rollbackDialogCallback) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(context); builderSingle.setIcon(R.drawable.ic_icon_danger); @@ -36,7 +35,7 @@ public static AlertDialog showAvailableRollbackFormsDialog(@NonNull final Contex final ArrayAdapter arrayAdapter = new ArrayAdapter(context, android.R.layout.select_dialog_singlechoice); int counter = 0; - for (ClientFormDao.ClientFormModel clientForm : clientFormList) { + for (ClientFormContract.Model clientForm : clientFormList) { if (clientForm.getVersion().equals(currentClientForm.getVersion())) { selectedItem = counter; arrayAdapter.add("v" + clientForm.getVersion() + context.getString(R.string.current_corrupted_form)); @@ -74,26 +73,26 @@ public void onClick(DialogInterface dialog, int which) { builderSingle.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { - if (context instanceof JsonSubFormAndRulesLoader) { - ((JsonSubFormAndRulesLoader) context).setVisibleFormErrorAndRollbackDialog(false); + if (context instanceof ClientFormContract.View) { + ((ClientFormContract.View) context).setVisibleFormErrorAndRollbackDialog(false); } } }); - if (context instanceof JsonSubFormAndRulesLoader) { - ((JsonSubFormAndRulesLoader) context).setVisibleFormErrorAndRollbackDialog(true); + if (context instanceof ClientFormContract.View) { + ((ClientFormContract.View) context).setVisibleFormErrorAndRollbackDialog(true); } return builderSingle.show(); } @VisibleForTesting - protected static boolean selectForm(@NonNull ClientFormDao clientFormRepository, int pos, @NonNull String formVersion, @NonNull Context context, @NonNull List clientFormList, @NonNull ClientFormDao.ClientFormModel currentClientForm, @NonNull RollbackDialogCallback rollbackDialogCallback) { + protected static boolean selectForm(@NonNull ClientFormContract.Dao clientFormRepository, int pos, @NonNull String formVersion, @NonNull Context context, @NonNull List clientFormList, @NonNull ClientFormContract.Model currentClientForm, @NonNull RollbackDialogCallback rollbackDialogCallback) { if (formVersion.contains(context.getString(R.string.current_corrupted_form))) { Toast.makeText(context, R.string.cannot_select_corrupted_form_rollback, Toast.LENGTH_LONG).show(); return false; } else { - ClientFormDao.ClientFormModel selectedClientForm; + ClientFormContract.Model selectedClientForm; if (formVersion.equals(JsonFormConstants.CLIENT_FORM_ASSET_VERSION)) { selectedClientForm = clientFormRepository.createNewClientFormModel(); selectedClientForm.setVersion(JsonFormConstants.CLIENT_FORM_ASSET_VERSION); 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 00f4eb20f..3db13c58c 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 @@ -53,7 +53,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.smartregister.client.utils.contract.JsonSubFormAndRulesLoader; +import org.smartregister.client.utils.contract.ClientFormContract; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -61,7 +61,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; -import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -1784,16 +1783,16 @@ public String setValues(JSONArray jsonArray, String type) { } @Nullable - public JSONObject getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull ClientFormDao clientFormRepository, @NonNull String formIdentity) { + 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 ClientFormDao clientFormRepository, @NonNull String formIdentity, @Nullable OnFormFetchedCallback onFormFetchedCallback) { + public void getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity, @Nullable OnFormFetchedCallback onFormFetchedCallback) { getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, onFormFetchedCallback); } - private JSONObject getFormJsonFromRepositoryOrAssetsWithOptionalCallback(@NonNull Context context, @NonNull ClientFormDao clientFormRepository, String formIdentity, @Nullable final OnFormFetchedCallback onFormFetchedCallback) { - ClientFormDao.ClientFormModel clientForm = getClientFormFromRepository(context, clientFormRepository, formIdentity); + private JSONObject getFormJsonFromRepositoryOrAssetsWithOptionalCallback(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, String formIdentity, @Nullable final OnFormFetchedCallback onFormFetchedCallback) { + ClientFormContract.Model clientForm = getClientFormFromRepository(context, clientFormRepository, formIdentity); try { if (clientForm != null) { @@ -1840,7 +1839,7 @@ public void onFormFetched(@Nullable String form) { } } - public JSONObject getFormJson(@NonNull Context context, @NonNull ClientFormDao clientFormRepository, String formIdentity) { + public JSONObject getFormJson(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, String formIdentity) { if (context != null) { try { String locale = context.getResources().getConfiguration().locale.getLanguage(); @@ -1873,7 +1872,7 @@ public JSONObject getFormJson(@NonNull Context context, @NonNull ClientFormDao c return null; } - private ClientFormDao.ClientFormModel getClientFormFromRepository(@NonNull Context context, @NonNull ClientFormDao clientFormRepository, String formIdentity) { + private ClientFormContract.Model getClientFormFromRepository(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, String formIdentity) { //Check the current locale of the app to load the correct version of the form in the desired language String locale = context.getResources().getConfiguration().locale.getLanguage(); String localeFormIdentity = formIdentity; @@ -1881,7 +1880,7 @@ private ClientFormDao.ClientFormModel getClientFormFromRepository(@NonNull Conte localeFormIdentity = localeFormIdentity + "-" + locale; } - ClientFormDao.ClientFormModel clientForm = clientFormRepository.getActiveClientFormByIdentifier(localeFormIdentity); + ClientFormContract.Model clientForm = clientFormRepository.getActiveClientFormByIdentifier(localeFormIdentity); if (clientForm == null) { String revisedFormName = extractFormNameWithoutExtension(localeFormIdentity); @@ -1890,25 +1889,25 @@ private ClientFormDao.ClientFormModel getClientFormFromRepository(@NonNull Conte return clientForm; } - public void handleJsonFormOrRulesError(@NonNull Context context, @NonNull ClientFormDao clientFormRepository, @NonNull String formIdentity, @NonNull OnFormFetchedCallback onFormFetchedCallback) { + public void handleJsonFormOrRulesError(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity, @NonNull OnFormFetchedCallback onFormFetchedCallback) { handleJsonFormOrRulesError(context, clientFormRepository, false, formIdentity, onFormFetchedCallback); } - public void handleJsonFormOrRulesError(@NonNull final Context context, @NonNull final ClientFormDao clientFormRepository, final boolean isRulesFile, @NonNull final String formIdentity, @NonNull final OnFormFetchedCallback onFormFetchedCallback) { - final ClientFormDao.ClientFormModel clientForm = getClientFormFromRepository(context, clientFormRepository, formIdentity); - List clientForms = clientFormRepository.getClientFormByIdentifier(clientForm.getIdentifier()); + public void handleJsonFormOrRulesError(@NonNull final Context context, @NonNull final ClientFormContract.Dao clientFormRepository, final boolean isRulesFile, @NonNull final String formIdentity, @NonNull final OnFormFetchedCallback onFormFetchedCallback) { + final ClientFormContract.Model clientForm = getClientFormFromRepository(context, clientFormRepository, formIdentity); + List clientForms = clientFormRepository.getClientFormByIdentifier(clientForm.getIdentifier()); if (clientForms.size() > 0) { // Show dialog asking user if they want to rollback to the previous available version X // if YES, then provide that form instead // if NO, then continue down - boolean dialogIsShowing = (context instanceof JsonSubFormAndRulesLoader) && ((JsonSubFormAndRulesLoader) context).isVisibleFormErrorAndRollbackDialog(); + boolean dialogIsShowing = (context instanceof ClientFormContract.View) && ((ClientFormContract.View) context).isVisibleFormErrorAndRollbackDialog(); if (!dialogIsShowing) { FormRollbackDialogUtil.showAvailableRollbackFormsDialog(context, clientFormRepository, clientForms, clientForm, new RollbackDialogCallback() { @Override - public void onFormSelected(@NonNull ClientFormDao.ClientFormModel selectedForm) { + public void onFormSelected(@NonNull ClientFormContract.Model selectedForm) { if (selectedForm.getJson() == null && selectedForm.getVersion().equals(JsonFormConstants.CLIENT_FORM_ASSET_VERSION)) { if (isRulesFile) { @@ -1939,7 +1938,7 @@ public void onCancelClicked() { } @Nullable - public JSONObject getSubFormJsonFromRepository(@NonNull Context context, @NonNull ClientFormDao clientFormDao, String formIdentity, String subFormsLocation, boolean translateSubForm) throws JSONException { + public JSONObject getSubFormJsonFromRepository(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormDao, String formIdentity, String subFormsLocation, boolean translateSubForm) throws JSONException { String locale = context.getResources().getConfiguration().locale.getLanguage(); //Check the current locale of the app to load the correct version of the form in the desired language @@ -1949,7 +1948,7 @@ public JSONObject getSubFormJsonFromRepository(@NonNull Context context, @NonNul } String dbFormName = StringUtils.isBlank(subFormsLocation) ? localeFormIdentity : subFormsLocation + "/" + localeFormIdentity; - ClientFormDao.ClientFormModel clientForm = clientFormDao.getActiveClientFormByIdentifier(dbFormName); + ClientFormContract.Model clientForm = clientFormDao.getActiveClientFormByIdentifier(dbFormName); if (clientForm == null) { String revisedFormName = extractFormNameWithoutExtension(dbFormName); @@ -1978,7 +1977,7 @@ public JSONObject getSubFormJsonFromRepository(@NonNull Context context, @NonNul } @Nullable - public BufferedReader getRulesFromRepository(@NonNull Context context, @NonNull ClientFormDao clientFormDao, @NonNull String fileName) { + public BufferedReader getRulesFromRepository(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormDao, @NonNull String fileName) { String locale = context.getResources().getConfiguration().locale.getLanguage(); //Check the current locale of the app to load the correct version of the form in the desired language @@ -1987,7 +1986,7 @@ public BufferedReader getRulesFromRepository(@NonNull Context context, @NonNull localeFormIdentity = localeFormIdentity + "-" + locale; } - ClientFormDao.ClientFormModel clientForm = clientFormDao.getActiveClientFormByIdentifier(localeFormIdentity); + ClientFormContract.Model clientForm = clientFormDao.getActiveClientFormByIdentifier(localeFormIdentity); if (clientForm != null) { Timber.d("============%s form loaded from db============", localeFormIdentity); String originalJson = clientForm.getJson(); @@ -2005,7 +2004,7 @@ protected String extractFormNameWithoutExtension(String localeFormIdentity) { localeFormIdentity + JsonFormConstants.JSON_FILE_EXTENSION; } - public void injectFormStatus(@NonNull JSONObject jsonObject, @NonNull ClientFormDao.ClientFormModel clientForm) { + public void injectFormStatus(@NonNull JSONObject jsonObject, @NonNull ClientFormContract.Model clientForm) { if (clientForm.isNew()) { try { jsonObject.put(JsonFormConstants.Properties.IS_NEW, clientForm.isNew());