[Android] Remove instanceof call in image loader

Geoffrey Métais git at videolan.org
Mon Mar 20 17:43:11 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 20 17:18:24 2017 +0100| [4f2f4262e203bea78b5d8b44275b8a601b668c6d] | committer: Geoffrey Métais

Remove instanceof call in image loader

> https://code.videolan.org/videolan/vlc-android/commit/4f2f4262e203bea78b5d8b44275b8a601b668c6d
---

 .../src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java   | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
index 19feca7..3a646f5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
@@ -94,15 +94,17 @@ public class AsyncImageLoader {
             return;
         }
         if (item.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
-            if (item instanceof MediaGroup)
-                item = ((MediaGroup) item).getFirstMedia();
-            int type = ((MediaWrapper) item).getType();
+            MediaWrapper mw = (MediaWrapper) item;
+            if (mw.getType() == MediaWrapper.TYPE_GROUP)
+                mw = ((MediaGroup)mw).getFirstMedia();
+            int type = mw.getType();
             boolean isMedia = type == MediaWrapper.TYPE_AUDIO || type == MediaWrapper.TYPE_VIDEO;
-            Uri uri = ((MediaWrapper) item).getUri();
+            Uri uri = mw.getUri();
             if (!isMedia && !(type == MediaWrapper.TYPE_DIR && "upnp".equals(uri.getScheme())))
                 return;
+            item = mw;
             if (item.getId() == 0L && (isMedia) && "file".equals(uri.getScheme())) {
-                MediaWrapper mw = VLCApplication.getMLInstance().getMedia(uri);
+                mw = VLCApplication.getMLInstance().getMedia(uri);
                 if (mw != null)
                     item = mw;
             }



More information about the Android mailing list