Skip to content

Repository files navigation

ValidatorValue


Simple validate without IF.


Content List


Download

Add maven jitpack.io and dependencies in build.gradle (Project) :

// build.gradle projectallprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/moduledependencies {
...
implementation 'com.github.gzeinnumer:ValidatorValue:version'//required for testing
implementation 'com.github.gzeinnumer:DialogAndroid:3.0.0'
implementation 'com.github.gzeinnumer:SimpleMaterialStyle:2.0.0'
}

Feature List


Usage

Validate

  • Type 1

Return Result and use Toast as message if validate fail

btnValidate.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(Viewv) {
StringstrUsername = edUsername.getText().toString();
StringstrPassword = edPassword.getText().toString();
// If you want to hide default `Toast` use this.//ValidatorValue.with()ValidatorValue.with(getApplicationContext())
.addValue(strUsername, "Minimal 5 Character", 5)
.addValue(strPassword, "Minimal 8 Character", 8)
.validateListener(newValidatorValueResult() {
@OverridepublicvoidonSuccess() {
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
//do something
}
});
}
});

  • Type 2

Return Result and use Custom message if validate fail

btnValidate.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(Viewv) {
StringstrUsername = edUsername.getText().toString();
StringstrPassword = edPassword.getText().toString();
ValidatorValue.with(getApplicationContext())
.addValue(strUsername)
.addValue(strPassword, "Minimal 8 Character", 8)
.validateListener(newValidatorValueResult() {
@OverridepublicvoidonSuccess() {
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
}, newValidatorValueMessage() {
@OverridepublicvoidonFailed(Stringmsg) {
newInfoDialog(getSupportFragmentManager())
.setDialogType(DialogType.DialogError)
.setTitle("INFO!!!")
.setContent(msg).show();
}
});
}
});

Customize

You can customize Length and Message for validate and required length

Stringvalue = "GZeinNumer";
Stringmsg = "Username Can't Empty";
intminLength = 5;
ValidatorValue.with(getApplicationContext()).addValue(value); // msg = "Required correct value" // minLenth = 1ValidatorValue.with(getApplicationContext()).addValue(value, msg); // minLenth = 1ValidatorValue.with(getApplicationContext()).addValue(value, msg, minLength);

You can put boolean to

Stringvalue = "GZeinNumer";
booleanisValid = value.length()>0;
Stringmsg = "Username Can't Empty";
ValidatorValue.with(getApplicationContext()).addValue(isValid); // msg = "Required correct value"ValidatorValue.with(getApplicationContext()).addValue(isValid, msg);

Example Code/App

MainActivity.java & activity_main.xml

Sample Code And App


Version

  • 1.0.0
    • First Release
  • 1.1.0
    • Hide or Display Message

Contribution

You can sent your constibution to branchopen-pull.

Fore More All My Library


Copyright 2021 M. Fadli Zein

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages