Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
fix the bug when validate success,the error message still take up the space.
  • Loading branch information
zillachan committed Oct 18, 2017
1 parent cdd6aab commit 708bd06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
10 changes: 5 additions & 5 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
applicationId "pub.zilla.example"
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 25
versionCode 1
versionName "1.0"

Expand All @@ -28,8 +28,8 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
// compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:8.8.1'
Expand Down
14 changes: 7 additions & 7 deletions valizilla/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.zillachan'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
// applicationId "pub.zilla.validzilla"
minSdkVersion 19
targetSdkVersion 26
versionCode 9
versionName "1.1.3"
targetSdkVersion 25
versionCode 10
versionName "1.1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -25,8 +25,8 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}

Expand Down
20 changes: 14 additions & 6 deletions valizilla/src/main/java/pub/zilla/validzilla/ValiZilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import android.support.design.widget.TextInputLayout;
import android.text.TextUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -61,18 +59,18 @@ public int compare(ValiModel o1, ValiModel o2) {
String result = targetField.getEditText().getText().toString();//result
if (TextUtils.isEmpty(model.getReg())) {//not null check fail
if (TextUtils.isEmpty(result)) {
targetField.setError(targetField.getContext().getString(model.getError()));
setError(targetField, targetField.getContext().getString(model.getError()));
invokeSuccess(target, ValiFailed.class, orders);
return;
} else {
targetField.setError("");
setError(targetField, null);
}
} else if (!result.matches(model.getReg())) {// reg check fail;
targetField.setError(targetField.getContext().getString(model.getError()));
setError(targetField, targetField.getContext().getString(model.getError()));
invokeSuccess(target, ValiFailed.class, orders);
return;
} else {
targetField.setError("");
setError(targetField, null);
}
}
} catch (IllegalAccessException e) {
Expand Down Expand Up @@ -173,4 +171,14 @@ private static ValiWapper getFieldsFromCache(Class c) {
}
return wapper;
}

private static void setError(TextInputLayout textInputLayout, String message) {
if (TextUtils.isEmpty(message)) {
textInputLayout.setError(null);
textInputLayout.setErrorEnabled(false);
} else {
textInputLayout.setError(message);
textInputLayout.setErrorEnabled(true);
}
}
}

0 comments on commit 708bd06

Please sign in to comment.