Powerful Android Validator Crawler⚔
Validator box library that can inspect any type of form, provides multiple validation functions with an inclusion of clearing views(❁´◡`❁)
Whenever you are building any form whether it could be a survey, personal information tab or performing filtration functionality using an e-App, validation is a keen module.
Let us check what’s perspective the App and Developer see while facing the validation scenario:
App Perspective
The required view not need to be empty, the range box not exceed from upper bound limit, the selective question not mandatory to be filled or is checklist items selected or not.
Developer Perspective
Lot of views requires lot of code. OK do some calculation if we have 10 views (fields) in a form then validating a single view takes 4 LOC (lines of code) and clearing view takes 2 LOC then the total for 1 view is 6 LOC and for the whole form 10x6=60LOC 😨
Idea ⚔
Why we cannot implement crawler that can help us to iterate the whole form of any style type or views and it could be possible in only 01 LOC for Validation and 01 LOC for Clearing 😲
Exactly we’ve an android library:
Validator Crawler, that would help the developers to get two different functionalities i.e validate and clear.
Get started from validation, this library provides multiple functionality having 10+ validate functions. The user have an authority to validate whole form or even single view, procedure is described below. The view includes:
- Edittext
- RadioGroup
- Checkbox (include Multi checklist)
- Spinner
Secondly, it also provides multiple functions to clear whole form views or single view that are filled. The clearing functionality is work for all above described views including:
- Switch (Toggle)
Additional Functionality
In this library we also incorporated Edittext Picker Library so, feel free to use Edittext Picker views or if you don’t know about this library then read this article:
Huuhhh!!! lots of theory. Lets do break the ice and implement this cool library 😎
Implementation
This library will work on other support versions. But in future I only support AndroidX version.
Gradle
In project.gradle, add this code in allprojects root
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add the dependency in app.gradle:
Get the latest release from here📱
dependencies {
implementation 'com.github.AliAzaz:AndroidValidatorCrawler:X.X.X'
}
After adding dependency sync the project
Yooo… gradle work done 👍
Comparison of Past work and AndroidValidatorCrawler work
Validator part
Past Exercise
Most of the developers follow this procedure:
It’s too hectic 😣. Now, check how this library can reduce LOC.
Current Exercise
Toast is auto enabled in library, but if you don’t want to show it then pass false in last argument of any provided functions of Validator class.
If any validation error comes then the toast will show having an error string that’s captured from default string resource. First the crawler get the view id then iterate the whole string file having a tag of same view id and get the string and if it’s not available then it’ll show short message like ERROR(Empty), ERROR(Range), ERROR(Pattern) and ERROR(Invalid).
For Multi checklist, short message will show
Clearing Part
Past Exercise
Current Exercise
Cleared views are auto enabled = true after clearing, but if you want to make the fields readonly or any other scenario then pass the false in the last argument of any provided functions of Clear class.
WHAT you can say?It’s simple or not😁!!!!
Crawler provided functions
Validator Class
Clear Class
Rules need to follow
There are some rules that you need to follow while implementing this library
Not (!) Required: The crawler will not validate any view that having any of these attributes Visibility= gone, Enabled= false and Tag= -1.
Checklist (Multiple Checkbox): Put the whole checklist in viewgroup and provide Tag=0 to that viewgroup. See example here
Parent-Child Views: Sometimes there is a situation happens when a view contains another view, scenario of multi checklist example is defined below. The root view can be the checkbox or radiogroup, so you need to provide the id to root view and make this id as a Tag Id to its child viewgroup or view. By implementing this procedure the crawler can easily able to track the targeted subgroup. You can use any view type as subgroup.
That’s done! It’s too simple to implement and get the tasteful fruit 😃
Run the App on device
Running Output
Do you want to HELP this Library?
I need your help to build this library much more productive. Give Star ⭐ ️and Fork this project to contribute in it. I would appreciate your contribution.
I’m also working on this library to expand its functionality 🧐
Thanks for spending your precious time in reading this article. If you liked it then Claps 👏 multiple times to say Thanks and helps others by referring it 😊. And also read my other articles on Medium.
Connect with me on my socials and become my friend Twitter, Github and LinkedIn.