Skip to content

Commit

Permalink
Merge branch 'master' into update-release-version
Browse files Browse the repository at this point in the history
  • Loading branch information
zzainulabidin authored Jul 6, 2020
2 parents 98b2106 + ab6aa0e commit 2b79d48
Show file tree
Hide file tree
Showing 6 changed files with 620 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.rey.material.util.ViewUtil;
import com.vijay.jsonwizard.BuildConfig;
import com.vijay.jsonwizard.NativeFormLibrary;
import com.vijay.jsonwizard.R;
import com.vijay.jsonwizard.constants.JsonFormConstants;
import com.vijay.jsonwizard.customviews.ExpansionPanelGenericPopupDialog;
Expand Down Expand Up @@ -1782,11 +1783,24 @@ public String setValues(JSONArray jsonArray, String type) {
return value.replaceAll(", $", "");
}


@Nullable
public JSONObject getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull String formIdentity) {
ClientFormContract.Dao clientFormRepository = NativeFormLibrary.getInstance().getClientFormDao();
return getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, null);
}

@Nullable
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 String formIdentity, @Nullable OnFormFetchedCallback<JSONObject> onFormFetchedCallback) {
ClientFormContract.Dao clientFormRepository = NativeFormLibrary.getInstance().getClientFormDao();
getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, onFormFetchedCallback);
}

public void getFormJsonFromRepositoryOrAssets(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity, @Nullable OnFormFetchedCallback<JSONObject> onFormFetchedCallback) {
getFormJsonFromRepositoryOrAssetsWithOptionalCallback(context, clientFormRepository, formIdentity, onFormFetchedCallback);
}
Expand Down Expand Up @@ -1829,7 +1843,7 @@ public void onFormFetched(@Nullable String form) {
}

Timber.d("============%s form loaded from Assets=============", formIdentity);
JSONObject jsonObject = getFormJson(context, clientFormRepository, formIdentity);
JSONObject jsonObject = getFormJson(context, formIdentity);

if (onFormFetchedCallback != null) {
onFormFetchedCallback.onFormFetched(jsonObject);
Expand All @@ -1839,7 +1853,7 @@ public void onFormFetched(@Nullable String form) {
}
}

