Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 00c69a2

Browse files
committed
Add simple listener to validation
1 parent 2cb73e2 commit 00c69a2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

  • library/src/main/java/br/com/ilhasoft/support/validation

library/src/main/java/br/com/ilhasoft/support/validation/Validator.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Validator {
2121
private static final int FORM_VALIDATION_MODE = 1;
2222

2323
private ViewDataBinding target;
24+
private ValidationListener validationListener;
2425

2526
private int mode = FIELD_VALIDATION_MODE;
2627
private final Set<View> disabledViews;
@@ -30,6 +31,20 @@ public Validator(ViewDataBinding target) {
3031
this.disabledViews = new HashSet<>();
3132
}
3233

34+
public void setValidationListener(ValidationListener validationListener) {
35+
this.validationListener = validationListener;
36+
}
37+
38+
public void toValidate() {
39+
if (validationListener == null) throw new IllegalArgumentException("Validation listener should not be null.");
40+
41+
if (validate()) {
42+
validationListener.onSuccess();
43+
} else {
44+
validationListener.onError();
45+
}
46+
}
47+
3348
public boolean validate() {
3449
List<View> viewWithValidations = getViewsWithValidation();
3550
return isAllViewsValid(viewWithValidations);
@@ -96,4 +111,11 @@ private <ViewType extends View> List<View> getViewsWithValidation(List<ViewType>
96111
private List<View> getViewsWithValidation(View view) {
97112
return ViewTagHelper.filterViewWithTag(R.id.validator_rule, view);
98113
}
114+
115+
public interface ValidationListener {
116+
117+
void onSuccess();
118+
119+
void onError();
120+
}
99121
}

0 commit comments

Comments
 (0)