Browse Source

Release 0.7.2.4

Aidan Follestad 10 years ago
parent
commit
06f1af8c0f

+ 1 - 1
README.md

@@ -24,7 +24,7 @@ Easily reference the library in your Android projects using this dependency in y
 
 ```Gradle
 dependencies {
-    compile 'com.afollestad:material-dialogs:0.7.2.3'
+    compile 'com.afollestad:material-dialogs:0.7.2.4'
 }
 ```
 

+ 2 - 2
library/build.gradle

@@ -9,7 +9,7 @@ android {
         minSdkVersion 8
         targetSdkVersion 22
         versionCode 1
-        versionName "0.7.2.3"
+        versionName "0.7.2.4"
     }
     lintOptions {
         abortOnError false
@@ -28,7 +28,7 @@ publish {
     userOrg = 'drummer-aidan'
     groupId = 'com.afollestad'
     artifactId = 'material-dialogs'
-    version = '0.7.2.3'
+    version = '0.7.2.4'
     description = 'A library for implementing Material design styled dialogs across all versions of Android.'
     website = 'https://github.com/afollestad/material-dialogs'
     issueTracker = "${website}/issues"

+ 1 - 16
library/src/main/java/com/afollestad/materialdialogs/DialogInit.java

@@ -371,22 +371,7 @@ class DialogInit {
         dialog.setTypeface(dialog.input, builder.regularFont);
         if (builder.inputPrefill != null)
             dialog.input.setText(builder.inputPrefill);
-        if (builder.alwaysCallInputCallback) {
-            dialog.input.addTextChangedListener(new TextWatcher() {
-                @Override
-                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-                }
-
-                @Override
-                public void onTextChanged(CharSequence s, int start, int before, int count) {
-                    dialog.mBuilder.inputCallback.onInput(dialog, s);
-                }
-
-                @Override
-                public void afterTextChanged(Editable s) {
-                }
-            });
-        }
+        dialog.setInternalInputCallback();
         dialog.input.setHint(builder.inputHint);
         dialog.input.setSingleLine();
         dialog.input.setTextColor(builder.contentColor);

+ 37 - 2
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -18,7 +18,9 @@ import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
 import android.support.v4.content.res.ResourcesCompat;
+import android.text.Editable;
 import android.text.TextUtils;
+import android.text.TextWatcher;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewTreeObserver;
@@ -381,6 +383,7 @@ public class MaterialDialog extends DialogBase implements
         protected CharSequence inputPrefill;
         protected CharSequence inputHint;
         protected InputCallback inputCallback;
+        protected boolean inputAllowEmpty;
         protected int inputType = -1;
         protected boolean alwaysCallInputCallback;
 
@@ -994,15 +997,24 @@ public class MaterialDialog extends DialogBase implements
             return this;
         }
 
-        public Builder input(CharSequence hint, CharSequence prefill, @NonNull InputCallback callback) {
+        public Builder input(CharSequence hint, CharSequence prefill, boolean allowEmptyInput, @NonNull InputCallback callback) {
             this.inputCallback = callback;
             this.inputHint = hint;
             this.inputPrefill = prefill;
+            this.inputAllowEmpty = allowEmptyInput;
             return this;
         }
 
+        public Builder input(CharSequence hint, CharSequence prefill, @NonNull InputCallback callback) {
+            return input(hint, prefill, true, callback);
+        }
+
+        public Builder input(@StringRes int hint, @StringRes int prefill, boolean allowEmptyInput, @NonNull InputCallback callback) {
+            return input(hint == 0 ? null : context.getText(hint), prefill == 0 ? null : context.getText(prefill), allowEmptyInput, callback);
+        }
+
         public Builder input(@StringRes int hint, @StringRes int prefill, @NonNull InputCallback callback) {
-            return input(hint == 0 ? null : context.getText(hint), prefill == 0 ? null : context.getText(prefill), callback);
+            return input(hint, prefill, true, callback);
         }
 
         public Builder inputType(int type) {
@@ -1346,6 +1358,29 @@ public class MaterialDialog extends DialogBase implements
         }
     }
 
+    protected void setInternalInputCallback() {
+        if (input == null) return;
+        input.addTextChangedListener(new TextWatcher() {
+            @Override
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+            }
+
+            @Override
+            public void onTextChanged(CharSequence s, int start, int before, int count) {
+                if (mBuilder.alwaysCallInputCallback)
+                    mBuilder.inputCallback.onInput(MaterialDialog.this, s);
+                if (!mBuilder.inputAllowEmpty) {
+                    final View positiveAb = getActionButton(DialogAction.POSITIVE);
+                    positiveAb.setEnabled(s.toString().trim().length() > 0);
+                }
+            }
+
+            @Override
+            public void afterTextChanged(Editable s) {
+            }
+        });
+    }
+
     @Override
     protected void onStop() {
         super.onStop();

+ 2 - 2
sample/build.gradle

@@ -17,8 +17,8 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 9
         targetSdkVersion 22
-        versionCode 112
-        versionName "0.7.2.3"
+        versionCode 113
+        versionName "0.7.2.4"
     }
     lintOptions {
         abortOnError false

BIN
sample/sample.apk


+ 1 - 1
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -600,7 +600,7 @@ public class MainActivity extends ActionBarActivity implements
                 .inputType(InputType.TYPE_CLASS_TEXT |
                         InputType.TYPE_TEXT_VARIATION_PERSON_NAME |
                         InputType.TYPE_TEXT_FLAG_CAP_WORDS)
-                .input(R.string.input_hint, 0, new MaterialDialog.InputCallback() {
+                .input(R.string.input_hint, 0, false, new MaterialDialog.InputCallback() {
                     @Override
                     public void onInput(MaterialDialog dialog, CharSequence input) {
                         showToast("Hello, " + input.toString() + "!");