All Projects → Ilhasoft → Data Binding Validator

Ilhasoft / Data Binding Validator

Licence: apache-2.0
Android fields validation library based on data binding adapters.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Data Binding Validator

BakingApp
🍛🍴 This app allows a user to select a recipe and see video-guided steps for how to complete it, showcasing MVVM, Retrofit, ExoPlayer with lifecycle components, Master/Detail Flow, Widgets.
Stars: ✭ 18 (-94.78%)
Mutual labels:  databinding
Valiktor
Valiktor is a type-safe, powerful and extensible fluent DSL to validate objects in Kotlin
Stars: ✭ 267 (-22.61%)
Mutual labels:  validation-library
Easyvalidation
✔️ A text and input validation library in Kotlin for Android
Stars: ✭ 328 (-4.93%)
Mutual labels:  validation-library
modern-android
Modern Android Project Skeleton
Stars: ✭ 17 (-95.07%)
Mutual labels:  databinding
Kotlinjetpackinaction
🔥🔥 Kotlin Jetpack zero to hero. 新手到高手
Stars: ✭ 264 (-23.48%)
Mutual labels:  databinding
Tvflix
TvFlix android app using Dagger Hilt, Coroutines, Flow, KTX, Jetpack(Room, ViewModel, Paging3, Lifecycle) based on MVVM architecture purely written in Kotlin
Stars: ✭ 286 (-17.1%)
Mutual labels:  databinding
thai-citizen-id-validator
🦉 Validate Thai Citizen ID with 0 dependencies 🇹🇭
Stars: ✭ 35 (-89.86%)
Mutual labels:  validation-library
Validator Docs
Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.
Stars: ✭ 334 (-3.19%)
Mutual labels:  validation-library
Tictactoe Mvvm
Sample android application used to learn the Model View View Model pattern and DataBinding in Android
Stars: ✭ 268 (-22.32%)
Mutual labels:  databinding
Rivets
Lightweight and powerful data binding.
Stars: ✭ 3,221 (+833.62%)
Mutual labels:  databinding
T Mvp
Android AOP Architecture by Apt, AspectJ, Javassisit, based on Realm+Databinding+MVP+Retrofit+Rxjava2
Stars: ✭ 2,740 (+694.2%)
Mutual labels:  databinding
Android Mvp Mvvm Flytour
🔥🔥🔥 FlyTour是Android MVVM+MVP+Dagger2+Retrofit+RxJava+组件化+插件组成的双编码架构+双工程架构+双语言Android应用开发框架,通过不断的升级迭代该框架已经有了十个不同的版本,5.0之前工程架构采用gradle配置实现组件化,5.0之后的工程架构采用VirtualAPK实现了插件化,5.0之前采用Java编码实现,5.0之后采用Kotlin编码实现,编码架构由MVVM和MVP组成,工程架构和编码架构及编码语言开发者可根据自己具体的项目实际需求去决定选择使用,该框架是Android组件化、Android插件化、Android MVP架构、Android MVVM架构的集大成者,帮助你快速的搭建自己的App项目开发框架,以便把主要的精…
Stars: ✭ 2,948 (+754.49%)
Mutual labels:  databinding
Androidlife
📔 CaMnter's android learning life and footprint.
Stars: ✭ 293 (-15.07%)
Mutual labels:  databinding
validate-polish
Utility library for validation of PESEL, NIP, REGON, identity card etc. Aimed mostly at Polish enviroment. [Polish] Walidacja numerów pesel, nip, regon, dowodu osobistego.
Stars: ✭ 31 (-91.01%)
Mutual labels:  validation-library
Jetpack From Java To Kotlin
本项目专注于提供 Jetpack 核心组件 Java vs Kotlin 1:1 对照示例 —— This project focuses on providing comparative examples of the core components of Jetpack from Java to Kotlin.
Stars: ✭ 330 (-4.35%)
Mutual labels:  databinding
LoginMVVM
Android login application with form validation and Database storage made using MVVM and Data binding
Stars: ✭ 19 (-94.49%)
Mutual labels:  databinding
Androidstarters.com
Kickstart your next Android Application in 10 seconds.
Stars: ✭ 280 (-18.84%)
Mutual labels:  databinding
Android Jetpack Demo
🔥 快速入门Android Jetpack以及相关Kotlin、RxJava、MVVM等主流技术,独立构架App的基础技能
Stars: ✭ 335 (-2.9%)
Mutual labels:  databinding
Moko Mvvm
Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 329 (-4.64%)
Mutual labels:  databinding
Jetpack github
基于Kotlin + Jetpack全家桶 + Coroutines(协程) + Flutter等架构实现的一款精简版Github客户端项目,望与广大小伙伴一起成长,欢迎start or fork!
Stars: ✭ 314 (-8.99%)
Mutual labels:  databinding

