Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow getting forms from db without appending locale #586

Merged
merged 4 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,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 FormUtils.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
Expand Up @@ -8,7 +8,7 @@
/**
* Created by keyman on 04/12/2018.
*/
public class JsonWizardFormActivity extends JsonFormActivity {
public class JsonWizardFormActivity extends FormConfigurationJsonFormActivity {

@Override
public void initializeFormFragment() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.vijay.jsonwizard.activities;

import com.vijay.jsonwizard.utils.FormUtils;

public class NoLocaleJsonWizardFormActivity extends JsonWizardFormActivity {
@Override
protected FormUtils getFormUtils() {
return FormUtils.newInstanceWithNoLocale();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ public class FormUtils {
private Utils utils = new Utils();
private GenericDialogInterface genericDialogInterface;

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

public static FormUtils newInstanceWithNoLocale(){
LZRS marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down Expand Up @@ -1979,13 +1992,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 @@ -2061,13 +2078,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 @@ -2098,13 +2110,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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.1.0-SNAPSHOT
VERSION_NAME=2.1.1-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down