Browse Source

An update will go out for the sample project, to fix various crash issues and < API 10 compatibility. Library is not updated yet.

Aidan Follestad 10 years ago
parent
commit
871aac5fed

+ 8 - 15
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -22,6 +22,7 @@ import android.support.annotation.LayoutRes;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
+import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -315,6 +316,8 @@ public class MaterialDialog extends DialogBase implements
      */
     @Nullable
     private static View getBottomView(ViewGroup viewGroup) {
+        if (viewGroup == null)
+            return null;
         View bottomView = null;
         for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
             View child = viewGroup.getChildAt(i);
@@ -328,6 +331,8 @@ public class MaterialDialog extends DialogBase implements
 
     @Nullable
     private static View getTopView(ViewGroup viewGroup) {
+        if (viewGroup == null)
+            return null;
         View topView = null;
         for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
             View child = viewGroup.getChildAt(i);
@@ -340,7 +345,8 @@ public class MaterialDialog extends DialogBase implements
     }
 
     private static boolean canViewOrChildScroll(View view, boolean atBottom) {
-        /* Is the bottom view something that scrolls? */
+        if (view == null)
+            return false;
         if (view instanceof ScrollView) {
             ScrollView sv = (ScrollView) view;
             if (sv.getChildCount() == 0)
@@ -351,7 +357,7 @@ public class MaterialDialog extends DialogBase implements
             return canAdapterViewScroll((AdapterView) view);
         } else if (view instanceof WebView) {
             return canWebViewScroll((WebView) view);
-        } else if (isRecyclerView(view)) {
+        } else if (view instanceof RecyclerView) {
             return RecyclerUtil.canRecyclerViewScroll(view);
         } else {
             if (atBottom) {
@@ -362,19 +368,6 @@ public class MaterialDialog extends DialogBase implements
         }
     }
 
-    private static boolean isRecyclerView(View view) {
-        boolean isRecyclerView = false;
-        try {
-            Class.forName("android.support.v7.widget.RecyclerView");
-
-            // We got here, so now we can safely check
-            isRecyclerView = RecyclerUtil.isRecyclerView(view);
-        } catch (ClassNotFoundException ignored) {
-        }
-
-        return isRecyclerView;
-    }
-
     private static boolean canWebViewScroll(WebView view) {
         return view.getMeasuredHeight() > view.getContentHeight();
     }

+ 1 - 1
sample/build.gradle

@@ -8,7 +8,7 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 9
         targetSdkVersion 22
-        versionCode 95
+        versionCode 96
         versionName "0.6.6.1"
     }
     lintOptions {

BIN
sample/sample.apk