Git Product home page Git Product logo

validotor's Introduction

Almost all applications have login fucntionality and when we try to create new project we either copy paste the code from other project and add validation for username/password. I have created this library which will validate the fields using 2-3 lines of code. You just need to pass the EditText instance of username and password to LoginBuilder class.

Step to add this import library in your project.

Add this in your root build.gradle at the end of repositories:

step 1


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

Step 2

dependencies {
	        implementation 'com.github.vinayakmestri:validotor:0.1.1'
	}

Now lets go coding

Your login.xml file would be like

<EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="50dp" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:inputType="textPassword" />

    <Button
    	android:id="@+id/loginButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="onClick"
        android:text="Login" />

Add below code in your LoginActivity.java in Onlclick event on Login button

@OnClick({R.id.loginButton})
void onClick(View view) {
// parameters username and password are the EditText intsance.

 LoginBuilder loginBuilder = LoginBuilder.getInstance().setPasswordField(password).setUsernameField(username)
                .addPasswordValidations(new ValidationBuilder().add(new TextLengthValidator(5,"Short length")).add(new EmptyValidator("Empty password")))
                .addUserNameValidations(new ValidationBuilder().add(new EmailValidator("Wrong email")).add(new EmptyValidator("Empty username"))).build();
        loginAuthBuilder.setCallBack(new ValidationCallBack() {
            @Override
            public void onSuccess(String username, String password) {
                Toast.makeText(A.this,username+ " "+password,Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(int id, String errorCode) {

                Toast.makeText(A.this,""+errorCode,Toast.LENGTH_SHORT).show();
            }

        }).login();

}

Thank you...

validotor's People

Contributors

vinayakmestri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.