This repository was archived by the owner on Nov 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
library/src/main/java/br/com/ilhasoft/support/validation Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments