1
0
Aidan Follestad 8 жил өмнө
parent
commit
9c5739b82a

+ 8 - 4
commons/src/main/java/com/afollestad/materialdialogs/folderselector/FolderChooserDialog.java

@@ -55,14 +55,18 @@ public class FolderChooserDialog extends DialogFragment implements MaterialDialo
 
     String[] getContentsArray() {
         if (parentContents == null) {
-            if (canGoUp)
+            if (canGoUp) {
                 return new String[]{getBuilder().goUpLabel};
+            }
             return new String[]{};
         }
         String[] results = new String[parentContents.length + (canGoUp ? 1 : 0)];
-        if (canGoUp) results[0] = "...";
-        for (int i = 0; i < parentContents.length; i++)
-            results[canGoUp ? i + 1 : i] = parentContents[i].getName();
+        if (canGoUp) {
+            results[0] = getBuilder().goUpLabel;
+        }
+        for (int i = canGoUp ? 1 : 0; i < parentContents.length; i++) {
+            results[i] = parentContents[i].getName();
+        }
         return results;
     }
 

+ 11 - 9
core/src/main/java/com/afollestad/materialdialogs/DefaultRvAdapter.java

@@ -56,8 +56,7 @@ class DefaultRvAdapter extends RecyclerView.Adapter<DefaultRvAdapter.DefaultVH>
         boolean disabled = DialogUtils.isIn(index, dialog.builder.disabledIndices);
         switch (dialog.listType) {
             case SINGLE: {
-                @SuppressLint("CutPasteId")
-                RadioButton radio = (RadioButton) holder.control;
+                @SuppressLint("CutPasteId") RadioButton radio = (RadioButton) holder.control;
                 boolean selected = dialog.builder.selectedIndex == index;
                 if (dialog.builder.choiceWidgetColor != null) {
                     MDTintHelper.setTint(radio, dialog.builder.choiceWidgetColor);
@@ -69,8 +68,7 @@ class DefaultRvAdapter extends RecyclerView.Adapter<DefaultRvAdapter.DefaultVH>
                 break;
             }
             case MULTI: {
-                @SuppressLint("CutPasteId")
-                CheckBox checkbox = (CheckBox) holder.control;
+                @SuppressLint("CutPasteId") CheckBox checkbox = (CheckBox) holder.control;
                 boolean selected = dialog.selectedIndicesList.contains(index);
                 if (dialog.builder.choiceWidgetColor != null) {
                     MDTintHelper.setTint(checkbox, dialog.builder.choiceWidgetColor);
@@ -167,22 +165,26 @@ class DefaultRvAdapter extends RecyclerView.Adapter<DefaultRvAdapter.DefaultVH>
         }
 
         @Override public void onClick(View view) {
-            if (adapter.callback != null) {
+            if (adapter.callback != null && getAdapterPosition() != RecyclerView.NO_POSITION) {
                 CharSequence text = null;
-                if (adapter.dialog.builder.items != null && getAdapterPosition() < adapter.dialog.builder.items.size())
+                if (adapter.dialog.builder.items != null &&
+                        getAdapterPosition() < adapter.dialog.builder.items.size()) {
                     text = adapter.dialog.builder.items.get(getAdapterPosition());
+                }
                 adapter.callback.onItemSelected(adapter.dialog, view, getAdapterPosition(), text, false);
             }
         }
 
         @Override public boolean onLongClick(View view) {
-            if (adapter.callback != null) {
+            if (adapter.callback != null && getAdapterPosition() != RecyclerView.NO_POSITION) {
                 CharSequence text = null;
-                if (adapter.dialog.builder.items != null && getAdapterPosition() < adapter.dialog.builder.items.size())
+                if (adapter.dialog.builder.items != null &&
+                        getAdapterPosition() < adapter.dialog.builder.items.size()) {
                     text = adapter.dialog.builder.items.get(getAdapterPosition());
+                }
                 return adapter.callback.onItemSelected(adapter.dialog, view, getAdapterPosition(), text, true);
             }
             return false;
         }
     }
-}
+}

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

@@ -55,7 +55,7 @@ class DialogInit {
     @LayoutRes static int getInflateLayout(MaterialDialog.Builder builder) {
         if (builder.customView != null) {
             return R.layout.md_dialog_custom;
-        } else if (builder.items != null && builder.items.size() > 0 || builder.adapter != null) {
+        } else if (builder.items != null || builder.adapter != null) {
             if (builder.checkBoxPrompt != null)
                 return R.layout.md_dialog_list_check;
             return R.layout.md_dialog_list;

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

@@ -772,6 +772,8 @@ public class MaterialDialog extends DialogBase implements
                     i++;
                 }
                 items(array);
+            } else if (collection.size() == 0) {
+                items = new ArrayList<>();
             }
             return this;
         }

+ 1 - 1
sample/build.gradle

@@ -49,4 +49,4 @@ dependencies {
     compile "com.android.support:gridlayout-v7:$SUPPORT_LIBRARY_VERSION"
     compile 'com.jakewharton:butterknife:8.1.0'
     annotationProcessor 'com.jakewharton:butterknife-compiler:8.1.0'
-}
+}