[Android] Load cone default before real cover if any

Geoffrey Métais git at videolan.org
Tue Sep 8 15:52:10 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Sep  8 15:51:36 2015 +0200| [8ac2bcf35f722e6a206cdb383b49b66626204c03] | committer: Geoffrey Métais

Load cone default before real cover if any

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=8ac2bcf35f722e6a206cdb383b49b66626204c03
---

 vlc-android/src/org/videolan/vlc/gui/AsyncImageLoader.java    |    2 +-
 .../org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java   |    1 +
 vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java     |    9 +++------
 vlc-android/src/org/videolan/vlc/util/BitmapCache.java        |    5 ++++-
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AsyncImageLoader.java b/vlc-android/src/org/videolan/vlc/gui/AsyncImageLoader.java
index d634251..76a6e9c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AsyncImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AsyncImageLoader.java
@@ -62,7 +62,7 @@ public class AsyncImageLoader {
         ImageUpdater updater = new ImageUpdater() {
             @Override
             public void updateImage(final Bitmap bitmap, View target) {
-                if (activity != null) {
+                if (bitmap != null && activity != null) {
                     activity.runOnUiThread(new Runnable() {
                         @Override
                         public void run() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index 004fa38..a9aee41 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -332,6 +332,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
             AsyncImageLoader.LoadAudioCover(fetcher, holder.binding, mContext);
         }
 
+        holder.binding.setVariable(BR.cover, AudioUtil.DEFAULT_COVER);
         holder.binding.setVariable(BR.footer, !isMediaItemAboveASeparator(position));
         holder.binding.setVariable(BR.clickable, mContextPopupMenuListener != null);
         holder.binding.setVariable(BR.handler, this);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index a5a4582..acc1adb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -20,7 +20,6 @@
 package org.videolan.vlc.gui.audio;
 
 import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
@@ -28,17 +27,15 @@ import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.CompressFormat;
 import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
 import android.media.RingtoneManager;
 import android.net.Uri;
-import android.os.Build;
 import android.provider.MediaStore;
 import android.support.annotation.RequiresPermission;
 import android.util.Log;
 import android.widget.Toast;
 
-import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.util.AndroidUtil;
-import org.videolan.libvlc.util.VLCUtil;
 import org.videolan.vlc.BuildConfig;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
@@ -84,6 +81,8 @@ public class AudioUtil {
      */
     public static String PLAYLIST_DIR = null;
 
+    public static final BitmapDrawable DEFAULT_COVER = new BitmapDrawable(VLCApplication.getAppResources(), BitmapCache.getFromResource(VLCApplication.getAppResources(), R.drawable.icon));
+
     @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS)
     public static void setRingtone(MediaWrapper song, Context context){
         File newringtone = AndroidUtil.UriToFile(song.getUri());
@@ -408,8 +407,6 @@ public class AudioUtil {
                 else if (media.getAlbum() != null)
                     testedAlbums.add(media.getAlbum());
             }
-            if (cover == null)
-                cover = BitmapCache.getFromResource(context.getResources(), R.drawable.icon);
             return cover;
         }
     }
diff --git a/vlc-android/src/org/videolan/vlc/util/BitmapCache.java b/vlc-android/src/org/videolan/vlc/util/BitmapCache.java
index 35bdbf8..18a8165 100644
--- a/vlc-android/src/org/videolan/vlc/util/BitmapCache.java
+++ b/vlc-android/src/org/videolan/vlc/util/BitmapCache.java
@@ -28,9 +28,11 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Build;
 import android.support.v4.util.LruCache;
+import android.text.TextUtils;
 import android.util.Log;
 
 import org.videolan.libvlc.util.AndroidUtil;
+import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 
 import java.lang.ref.SoftReference;
@@ -44,6 +46,7 @@ public class BitmapCache {
     public final static String TAG = "VLC/BitmapCache";
     private final static boolean LOG_ENABLED = false;
 
+    private static final String CONE_KEY = "res:"+ R.drawable.cone;
     private static BitmapCache mInstance;
     private final LruCache<String, SoftReference<Bitmap>> mMemCache;
     Set<SoftReference<Bitmap>> mCachedBitmaps;
@@ -82,7 +85,7 @@ public class BitmapCache {
             protected void entryRemoved(boolean evicted, String key, SoftReference<Bitmap> oldValue, SoftReference<Bitmap> newValue) {
                 if (evicted) {
                     mCachedBitmaps.remove(oldValue);
-                    if (oldValue.get() != null)
+                    if (oldValue.get() != null && !TextUtils.equals(key, CONE_KEY))
                         addReusableBitmapRef(oldValue);
                 }
             }



More information about the Android mailing list