Browse Source

Gradle update, Support Library update, added extension filter to file chooser, added dialog parameter to simple list callback, etc.

Aidan Follestad 8 years ago
parent
commit
bc48329f1a

+ 1 - 1
.travis.yml

@@ -4,7 +4,7 @@ android:
   components:
     - tools
     - platform-tools
-    - build-tools-24.0.0
+    - build-tools-24.0.2
     - android-24
     - extra-android-support
     - extra-android-m2repository

+ 4 - 3
README.md

@@ -99,7 +99,7 @@ You can create basic, list, single/multi choice, progress, input, etc. dialogs w
 ```gradle
 dependencies {
 	// ... other dependencies here
-    compile 'com.afollestad.material-dialogs:core:0.9.0.1'
+    compile 'com.afollestad.material-dialogs:core:0.9.0.2'
 }
 ```
 
@@ -111,7 +111,7 @@ The *commons* module contains extensions to the library that not everyone may ne
 ```gradle
 dependencies {
     // ... other dependencies here
-    compile 'com.afollestad.material-dialogs:commons:0.9.0.1'
+    compile 'com.afollestad.material-dialogs:commons:0.9.0.2'
 }
 ```
 
@@ -1220,6 +1220,7 @@ The Builder is used like this:
 new FileChooserDialog.Builder(this)
     .initialPath("/sdcard/Download")  // changes initial path, defaults to external storage directory
     .mimeType("image/*") // Optional MIME type filter
+    .extensions(".png", ".jpg") // Optional extension filter, will override mimeType()
     .tag("optional-identifier")
     .goUpLabel("Up") // custom go up label, default label is "..."
     .show();
