From ab3d6f40332e8abaf5c6f4010071b87db5a3c8e9 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 25 May 2013 18:02:35 -0700 Subject: Never recycle the image displayed on the DownloadFragment, can cause Exceptions when going back to it after a long time --- .../src/github/daneren2005/dsub/util/ImageLoader.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java index 61f20c0a..f84116f7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ImageLoader.java @@ -56,6 +56,7 @@ public class ImageLoader implements Runnable { private Handler mHandler = new Handler(); private Context context; private LruCache cache; + private Bitmap nowPlaying; private final BlockingQueue queue; private final int imageSizeDefault; private final int imageSizeLarge; @@ -73,7 +74,7 @@ public class ImageLoader implements Runnable { @Override protected void entryRemoved(boolean evicted, String key, Bitmap oldBitmap, Bitmap newBitmap) { - if(evicted) { + if(evicted && oldBitmap != nowPlaying) { oldBitmap.recycle(); } } @@ -110,13 +111,16 @@ public class ImageLoader implements Runnable { if (bitmap != null) { final Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap); setImage(view, drawable, large); + if(large) { + nowPlaying = bitmap; + } return; } if (!large) { setUnknownImage(view, large); } - queue.offer(new Task(view.getContext(), entry, size, imageSizeLarge, new ViewTaskHandler(view, crossfade))); + queue.offer(new Task(view.getContext(), entry, size, imageSizeLarge, large, new ViewTaskHandler(view, crossfade))); } public void loadImage(Context context, RemoteControlClient remoteControl, MusicDirectory.Entry entry) { @@ -133,7 +137,7 @@ public class ImageLoader implements Runnable { } setUnknownImage(remoteControl); - queue.offer(new Task(context, entry, imageSizeLarge, imageSizeLarge, new RemoteControlClientTaskHandler(remoteControl))); + queue.offer(new Task(context, entry, imageSizeLarge, imageSizeLarge, false, new RemoteControlClientTaskHandler(remoteControl))); } private String getKey(String coverArtId, int size) { @@ -228,13 +232,15 @@ public class ImageLoader implements Runnable { private final MusicDirectory.Entry mEntry; private final int mSize; private final int mSaveSize; + private final boolean mIsNowPlaying; private ImageLoaderTaskHandler mTaskHandler; - public Task(Context context, MusicDirectory.Entry entry, int size, int saveSize, ImageLoaderTaskHandler taskHandler) { + public Task(Context context, MusicDirectory.Entry entry, int size, int saveSize, boolean isNowPlaying, ImageLoaderTaskHandler taskHandler) { mContext = context; mEntry = entry; mSize = size; mSaveSize = saveSize; + mIsNowPlaying = isNowPlaying; mTaskHandler = taskHandler; } @@ -255,6 +261,9 @@ public class ImageLoader implements Runnable { cache.put(key, bitmap); // Make sure key is the most recently "used" cache.get(key); + if(mIsNowPlaying) { + nowPlaying = bitmap; + } final Drawable drawable = Util.createDrawableFromBitmap(mContext, bitmap); mTaskHandler.setDrawable(drawable); -- cgit v1.2.3