Data Binding Validator by Ilhasoft

Release

The Data Binding Validator makes it easy and quick to validate fields in forms using data binding framework.

Download

Step 1: Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Step 2: Add the dependency

  dependencies {
    compile 'com.github.Ilhasoft:data-binding-validator:LATEST-VERSION'
  }

Latest Version: Latest version

Features:

  • Minimum/Maximum length validation for text fields;
  • Validate inputs based on field type (email, credit card, URL, CPF and so on);
  • Pre-defined error messages translated into English, Portuguese and Spanish;
  • Custom error messages by field;
  • Supports TextInputLayout and EditText;

Sample

...

Usage

Enabling Data Binding

You need to enable Data Binding to use this library, add the following code into your main module's build.gradle:

android {
    ....
    dataBinding {
        enabled = true
    }
}

Setting up validations directly on layout

It's possible to insert directly on layout creation, the validation on input fields. The error messages in different languages already are configured inside the library, not requiring the adding by developers. These are the existing validation types:

Validate Characters Length

Adding validateMinLength or validateMaxLength to your EditText, it's possible to configure a minimum or maximum characters length:

<EditText
  android:id="@+id/name"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  app:validateMinLength="@{4}"
  app:validateMaxLength="@{10}"/>

Validate Empty Characters

Adding validateEmpty, you can validate if the EditText is empty:

<EditText
  android:id="@+id/hello"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  app:validateEmpty="@{true}" />

Validate Date Patterns

Adding validateDate, you can set a pattern accepted by the EditText such as dd/MM/yyyy, yyyy and so on:

<EditText
  android:id="@+id/date"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  app:validateDate='@{"dd/MM/yyyy"}' />

Validate Regex

Adding validateRegex, you can set a regular expression to be validated, for example:

<EditText
  android:id="@+id/regex"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  app:validateRegex='@{"[a-zA-Z0-9-._]+"}'
  app:validateRegexMessage="@{@string/regexErrorMessage}" />

Validate Input Types

You can even validate input by date, for example Email, URL, Username, CreditCard, CPF, CEP and so on:

<EditText app:validateType='@{"email"}' />

<EditText app:validateType='@{"url"}' />

<EditText app:validateType='@{"creditCard"}' />

<EditText app:validateType='@{"username"}' />

<EditText app:validateType='@{"cpf"}' />

Applying Validation

It will be necessary to instantiate Validator passing as argument your ViewDataBinding instance got from your layout binding. After that you can call validate() that will return if your data is valid or not. Example:

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);
  final Validator validator = new Validator(binding);

  binding.validate.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      if (validator.validate()) {
        saveToDatabase();
      }
    }
  });
}

Or you can use toValidate() if prefer using listener to validation response:

public class YourActivity extends AppCompatActivity implements Validator.ValidationListener {

    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);
        final Validator validator = new Validator(binding);
        validator.setValidationListener(this);

        binding.validate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                validator.toValidate()
            }
        });
    }

    @Override
    public void onValidationSuccess() {
        saveToDatabase();
    }

    @Override
    public void onValidationError() {
        Toast.makeText(YourActivity.this, "Dados inválidos!", Toast.LENGTH_SHORT).show();
    }
}

Custom Error Messages

You can add custom error messages by using the same validation rule name and adding Message at the end, such as validateTypeMessage, validateDateMessage, validateRegexMessage and so on. For example:

<EditText
  android:id="@+id/date"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  app:validateDate='@{"dd/MM/yyyy"}'
  app:validateDateMessage="@{@string/dateErrorMessage}" />

Validating

If you want to validate all the fields, you can simply call validator.validate(), to validate specific views you can call validator.validate(view) or validator.validate(viewsList);

Validation modes

The validation can be applied in two way, field by field or the whole form at once. By default, it's configured field by field, however, you can call validator.enableFormValidationMode(); to enable the validation of the whole form.

If you want to come back to the default way, call validator.enableFieldValidationMode();

Auto dismiss

By default, the library prompts error messages and doens't dismiss the error automatically, however, you can add on your layout validation the same rule name by adding AutoDismiss at the end, which receives a boolean. In this case it could dismiss the error automatically. For example:

<EditText
  android:id="@+id/date"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  app:validateDate='@{"dd/MM/yyyy"}'
  app:validateDateMessage="@{@string/dateErrorMessage}"
  app:validateDateAutoDismiss="@{true}" />

License

Copyright 2017-present Ilhasoft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].