public JSONObject getFormJson(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, String formIdentity) {
public JSONObject getFormJson(@NonNull Context context, String formIdentity) {
if (context != null) {
try {
String locale = context.getResources().getConfiguration().locale.getLanguage();
Expand Down Expand Up @@ -1889,6 +1903,11 @@ private ClientFormContract.Model getClientFormFromRepository(@NonNull Context c
return clientForm;
}

public void handleJsonFormOrRulesError(@NonNull Context context, @NonNull String formIdentity, @NonNull OnFormFetchedCallback<String> onFormFetchedCallback) {
ClientFormContract.Dao clientFormRepository = NativeFormLibrary.getInstance().getClientFormDao();
handleJsonFormOrRulesError(context, clientFormRepository, false, formIdentity, onFormFetchedCallback);
}

public void handleJsonFormOrRulesError(@NonNull Context context, @NonNull ClientFormContract.Dao clientFormRepository, @NonNull String formIdentity, @NonNull OnFormFetchedCallback<String> onFormFetchedCallback) {
handleJsonFormOrRulesError(context, clientFormRepository, false, formIdentity, onFormFetchedCallback);
}
Expand Down Expand Up @@ -1917,7 +1936,7 @@ public void onFormSelected(@NonNull ClientFormContract.Model selectedForm) {
Timber.e(e);
}
} else {
JSONObject jsonObject = getFormJson(context, clientFormRepository, formIdentity);
JSONObject jsonObject = getFormJson(context, formIdentity);

if (jsonObject != null) {
clientForm.setJson(jsonObject.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -775,6 +777,20 @@ public static void removeGeneratedDynamicRules(JsonFormFragment formFragment) {
}
}
}


public static String formatDateToPattern(String date, String inputFormat, String outputFormat) {
if (StringUtils.isEmpty(date)) return "";
SimpleDateFormat format = new SimpleDateFormat(inputFormat);
Date newDate = null;
try {
newDate = format.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
format = new SimpleDateFormat(outputFormat);
return format.format(newDate);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.vijay.jsonwizard.utils.FormUtils;
import com.vijay.jsonwizard.utils.NativeFormLangUtils;
import com.vijay.jsonwizard.utils.NativeFormsProperties;
import com.vijay.jsonwizard.utils.Utils;
import com.vijay.jsonwizard.validators.edittext.RequiredValidator;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -72,7 +73,9 @@ private static void showDatePickerDialog(Activity context, DatePickerDialog date
context.getFragmentManager().executePendingTransactions();

String text = editText.getText().toString();
Calendar date = FormUtils.getDate(text);
Calendar date = FormUtils.getDate(StringUtils.isNoneBlank(Form.getDatePickerDisplayFormat()) ?
Utils.formatDateToPattern(text, Form.getDatePickerDisplayFormat(), DATE_FORMAT.toPattern())
: text);
if (text.isEmpty()) {
Object defaultValue = datePickerDialog.getArguments().get(JsonFormConstants.DEFAULT);
if (defaultValue != null)
Expand All @@ -85,9 +88,10 @@ private static void showDatePickerDialog(Activity context, DatePickerDialog date
}
}

@VisibleForTesting
protected void updateDateText(Context context, MaterialEditText editText, TextView duration, String date) {
editText.setText(date);
private void updateDateText(Context context, MaterialEditText editText, TextView duration, String date) {
editText.setText(StringUtils.isNoneBlank(Form.getDatePickerDisplayFormat()) ?
Utils.formatDateToPattern(date, DATE_FORMAT.toPattern(), Form.getDatePickerDisplayFormat())
: date);
String durationLabel = (String) duration.getTag(R.id.label);
if (StringUtils.isNotBlank(durationLabel)) {
Locale locale = getSetLanguage(context);
Expand Down Expand Up @@ -277,7 +281,8 @@ private void addRefreshLogicView(Context context, MaterialEditText editText, Str

private void updateEditText(MaterialEditText editText, JSONObject jsonObject, String stepName, Context context, TextView duration) throws JSONException {

SimpleDateFormat DATE_FORMAT_LOCALE = getSimpleDateFormat(context);
Locale locale = getCurrentLocale(context);
final SimpleDateFormat DATE_FORMAT_LOCALE = new SimpleDateFormat("dd-MM-yyyy", locale);

String openMrsEntityParent = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_PARENT);
String openMrsEntity = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY);
Expand Down Expand Up @@ -314,15 +319,6 @@ private void updateEditText(MaterialEditText editText, JSONObject jsonObject, St
}
}

@VisibleForTesting
protected SimpleDateFormat getSimpleDateFormat(Context context) {
Locale locale = getCurrentLocale(context);

return StringUtils.isNoneEmpty(Form.getDatePickerDisplayFormat()) ?
new SimpleDateFormat(Form.getDatePickerDisplayFormat(), locale) :
new SimpleDateFormat("dd-MM-yyyy", locale);

}

@VisibleForTesting
protected Locale getCurrentLocale(Context context) {
Expand All @@ -334,7 +330,8 @@ protected DatePickerDialog createDateDialog(final Context context, final TextVie
final DatePickerDialog datePickerDialog = new DatePickerDialog();
datePickerDialog.setContext(context);

final SimpleDateFormat DATE_FORMAT = getSimpleDateFormat(context);
Locale locale = getCurrentLocale(context);
final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy", locale);

datePickerDialog.setOnDateSetListener(new android.app.DatePickerDialog.OnDateSetListener() {
@Override
Expand Down
Loading

0 comments on commit 2b79d48

Please sign in to comment.