Skip to content

Commit

Permalink
Merge pull request #11 from julianraj/develop
Browse files Browse the repository at this point in the history
migration to androidx + kotlin
  • Loading branch information
julianraj authored Sep 6, 2019
2 parents 6b80e8e + 312eaaa commit d0a5139
Show file tree
Hide file tree
Showing 37 changed files with 844 additions and 1,054 deletions.
31 changes: 31 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: 2

jobs:
build:
working_directory: ~/code
docker:
- image: circleci/android:api-29
environment:
JVM_OPTS: -Xmx3200m
steps:
- checkout
- restore_cache:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "validatedtextinputlayout/build.gradle" }}
# - run:
# name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
# command: sudo chmod +x ./gradlew
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle" }}-{{ checksum "validatedtextinputlayout/build.gradle" }}
- run:
name: Run Tests
command: ./gradlew runUnitTests
- store_artifacts: # for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
path: validatedtextinputlayout/build/reports
destination: reports
- store_test_results: # for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
path: validatedtextinputlayout/build/test-results
55 changes: 25 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,47 @@ ValidatedTextInputLayout [ ![Download](https://api.bintray.com/packages/julianra
## Demo ##
![Demo](./images/demo.gif)

**Note: library's package name has been corrected from validatedinputtextlayout to
validatedtextinputlayout in the latest version [You may want to update your xml files accordingly
on update]**
**Note: v1.0.0-beta1 adds migration to androidx and to kotlin from java. Upgrading to beta might
break your code.**

## Features ##
- **AutoValidation**
Validate the input field as the text changes.
`mInput.autoValidate(true);`
`input.autoValidate(true)`
If `false` you need to call the `validate()` method explicitly for validation.
OR
use xml attribute `autoValidate` as true or false.

- **AutoTrim**
`mInput.getValue()` will return the value of input field after removing leading and trailing
`input.getValue()` will return the value of input field after removing leading and trailing
white spaces

`mInput.autoTrimValue(true);`
`input.autoTrimValue(true)`
OR
use xml attribute `autoTrim` as true or false.

- **Add Validators**
You can add multiple validators to a single input field.
`mInput.addValidator(/* Your first Validator class goes here */);`
`mInput.addValidator(/* Your second Validator class goes here */);`
`input.addValidator(/* Your first Validator class goes here */)`
`input.addValidator(/* Your second Validator class goes here */)`

- **Clear Validators**
Removes all the validators associated with the input field.
`mInput.clearValidators();`
`input.clearValidators()`

- **Default Available Validators**
+ **RequiredValidator**
Validates the input field as required. i.e. empty value is not valid.
`mInput.addValidator(new RequiredValidator("Your error message"));`
`input.addValidator(RequiredValidator("Your error message"))`
OR
use xml attribute `isRequired` as true or false.
The default message will be "This field is required."
For custom message you can use xml attribute `requiredValidationMessage`

+ **LengthValidator**
Validates the input field against minimum and maximum length specified.
`mInput.addValidator(new LengthValidator(8 /* Max Length */, "Your error message"));`
`mInput.addValidator(new LengthValidator(4 /* Min Length */, *8 /* Max Length */, "Your error message"));`
`input.addValidator(LengthValidator(8 /* Max Length */, "Your error message"))`
`input.addValidator(LengthValidator(4 /* Min Length */, *8 /* Max Length */, "Your error message"))`
OR
use xml attributes `minLength` and `maxLength` with default values being "zero" and "indefinite" respectively.
The default message will be one of following
Expand All @@ -59,33 +58,29 @@ validatedtextinputlayout in the latest version [You may want to update your xml
For custom message you can use xml attribute `lengthValidationMessage`
+ **RegexValidator**
Validates the input field against provided regular expression. Equivalent to `String.matches()`
`mInput.addValidator(new RegexValidator("your_regex", "Your error message"));`
`input.addValidator(new RegexValidator("your_regex", "Your error message"))`
OR
use xml attribute `regex` to set your regular expression.
The default message will be "The field value does not match the required format."
For custom message you can use xml attribute `regexValidationMessage`
+ **DependencyValidator**
Validates the input field as per the dependency type with the input field it depends
on.
If `mInput1` depends on `mInput2` with dependency type TYPE_EQUAL: (i.e. `mInput1
.getValue()` must be equal to `mInput1.getValue()`)
`mInput1.addValidator(new DependencyValidator(mInput2, TYPE_EQUAL, "Your error
message"));`
If `input1` depends on `input2` with dependency type TYPE_EQUAL: (i.e. `input1
.getValue()` must be equal to `input1.getValue()`)
`input1.addValidator(new DependencyValidator(input2, TYPE_EQUAL, "Your error
message"))`

- **Custom Validators**
You can create your own validators to use with ValidatedTextInputLayout just by extending the `BaseValidator` class.
You need to call the `super()` method with the desired message and override `isValid()` method to return true or false;

Example: Validator class to check if field value contains character sequence "xyz"

public class MyValidator extends BaseValidator {
public MyValidator(String pErrorMessage){
super(pErrorMessage);
}
@Override
public boolean isValid(String pText){
return pText.contains("xyz");
class MyValidator(errorMessage: String,
callback: ValidationCallback? = null): BaseValidator(errorMessage, callback) {
override fun isValid(text: String): Boolean {
return text.contains("xyz")
}
}

Expand All @@ -100,13 +95,13 @@ validatedtextinputlayout in the latest version [You may want to update your xml
<dependency>
<groupId>com.julianraj</groupId>
<artifactId>validatedtextinputlayout</artifactId>
<version>0.3.0</version>
<version>1.0.0-beta1</version>
<type>pom</type>
</dependency>

- **Gradle**

compile 'com.julianraj:validatedtextinputlayout:0.3.0'
compile 'com.julianraj:validatedtextinputlayout:1.0.0-beta1'


- You can use and style it similar to **Android Design Library's** _TextInputLayout_
Expand All @@ -119,7 +114,7 @@ validatedtextinputlayout in the latest version [You may want to update your xml
validation:isRequired="true"
validation:requiredValidationMessage="Your error message here.">
<android.support.design.widget.TextInputEditText
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
Expand All @@ -136,7 +131,7 @@ validatedtextinputlayout in the latest version [You may want to update your xml
validation:maxLength="8"
validation:minLength="4">
<android.support.design.widget.TextInputEditText
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password (AutoValidated)"
Expand All @@ -153,7 +148,7 @@ validatedtextinputlayout in the latest version [You may want to update your xml
validation:regex="^[a-z0-9._%+-]+@(?:[a-z0-9-]+[.])+[a-z]{2,}$"
validation:regexValidationMessage="Your error message here">
<android.support.design.widget.TextInputEditText
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
Expand Down
23 changes: 19 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -16,13 +21,23 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

task clean(type: Delete) {
tasks.register("clean") {
delete rootProject.buildDir
}

task runUnitTests(dependsOn: [':validatedtextinputlayout:test']) {
tasks.register("runUnitTests") {
dependsOn 'validatedtextinputlayout:test'
description 'Run unit tests for the validatedtextinputlayout.'
}

//task clean(type: Delete) {
// delete rootProject.buildDir
//}
//
//task runUnitTests(dependsOn: [':validatedtextinputlayout:test']) {
// description 'Run unit tests for the validatedtextinputlayout.'
//}
20 changes: 0 additions & 20 deletions circle.yml

This file was deleted.

4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
29 changes: 20 additions & 9 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 29

defaultConfig {
applicationId "com.julianraj.validatedtextinputlayout"
minSdkVersion 9
targetSdkVersion 25
minSdkVersion 19
targetSdkVersion 29
versionCode 2
versionName "1.0"
}

compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -20,10 +27,14 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'

implementation project(':validatedtextinputlayout')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
}

compile project(':validatedtextinputlayout')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
repositories {
mavenCentral()
}
Loading

0 comments on commit d0a5139

Please sign in to comment.