Browse Source

Got rid of selector caching, using the same selector references was causing weird issues.

Aidan Follestad 10 years ago
parent
commit
8290ec2a51

+ 18 - 29
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -633,44 +633,33 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         invalidateActions();
         invalidateActions();
     }
     }
 
 
-    protected Drawable mSelectorCache;
-    protected Drawable mBtnSelectorCache;
-
     private Drawable getSelector() {
     private Drawable getSelector() {
-        if (mSelectorCache == null) {
-            if (mBuilder.selector != null) {
-                // Check if builder set the selector
-                mSelectorCache = mBuilder.selector;
-            } else {
-                // If not, try to get it from the user's global theme
-                mSelectorCache = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_selector);
-            }
-            if (mSelectorCache == null) {
-                // If it's still null, get the default selector
-                mSelectorCache = DialogUtils.resolveDrawable(getContext(), R.attr.md_selector);
-            }
+        if (mBuilder.selector != null) {
+            // Check if builder set the selector
+            return mBuilder.selector;
+        } else {
+            // If not, try to get it from the user's global theme
+            Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_selector);
+            if (d != null) return d;
         }
         }
-        return mSelectorCache;
+        // If it's still null, get the default selector
+        return DialogUtils.resolveDrawable(getContext(), R.attr.md_selector);
     }
     }
 
 
     private Drawable getButtonSelector() {
     private Drawable getButtonSelector() {
         if (isStacked) {
         if (isStacked) {
             return getSelector();
             return getSelector();
         } else {
         } else {
-            if (mBtnSelectorCache == null) {
-                if (mBuilder.btnSelector != null) {
-                    // Check if builder set the selector
-                    mBtnSelectorCache = mBuilder.btnSelector;
-                } else {
-                    // If not, try to get it from the user's global theme
-                    mBtnSelectorCache = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_btn_selector);
-                }
-                if (mBtnSelectorCache == null) {
-                    // If it's still null, get the default selector
-                    mBtnSelectorCache = DialogUtils.resolveDrawable(getContext(), R.attr.md_btn_selector);
-                }
+            if (mBuilder.btnSelector != null) {
+                // Check if builder set the selector
+                return mBuilder.btnSelector;
+            } else {
+                // If not, try to get it from the user's global theme
+                Drawable d = DialogUtils.resolveDrawable(mBuilder.context, R.attr.md_btn_selector);
+                if (d != null) return d;
             }
             }
-            return mBtnSelectorCache;
+            // If it's still null, get the default selector
+            return DialogUtils.resolveDrawable(getContext(), R.attr.md_btn_selector);
         }
         }
     }
     }