Skip to content

Commit

Permalink
allow getting forms from db without appending locale
Browse files Browse the repository at this point in the history
issue #585
  • Loading branch information
LZRS committed Jul 8, 2021
1 parent b266641 commit 1aaa7c3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.vijay.jsonwizard.interfaces.OnFormFetchedCallback;
import com.vijay.jsonwizard.utils.AppExecutors;
import com.vijay.jsonwizard.utils.FormUtils;
import com.vijay.jsonwizard.utils.FormUtilsFactory;
import com.vijay.jsonwizard.utils.NativeFormLangUtils;

import org.json.JSONException;
Expand All @@ -38,11 +39,15 @@ public class FormConfigurationJsonFormActivity extends JsonFormActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

formUtils = new FormUtils();
formUtils = getFormUtils();
JSONObject jsonObject = getmJSONObject();
checkIfFormUpdate(jsonObject);
}

protected FormUtils getFormUtils(){
return FormUtilsFactory.newInstance();
}

private void checkIfFormUpdate(@NonNull JSONObject formJsonObject) {
if (FormUtils.isFormNew(formJsonObject)) {
showFormVersionUpdateDialog(formJsonObject, getString(R.string.form_update_title), getString(R.string.form_update_message));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vijay.jsonwizard.activities;

import com.vijay.jsonwizard.utils.FormUtils;
import com.vijay.jsonwizard.utils.FormUtilsFactory;

public class NoLocaleJsonWizardFormActivity extends JsonWizardFormActivity {
@Override
protected FormUtils getFormUtils() {
return FormUtilsFactory.noLocaleInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1918,13 +1918,17 @@ public JSONObject getFormJson(@NonNull Context context, @NonNull String formIden
}
}

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
protected String getLocaleFormIdentity(final Context context, final String formIdentity){
String locale = context.getResources().getConfiguration().locale.getLanguage();
String localeFormIdentity = formIdentity;
if (!Locale.ENGLISH.getLanguage().equals(locale)) {
localeFormIdentity = localeFormIdentity + "-" + locale;
return formIdentity + "-" + locale;
}
return 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 localeFormIdentity = getLocaleFormIdentity(context, formIdentity);

ClientFormContract.Model clientForm = clientFormRepository.getActiveClientFormByIdentifier(localeFormIdentity);

Expand Down Expand Up @@ -2000,13 +2004,8 @@ public void onCancelClicked() {

@Nullable
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
String localeFormIdentity = formIdentity;
if (!Locale.ENGLISH.getLanguage().equals(locale)) {
localeFormIdentity = localeFormIdentity + "-" + locale;
}
String localeFormIdentity = getLocaleFormIdentity(context, formIdentity);

String dbFormName = StringUtils.isBlank(subFormsLocation) ? localeFormIdentity : subFormsLocation + "/" + localeFormIdentity;
ClientFormContract.Model clientForm = clientFormDao.getActiveClientFormByIdentifier(dbFormName);
Expand Down Expand Up @@ -2037,13 +2036,8 @@ public JSONObject getSubFormJsonFromRepository(@NonNull Context context, @NonNul

@Nullable
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
String localeFormIdentity = fileName;
if (!Locale.ENGLISH.getLanguage().equals(locale)) {
localeFormIdentity = localeFormIdentity + "-" + locale;
}
String localeFormIdentity = getLocaleFormIdentity(context, fileName);

ClientFormContract.Model clientForm = clientFormDao.getActiveClientFormByIdentifier(localeFormIdentity);
if (clientForm == null && StringUtils.isNotBlank(fileName) && fileName.contains("/") && !fileName.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.vijay.jsonwizard.utils;

import android.content.Context;

public class FormUtilsFactory {
public static FormUtils newInstance(){
return new FormUtils();
}

public static FormUtils noLocaleInstance(){
return new FormUtils(){
@Override
protected String getLocaleFormIdentity(Context context, String formIdentity) {
return formIdentity;
}
};
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.14.7.3-FORM-CONFIG-RULES-FIX-SNAPSHOT
VERSION_NAME=1.14.7.4-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down

0 comments on commit 1aaa7c3

Please sign in to comment.