Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingtoncosta committed Apr 3, 2018
1 parent d4da134 commit 94b3050
Showing 1 changed file with 10 additions and 74 deletions.
84 changes: 10 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,15 @@ Convalida is a simple, lightweight and powerful field validation library for And

## Why Convalida?

- Annotation-based;
- You can use with annotations or with data binding;
- Compile-time;
- Compatible with other annotation-based libraries and frameworks such as [ButterKnife][1], [AndroidAnnotations][2], etc;
- Compatible with other popular libraries such as [ButterKnife][1], [Android Data Binding][2], [Dagger 2][3], etc;
- Works with **Stock Android Widgets**;
- Based on [Material Design Error Patterns][4];

## Quick Start
## Documentation

**Step 1** - Annotate your fields with [Convalida Annotations][3]:

```java
@RequiredValidation(R.string.field_required)
EditText nameField;

@LengthValidation(min = 3, errorMessage = R.string.min_3_characters)
EditText nickNameField;

@OnlyNumberValidation(R.string.only_numbers)
EditText ageField;

@EmailValidation(R.string.invalid_email)
EditText emailField;

@ConfirmEmailValidation(R.string.emails_not_match)
EditText confirmEmailField;

@PatternValidation(errorMessage = R.string.invalid_phone, pattern = PHONE_PATTERN)
EditText phoneField;

@PasswordValidation(min = 3, pattern = MIXED_CASE_NUMERIC, errorMessage = R.string.invalid_password)
EditText passwordField;

@ConfirmPasswordValidation(R.string.passwords_not_match)
EditText confirmPasswordField;

@ValidateOnClick
Button validateButton;
```

**Step 2** - Initialize Convalida (notice that the it starts with the same name of the Activity):

```java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
SampleActivityFieldsValidation.init(this);
}
```

**Step 3** - Run the validations by clicking in the button mapped with `@ValidateOnClick` and handle success or error:

```java
@OnValidationSuccess
public void onValidationSuccess() {
Toast.makeText("Yay!", Toast.LENGTH_LONG).show();
}

@OnValidationError
public void error() {
Toast.makeText("Something is wrong :(", Toast.LENGTH_LONG).show();
}
```

_Note: Only the method annotated with `@OnValidationSuccess` is required._

**Step 4** - If you want to clear the validations:

```java
@ClearValidationsOnClick
Button clearValidationsButton;
```

**Remember: You must initialize the views (e.g [ButterKnife][1]) before apply the validations.**
See the [wiki][5] for more information.

## Download

Expand All @@ -90,7 +25,6 @@ Button clearValidationsButton;
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Expand All @@ -100,8 +34,8 @@ allprojects {

```groovy
dependencies {
 compile 'com.github.WellingtonCosta.convalida:convalida:1.3.7'
 annotationProcessor 'com.github.WellingtonCosta.convalida:convalida-compiler:1.3.7'
 implementation 'com.github.WellingtonCosta.convalida:convalida:2.0.0'
 annotationProcessor 'com.github.WellingtonCosta.convalida:convalida-compiler:2.0.0'
}
```

Expand All @@ -123,8 +57,10 @@ dependencies {

[1]: https://github.com/JakeWharton/butterknife

[2]: https://github.com/androidannotations/androidannotations
[2]: https://developer.android.com/topic/libraries/data-binding/index.html

[3]: https://github.com/WellingtonCosta/convalida/tree/master/convalida-annotations/src/main/java/convalida/annotations
[3]: https://github.com/google/dagger

[4]: https://material.io/guidelines/patterns/errors.html

[5]: https://github.com/WellingtonCosta/convalida/wiki

0 comments on commit 94b3050

Please sign in to comment.