Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
eddmash committed Nov 23, 2017
1 parent eb7bf3b commit d43617d
Show file tree
Hide file tree
Showing 30 changed files with 455 additions and 782 deletions.
85 changes: 83 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,85 @@
<a href='https://bintray.com/eddmash/maven/validation/1.0.0/link'><img src='https://api.bintray.com/packages/eddmash/maven/validation/images/download.svg?version=1.0.0'></a>
<a href='https://bintray.com/eddmash/maven/validation?source=watch' alt='Get automatic notifications about new "validation" versions'><img src='https://www.bintray.com/docs/images/bintray_badge_color.png'></a>
# Validation
A extendable validation library for android.

Android validation library documentation!
-----------------------------------------

A lightweight and extensible android validation library.

It uses simple, straightforward validation methods with a focus on readable and concise syntax.

Installation
------------

using Maven.

```
<dependency>
<groupId>com.eddmash</groupId>
<artifactId>validation</artifactId>
<version>1.0.13</version>
<type>pom</type>
</dependency>
```

using Gradle.

```
compile 'com.eddmash:validation:1.0.13'
```

Usage
-----
Using this library boils down to this steps

- Create a validator object

```
// validator takes Context(Activity) object as argument
Validator validator = new Validator(this);
```

- Add validation checks to the validator

```
// the view objects to validate
EditText nameEditText = (EditText) view.findViewById(R.id.name);
Spinner ageSpinner = (Spinner) view.findViewById(R.id.spinner);
// ... using check objects
validator.addCheck(new NotEmptyCheck(nameEditText, "name cannot be blank");
validator.addCheck(new NotEmptyCheck(ageSpinner, "age cannot be blank");
```
`Learn more about available checks <com/eddmash/validation/checks/package-index>`

- Validate and Handle the errors


To run the validations invole the validators
`validate() <ValidatorInterface.validate()>` method.

This method returns ``true`` if the validation passed or ``false`` if the validations failed.

Incase of validation failure, the validation errors can be accessed via the
`getErrors() <ValidatorInterface.getErrors()>` method.

This library comes with a convenience `ErrorRenderer <ErrorRenderer>`, which can be used
to easily display the validation errors.

```
// the layout where we display any validation errors
LinearLayout errorSpace = (LinearLayout) findViewById(R.id.error_base);
errorSpace.removeAllViews();// clear space first
if (validator.validate()) {
// .. code to perform if validation passes
} else {
// show the errors if validation failed
// we use the renderer class to handle the display
ErrorRenderer errorRenderer = new ErrorRenderer(this, validator);
errorRenderer.render(errorSpace);
}
```
7 changes: 7 additions & 0 deletions docs/source/checks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Checks
######
.. toctree::
:maxdepth: 2
:titlesonly:

com/eddmash/validation/checks/package-index
30 changes: 30 additions & 0 deletions docs/source/com/eddmash/validation/ExampleInstrumentedTest.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. java:import:: android.content Context
.. java:import:: android.support.test InstrumentationRegistry
.. java:import:: android.support.test.runner AndroidJUnit4
.. java:import:: org.junit Test
.. java:import:: org.junit.runner RunWith
ExampleInstrumentedTest
=======================

.. java:package:: com.eddmash.validation
:noindex:

.. java:type:: @RunWith public class ExampleInstrumentedTest
Instrumentation test, which will execute on an Android device.

**See also:** \ `Testing documentation <http://d.android.com/tools/testing>`_\

Methods
-------
useAppContext
^^^^^^^^^^^^^

.. java:method:: @Test public void useAppContext() throws Exception
:outertype: ExampleInstrumentedTest

22 changes: 22 additions & 0 deletions docs/source/com/eddmash/validation/ExampleUnitTest.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. java:import:: org.junit Test
ExampleUnitTest
===============

.. java:package:: com.eddmash.validation
:noindex:

.. java:type:: public class ExampleUnitTest
Example local unit test, which will execute on the development machine (host).

**See also:** \ `Testing documentation <http://d.android.com/tools/testing>`_\

Methods
-------
addition_isCorrect
^^^^^^^^^^^^^^^^^^

.. java:method:: @Test public void addition_isCorrect() throws Exception
:outertype: ExampleUnitTest

28 changes: 28 additions & 0 deletions docs/source/com/eddmash/validation/ValidationListener.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ValidationListener
==================

.. java:package:: com.eddmash.validation
:noindex:

.. java:type:: interface ValidationListener
Interface definition for callbacks to be invoked when the validation state has changed.