@@ -1295,7 +1296,7 @@ This library's implementation is just a pre-made adapter that you can pass to th
 ```java
 final MaterialSimpleListAdapter adapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
     @Override
-    public void onMaterialListItemSelected(int index, MaterialSimpleListItem item) {
+    public void onMaterialListItemSelected(MaterialDialog dialog, int index, MaterialSimpleListItem item) {
         // TODO
     }
 });

+ 1 - 1
build.gradle

@@ -3,7 +3,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.1.2'
+        classpath 'com.android.tools.build:gradle:2.2.0'
     }
 }
 

+ 3 - 3
commons/build.gradle

@@ -3,9 +3,9 @@ apply plugin: 'com.android.library'
 ext {
     PUBLISH_GROUP_ID = 'com.afollestad.material-dialogs'
     PUBLISH_ARTIFACT_ID = 'commons'
-    PUBLISH_VERSION = '0.9.0.1'
-    SUPPORT_LIBRARY_VERSION = '24.2.0'
-    BUILD_TOOLS = "24.0.0"
+    PUBLISH_VERSION = '0.9.0.2'
+    SUPPORT_LIBRARY_VERSION = '24.2.1'
+    BUILD_TOOLS = "24.0.2"
     TARGET_SDK = 24
 }
 

+ 24 - 6
commons/src/main/java/com/afollestad/materialdialogs/folderselector/FileChooserDialog.java

@@ -45,7 +45,7 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
     public FileChooserDialog() {
     }
 
-    String[] getContentsArray() {
+    CharSequence[] getContentsArray() {
         if (parentContents == null) {
             if (canGoUp)
                 return new String[]{getBuilder().mGoUpLabel};
@@ -58,7 +58,7 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
         return results;
     }
 
-    File[] listFiles(String mimeType) {
+    File[] listFiles(@Nullable String mimeType, @Nullable String[] extensions) {
         File[] contents = parentFolder.listFiles();
         List<File> results = new ArrayList<>();
         if (contents != null) {
@@ -67,8 +67,19 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
                 if (fi.isDirectory()) {
                     results.add(fi);
                 } else {
-                    if (fileIsMimeType(fi, mimeType, mimeTypeMap)) {
-                        results.add(fi);
+                    if (extensions != null) {
+                        boolean found = false;
+                        for (String ext : extensions) {
+                            if (fi.getName().toLowerCase().contains(ext.toLowerCase())) {
+                                found = true;
+                                break;
+                            }
+                        }
+                        if (found) results.add(fi);
+                    } else if (mimeType != null) {
+                        if (fileIsMimeType(fi, mimeType, mimeTypeMap)) {
+                            results.add(fi);
+                        }
                     }
                 }
             }
@@ -140,7 +151,7 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
         if (!getArguments().containsKey("current_path"))
             getArguments().putString("current_path", getBuilder().mInitialPath);
         parentFolder = new File(getArguments().getString("current_path"));
-        parentContents = listFiles(getBuilder().mMimeType);
+        parentContents = listFiles(getBuilder().mMimeType, getBuilder().mExtensions);
         return new MaterialDialog.Builder(getActivity())
                 .title(parentFolder.getAbsolutePath())
                 .items(getContentsArray())
@@ -173,7 +184,7 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
             mCallback.onFileSelection(this, parentFolder);
             dismiss();
         } else {
-            parentContents = listFiles(getBuilder().mMimeType);
+            parentContents = listFiles(getBuilder().mMimeType, getBuilder().mExtensions);
             MaterialDialog dialog = (MaterialDialog) getDialog();
             dialog.setTitle(parentFolder.getAbsolutePath());
             getArguments().putString("current_path", parentFolder.getAbsolutePath());
@@ -206,6 +217,7 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
         protected int mCancelButton;
         protected String mInitialPath;
         protected String mMimeType;
+        protected String[] mExtensions;
         protected String mTag;
         protected String mGoUpLabel;
 
@@ -237,6 +249,12 @@ public class FileChooserDialog extends DialogFragment implements MaterialDialog.
             return this;
         }
 
+        @NonNull
+        public Builder extensionsFilter(@Nullable String... extensions) {
+            mExtensions = extensions;
+            return this;
+        }
+
         @NonNull
         public Builder tag(@Nullable String tag) {
             if (tag == null)

+ 2 - 2
commons/src/main/java/com/afollestad/materialdialogs/simplelist/MaterialSimpleListAdapter.java

@@ -24,7 +24,7 @@ import java.util.List;
 public class MaterialSimpleListAdapter extends RecyclerView.Adapter<MaterialSimpleListAdapter.SimpleListVH> implements MDAdapter {
 
     public interface Callback {
-        void onMaterialListItemSelected(int index, MaterialSimpleListItem item);
+        void onMaterialListItemSelected(MaterialDialog dialog, int index, MaterialSimpleListItem item);
     }
 
     private MaterialDialog dialog;
@@ -103,7 +103,7 @@ public class MaterialSimpleListAdapter extends RecyclerView.Adapter<MaterialSimp
         @Override
         public void onClick(View view) {
             if (adapter.mCallback != null)
-                adapter.mCallback.onMaterialListItemSelected(getAdapterPosition(), adapter.getItem(getAdapterPosition()));
+                adapter.mCallback.onMaterialListItemSelected(adapter.dialog, getAdapterPosition(), adapter.getItem(getAdapterPosition()));
         }
     }
 }

+ 3 - 3
core/build.gradle

@@ -3,9 +3,9 @@ apply plugin: 'com.android.library'
 ext {
     PUBLISH_GROUP_ID = 'com.afollestad.material-dialogs'
     PUBLISH_ARTIFACT_ID = 'core'
-    PUBLISH_VERSION = '0.9.0.1'
-    SUPPORT_LIBRARY_VERSION = '24.2.0'
-    BUILD_TOOLS = "24.0.0"
+    PUBLISH_VERSION = '0.9.0.2'
+    SUPPORT_LIBRARY_VERSION = '24.2.1'
+    BUILD_TOOLS = "24.0.2"
     TARGET_SDK = 24
 }
 

+ 1 - 1
core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -756,7 +756,7 @@ public class MaterialDialog extends DialogBase implements
 
         public Builder items(@NonNull Collection collection) {
             if (collection.size() > 0) {
-                final String[] array = new String[collection.size()];
+                final CharSequence[] array = new CharSequence[collection.size()];
                 int i = 0;
                 for (Object obj : collection) {
                     array[i] = obj.toString();

+ 2 - 2
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
-#Fri Nov 28 16:53:41 CST 2014
+#Mon Sep 19 14:49:42 CDT 2016
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

+ 4 - 4
sample/build.gradle

@@ -11,9 +11,9 @@ apply plugin: 'com.android.application'
 apply plugin: 'com.neenbedankt.android-apt'
 
 ext {
-    PUBLISH_VERSION = '0.9.0.1'
-    SUPPORT_LIBRARY_VERSION = '24.2.0'
-    BUILD_TOOLS = "24.0.0"
+    PUBLISH_VERSION = '0.9.0.2'
+    SUPPORT_LIBRARY_VERSION = '24.2.1'
+    BUILD_TOOLS = "24.0.2"
     TARGET_SDK = 24
 }
 
@@ -25,7 +25,7 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 9
         targetSdkVersion TARGET_SDK
-        versionCode 166
+        versionCode 167
         versionName PUBLISH_VERSION
     }
     lintOptions {