From 900e009ed6d278c5b6b63eb1d97ec6dfe78b2d2f Mon Sep 17 00:00:00 2001 From: Joshua Bahnsen Date: Thu, 23 Jan 2014 21:18:33 -0700 Subject: [PATCH] Try to optimize image loading for AlbumView --- .../ultrasonic/androidapp/util/ImageLoader.java | 16 ++++++++++++---- .../ultrasonic/androidapp/view/AlbumView.java | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/com/thejoshwa/ultrasonic/androidapp/util/ImageLoader.java b/src/com/thejoshwa/ultrasonic/androidapp/util/ImageLoader.java index f20147b3..cfb887fe 100644 --- a/src/com/thejoshwa/ultrasonic/androidapp/util/ImageLoader.java +++ b/src/com/thejoshwa/ultrasonic/androidapp/util/ImageLoader.java @@ -149,7 +149,7 @@ public class ImageLoader implements Runnable if (bitmap != null) { - setImageBitmap(view, bitmap, crossFade); + setImageBitmap(view, entry, bitmap, crossFade); return; } @@ -193,12 +193,20 @@ public class ImageLoader implements Runnable return null; } - private void setImageBitmap(View view, Bitmap bitmap, boolean crossFade) + private void setImageBitmap(View view, MusicDirectory.Entry entry, Bitmap bitmap, boolean crossFade) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; + MusicDirectory.Entry tagEntry = (MusicDirectory.Entry) view.getTag(); + + if (entry != null && tagEntry != null && !entry.equals(tagEntry)) + { + Log.i(TAG, "Skipping entry"); + return; + } + if (crossFade) { Drawable existingDrawable = imageView.getDrawable(); @@ -227,7 +235,7 @@ public class ImageLoader implements Runnable { if (large) { - setImageBitmap(view, largeUnknownImage, false); + setImageBitmap(view, null, largeUnknownImage, false); } else { @@ -308,7 +316,7 @@ public class ImageLoader implements Runnable @Override public void run() { - setImageBitmap(view, bitmap, crossFade); + setImageBitmap(view, entry, bitmap, crossFade); } }); } diff --git a/src/com/thejoshwa/ultrasonic/androidapp/view/AlbumView.java b/src/com/thejoshwa/ultrasonic/androidapp/view/AlbumView.java index 82a719bf..b8c38319 100644 --- a/src/com/thejoshwa/ultrasonic/androidapp/view/AlbumView.java +++ b/src/com/thejoshwa/ultrasonic/androidapp/view/AlbumView.java @@ -96,6 +96,8 @@ public class AlbumView extends UpdateView public void setAlbum(final MusicDirectory.Entry album) { + viewHolder.cover_art.setTag(album); + imageLoader.loadImage(viewHolder.cover_art, album, false, 0, false, true); this.entry = album; String title = album.getTitle(); @@ -106,7 +108,6 @@ public class AlbumView extends UpdateView viewHolder.artist.setText(artist); viewHolder.artist.setVisibility(artist == null ? View.GONE : View.VISIBLE); viewHolder.star.setImageDrawable(starred ? starDrawable : starHollowDrawable); - imageLoader.loadImage(viewHolder.cover_art, album, false, 0, false, true); if (Util.isOffline(this.context) || "-1".equals(album.getId())) {