Methods
-------
onValidationFailed
^^^^^^^^^^^^^^^^^^

.. java:method:: void onValidationFailed()
:outertype: ValidationListener

Invoked when validation failed

onValidationSuccess
^^^^^^^^^^^^^^^^^^^

.. java:method:: void onValidationSuccess()
:outertype: ValidationListener

Invoked when the validation passed successfully.

108 changes: 10 additions & 98 deletions docs/source/com/eddmash/validation/Validator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,8 @@
.. java:import:: android.util Log
.. java:import:: android.view View
.. java:import:: android.widget EditText
.. java:import:: android.widget Spinner
.. java:import:: android.widget TextView
.. java:import:: com.eddmash.validation.checks ValidationCheck
.. java:import:: com.eddmash.validation.utils NumericRange
.. java:import:: com.google.common.collect Range
.. java:import:: java.util ArrayList
.. java:import:: java.util Collections
Expand All @@ -28,10 +16,6 @@
.. java:import:: java.util Map
.. java:import:: java.util.regex Matcher
.. java:import:: java.util.regex Pattern
Validator
=========

Expand All @@ -40,8 +24,6 @@ Validator

.. java:type:: public class Validator implements ValidatorInterface
Performs view validation.

Constructors
------------
Validator
Expand Down Expand Up @@ -84,28 +66,10 @@ disableCheck

\ :java:ref:`see <ValidatorInterface.addCheck(ValidationCheck)>`\

disableSpinnerValidation
^^^^^^^^^^^^^^^^^^^^^^^^

.. java:method:: public void disableSpinnerValidation(View view)
:outertype: Validator

disableSpinnerValidation
^^^^^^^^^^^^^^^^^^^^^^^^

.. java:method:: public void disableSpinnerValidation(int id)
:outertype: Validator

disableValidation
^^^^^^^^^^^^^^^^^
disableValidator
^^^^^^^^^^^^^^^^

.. java:method:: public void disableValidation(int id)
:outertype: Validator

disableValidation
^^^^^^^^^^^^^^^^^

.. java:method:: public void disableValidation(View view)
.. java:method:: @Override public void disableValidator(ValidatorInterface validatorInterface)
:outertype: Validator

getErrors
Expand All @@ -117,65 +81,7 @@ getErrors
getErrorsByTag
^^^^^^^^^^^^^^

.. java:method:: public List getErrorsByTag(String tag)
:outertype: Validator

Gets a list of errors for a specific tag.

:param tag:

setSpinnerValidation
^^^^^^^^^^^^^^^^^^^^

.. java:method:: public void setSpinnerValidation(int form_province, String pattern, int form_err_blank)
:outertype: Validator

setSpinnerValidation
^^^^^^^^^^^^^^^^^^^^

.. java:method:: public void setSpinnerValidation(int form_province, String pattern, String form_err_blank)
:outertype: Validator

setSpinnerValidation
^^^^^^^^^^^^^^^^^^^^

.. java:method:: public void setSpinnerValidation(Spinner spinner, String pattern, int form_err_blank)
:outertype: Validator

setSpinnerValidation
^^^^^^^^^^^^^^^^^^^^

.. java:method:: public void setSpinnerValidation(Spinner spinner, String pattern, String form_err_blank)
:outertype: Validator

setValidation
^^^^^^^^^^^^^

.. java:method:: public void setValidation(EditText view, Range pattern, String errorMsg, boolean strict)
:outertype: Validator

setValidation
^^^^^^^^^^^^^

.. java:method:: public void setValidation(int view, Range pattern, String errorMsg, boolean strict)
:outertype: Validator

setValidation
^^^^^^^^^^^^^

.. java:method:: public void setValidation(EditText view, String pattern, String errorMsg)
:outertype: Validator

setValidation
^^^^^^^^^^^^^

.. java:method:: public void setValidation(int view, String pattern, String errorMsg)
:outertype: Validator

setValidation
^^^^^^^^^^^^^

.. java:method:: public void setValidation(int view, String pattern, int errorMsg)
.. java:method:: @Override public List getErrorsByTag(String tag)
:outertype: Validator

toString
Expand All @@ -190,3 +96,9 @@ validate
.. java:method:: @Override public boolean validate()
:outertype: Validator

validate
^^^^^^^^

.. java:method:: @Override public void validate(ValidationListener validationListener)
:outertype: Validator

0 comments on commit d43617d

Please sign in to comment.