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

Validate on save function on tests from 2.1.16 #642

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
@@ -1,5 +1,7 @@
package com.vijay.jsonwizard.customviews;

import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;

import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
Expand Down Expand Up @@ -37,8 +39,6 @@

import timber.log.Timber;

import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;

/**
* Performs the expansion panel's {@link com.vijay.jsonwizard.widgets.ExpansionPanelFactory} functionality, which includes
* Reading and assigning values on load
Expand Down Expand Up @@ -208,10 +208,12 @@ private void attachOkDialogButton(ViewGroup dialogView) {
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
passData();
getJsonApi().setGenericPopup(null);
getJsonApi().updateGenericPopupSecondaryValues(new JSONArray(), getStepName());
ExpansionPanelGenericPopupDialog.this.dismissAllowingStateLoss();
if (getFormFragment().saveWithoutClosingForm(false)) {
passTestData();
getJsonApi().setGenericPopup(null);
getJsonApi().updateGenericPopupSecondaryValues(new JSONArray(), getStepName());
ExpansionPanelGenericPopupDialog.this.dismissAllowingStateLoss();
}
}
});
}
Expand Down Expand Up @@ -350,7 +352,7 @@ public void setContext(Context context) throws IllegalStateException {
}

@Override
protected void passData() {
protected void passTestData() {
if (!TextUtils.isEmpty(getWidgetType()) && getWidgetType().equals(JsonFormConstants.EXPANSION_PANEL)) {
onDataPass(getParentKey(), getChildKey());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,12 @@ private void attachDialogOkButton(ViewGroup dialogView) {
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
passData();
getJsonApi().setGenericPopup(null);
getJsonApi().updateGenericPopupSecondaryValues(null, getStepName());
GenericPopupDialog.this.dismiss();
if (getFormFragment().saveWithoutClosingForm(false)) {
passTestData();
getJsonApi().setGenericPopup(null);
getJsonApi().updateGenericPopupSecondaryValues(null, getStepName());
GenericPopupDialog.this.dismiss();
}
}
});
}
Expand All @@ -431,7 +433,7 @@ public void setContext(Context context) throws IllegalStateException {
this.context = context;
}

protected void passData() {
protected void passTestData() {
onGenericDataPass(getParentKey(), getChildKey());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ public boolean save(boolean skipValidation) {

return false;
}
public boolean saveWithoutClosingForm(boolean skipValidation) {
try {
mMainView.setTag(R.id.skip_validation, skipValidation);
return presenter.onSaveWithoutClosingForm(mMainView);
} catch (Exception e) {
Timber.e(e, " --> save");
return false;
}


}

public boolean shouldSkipStep() {
return shouldSkipStep;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.vijay.jsonwizard.presenters;

import static com.vijay.jsonwizard.utils.FormUtils.dpToPixels;
import static com.vijay.jsonwizard.utils.FormUtils.getDynamicLabelInfoList;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
Expand Down Expand Up @@ -92,9 +95,6 @@

import timber.log.Timber;

import static com.vijay.jsonwizard.utils.FormUtils.dpToPixels;
import static com.vijay.jsonwizard.utils.FormUtils.getDynamicLabelInfoList;

/**
* Created by vijay on 5/14/15.
*/
Expand Down Expand Up @@ -654,6 +654,32 @@ public void onSaveClick(LinearLayout mainView) {
}
}

public boolean onSaveWithoutClosingForm(LinearLayout mainView) {
validateAndWriteValues();
checkAndStopCountdownAlarm();
boolean isFormValid = isFormValid();
if (isFormValid || Boolean.parseBoolean(mainView.getTag(R.id.skip_validation).toString())) {
Utils.removeGeneratedDynamicRules(formFragment);
Intent returnIntent = new Intent();
getView().onFormFinish();
returnIntent.putExtra("json", formUtils.addFormDetails(getView().getCurrentJsonState()));
returnIntent.putExtra(JsonFormConstants.SKIP_VALIDATION,
Boolean.valueOf(mainView.getTag(R.id.skip_validation).toString()));
return true;
} else {
if (showErrorsOnSubmit()) {
launchErrorDialog();
getView().showToast(getView().getContext().getResources()
.getString(R.string.json_form_error_msg, getInvalidFields().size()));
} else {
getView().showSnackBar(getView().getContext().getResources()
.getString(R.string.json_form_error_msg, getInvalidFields().size()));

}
return false;
}
}

public boolean showErrorsOnSubmit() {
JSONObject entireJsonForm = formFragment.getJsonApi().getmJSONObject();
return entireJsonForm.optBoolean(JsonFormConstants.SHOW_ERRORS_ON_SUBMIT, false);
Expand Down