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 cee6cbd57..aac2110cc 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 @@ -16,6 +16,7 @@ import com.vijay.jsonwizard.utils.AppExecutors; import com.vijay.jsonwizard.utils.FormUtils; import com.vijay.jsonwizard.utils.NativeFormLangUtils; +import com.vijay.jsonwizard.utils.NoLocaleFormUtils; import org.json.JSONException; import org.json.JSONObject; @@ -43,8 +44,15 @@ protected void onCreate(Bundle savedInstanceState) { checkIfFormUpdate(jsonObject); } - protected FormUtils getFormUtils(){ - return FormUtils.newInstance(); + private FormUtils getFormUtils(){ + if (!this.isUsingLocaleForms()){ + return new NoLocaleFormUtils(); + } + return new FormUtils(); + } + + protected boolean isUsingLocaleForms(){ + return true; } private void checkIfFormUpdate(@NonNull JSONObject formJsonObject) { diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonWizardFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonWizardFormActivity.java new file mode 100644 index 000000000..c1337714c --- /dev/null +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/FormConfigurationJsonWizardFormActivity.java @@ -0,0 +1,37 @@ +package com.vijay.jsonwizard.activities; + +import com.vijay.jsonwizard.delegates.JsonWizardFormDelegate; + +import org.json.JSONException; + +public class FormConfigurationJsonWizardFormActivity extends FormConfigurationJsonFormActivity{ + + private final JsonWizardFormDelegate delegate = new JsonWizardFormDelegate(); + + @Override + public void initializeFormFragment() { + initializeFormFragmentCore(); + } + + @Override + public void writeValue(String stepName, String key, String value, String openMrsEntityParent, String openMrsEntity, String openMrsEntityId) throws JSONException { + callSuperWriteValue(stepName, key, value, openMrsEntityParent, openMrsEntity, openMrsEntityId); + } + + @Override + public void onFormFinish() { + callSuperFinish(); + } + + protected void callSuperFinish(){ + super.onFormFinish(); + } + + protected void callSuperWriteValue(String stepName, String key, String value, String openMrsEntityParent, String openMrsEntity, String openMrsEntityId) throws JSONException { + super.writeValue(stepName, key, value, openMrsEntityParent, openMrsEntity, openMrsEntityId); + } + + protected void initializeFormFragmentCore(){ + delegate.initializeFormFragmentCore(this.getSupportFragmentManager()); + } +} diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonWizardFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonWizardFormActivity.java index d64af4f3b..dce1e0525 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonWizardFormActivity.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/JsonWizardFormActivity.java @@ -1,17 +1,18 @@ package com.vijay.jsonwizard.activities; -import com.vijay.jsonwizard.constants.JsonFormConstants; -import com.vijay.jsonwizard.fragments.JsonWizardFormFragment; +import com.vijay.jsonwizard.delegates.JsonWizardFormDelegate; import org.json.JSONException; /** * Created by keyman on 04/12/2018. */ -public class JsonWizardFormActivity extends FormConfigurationJsonFormActivity { +public class JsonWizardFormActivity extends JsonFormActivity { + + private final JsonWizardFormDelegate delegate = new JsonWizardFormDelegate(); @Override - public void initializeFormFragment() { + public synchronized void initializeFormFragment() { initializeFormFragmentCore(); } @@ -34,8 +35,7 @@ protected void callSuperWriteValue(String stepName, String key, String value, St } protected void initializeFormFragmentCore() { - JsonWizardFormFragment jsonWizardFormFragment = JsonWizardFormFragment.getFormFragment(JsonFormConstants.FIRST_STEP_NAME); - getSupportFragmentManager().beginTransaction().add(com.vijay.jsonwizard.R.id.container, jsonWizardFormFragment).commit(); + delegate.initializeFormFragmentCore(this.getSupportFragmentManager()); } } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/NoLocaleFormConfigurationJsonWizardFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/NoLocaleFormConfigurationJsonWizardFormActivity.java new file mode 100644 index 000000000..1ecbbdc27 --- /dev/null +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/NoLocaleFormConfigurationJsonWizardFormActivity.java @@ -0,0 +1,8 @@ +package com.vijay.jsonwizard.activities; + +public class NoLocaleFormConfigurationJsonWizardFormActivity extends FormConfigurationJsonWizardFormActivity { + @Override + protected boolean isUsingLocaleForms() { + return false; + } +} diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/NoLocaleJsonWizardFormActivity.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/NoLocaleJsonWizardFormActivity.java deleted file mode 100644 index 6c8ad940f..000000000 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/activities/NoLocaleJsonWizardFormActivity.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.vijay.jsonwizard.activities; - -import com.vijay.jsonwizard.utils.FormUtils; - -public class NoLocaleJsonWizardFormActivity extends JsonWizardFormActivity { - @Override - protected FormUtils getFormUtils() { - return FormUtils.newInstanceWithNoLocale(); - } -} diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/delegates/JsonWizardFormDelegate.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/delegates/JsonWizardFormDelegate.java new file mode 100644 index 000000000..1cb137682 --- /dev/null +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/delegates/JsonWizardFormDelegate.java @@ -0,0 +1,18 @@ +package com.vijay.jsonwizard.delegates; + +import android.support.annotation.NonNull; +import android.support.v4.app.FragmentManager; + +import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.fragments.JsonWizardFormFragment; + +public class JsonWizardFormDelegate { + + public void initializeFormFragmentCore(@NonNull FragmentManager supportFragmentManager){ + JsonWizardFormFragment jsonWizardFormFragment = JsonWizardFormFragment.getFormFragment(JsonFormConstants.FIRST_STEP_NAME); + supportFragmentManager.beginTransaction() + .add(com.vijay.jsonwizard.R.id.container, jsonWizardFormFragment) + .commit(); + } + +} 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 a7be0dff5..9c0c3cf2e 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 @@ -104,19 +104,6 @@ public class FormUtils { private Utils utils = new Utils(); private GenericDialogInterface genericDialogInterface; - public static FormUtils newInstance(){ - return new FormUtils(); - } - - public static FormUtils newInstanceWithNoLocale(){ - return new FormUtils(){ - @Override - protected String getLocaleFormIdentity(Context context, String formIdentity) { - return formIdentity; - } - }; - } - public static Point getViewLocationOnScreen(View view) { int[] location = new int[2]; view.getLocationOnScreen(location); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NoLocaleFormUtils.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NoLocaleFormUtils.java new file mode 100644 index 000000000..bc40efbed --- /dev/null +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/NoLocaleFormUtils.java @@ -0,0 +1,10 @@ +package com.vijay.jsonwizard.utils; + +import android.content.Context; + +public class NoLocaleFormUtils extends FormUtils{ + @Override + protected String getLocaleFormIdentity(Context context, String formIdentity) { + return formIdentity; + } +}