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

Commit e96e858

Browse files
author
John Cordeiro
committed
Add validation for single view or specific views
1 parent 4531df3 commit e96e858

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public boolean validate() {
3535
return isAllViewsValid(viewWithValidations);
3636
}
3737

38+
public boolean validate(View view) {
39+
List<View> viewWithValidations = getViewsWithValidation(view);
40+
return isAllViewsValid(viewWithValidations);
41+
}
42+
43+
public boolean validate(List<View> views) {
44+
List<View> viewWithValidations = getViewsWithValidation(views);
45+
return isAllViewsValid(viewWithValidations);
46+
}
47+
3848
private boolean isAllViewsValid(List<View> viewWithValidations) {
3949
boolean allViewsValid = true;
4050
for (View viewWithValidation : viewWithValidations) {
@@ -78,4 +88,12 @@ private List<View> getViewsWithValidation() {
7888
}
7989
return Collections.singletonList(target.getRoot());
8090
}
91+
92+
private List<View> getViewsWithValidation(List<View> views) {
93+
return ViewTagHelper.filterViewsWithTag(R.id.validator_rule, views);
94+
}
95+
96+
private List<View> getViewsWithValidation(View view) {
97+
return ViewTagHelper.filterViewWithTag(R.id.validator_rule, view);
98+
}
8199
}

library/src/main/java/br/com/ilhasoft/support/validation/util/ViewTagHelper.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,30 @@ public static List<View> getViewsByTag(ViewGroup root, int tagId) {
3030
if (child instanceof ViewGroup) {
3131
views.addAll(getViewsByTag((ViewGroup) child, tagId));
3232
}
33+
addViewWhenContainsTag(tagId, views, child);
34+
}
35+
return views;
36+
}
3337

34-
final Object tagValue = child.getTag(tagId);
35-
if (tagValue != null) {
36-
views.add(child);
37-
}
38+
public static List<View> filterViewWithTag(int tagId, View view) {
39+
List<View> viewsWithTags = new ArrayList<>();
40+
addViewWhenContainsTag(tagId, viewsWithTags, view);
41+
return viewsWithTags;
42+
}
3843

44+
public static List<View> filterViewsWithTag(int tagId, List<View> views) {
45+
List<View> viewsWithTags = new ArrayList<>();
46+
for (View view : views) {
47+
addViewWhenContainsTag(tagId, viewsWithTags, view);
48+
}
49+
return viewsWithTags;
50+
}
51+
52+
private static void addViewWhenContainsTag(int tagId, List<View> views, View view) {
53+
final Object tagValue = view.getTag(tagId);
54+
if (tagValue != null) {
55+
views.add(view);
3956
}
40-
return views;
4157
}
4258

4359
}

0 commit comments

Comments
 (0)