Try to optimize image loading for AlbumView

This commit is contained in:
Joshua Bahnsen 2014-01-23 21:18:33 -07:00
parent bc114521c4
commit 900e009ed6
2 changed files with 14 additions and 5 deletions

View File

@ -149,7 +149,7 @@ public class ImageLoader implements Runnable
if (bitmap != null) if (bitmap != null)
{ {
setImageBitmap(view, bitmap, crossFade); setImageBitmap(view, entry, bitmap, crossFade);
return; return;
} }
@ -193,12 +193,20 @@ public class ImageLoader implements Runnable
return null; 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) if (view instanceof ImageView)
{ {
ImageView imageView = (ImageView) view; 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) if (crossFade)
{ {
Drawable existingDrawable = imageView.getDrawable(); Drawable existingDrawable = imageView.getDrawable();
@ -227,7 +235,7 @@ public class ImageLoader implements Runnable
{ {
if (large) if (large)
{ {
setImageBitmap(view, largeUnknownImage, false); setImageBitmap(view, null, largeUnknownImage, false);
} }
else else
{ {
@ -308,7 +316,7 @@ public class ImageLoader implements Runnable
@Override @Override
public void run() public void run()
{ {
setImageBitmap(view, bitmap, crossFade); setImageBitmap(view, entry, bitmap, crossFade);
} }
}); });
} }

View File

@ -96,6 +96,8 @@ public class AlbumView extends UpdateView
public void setAlbum(final MusicDirectory.Entry album) 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; this.entry = album;
String title = album.getTitle(); String title = album.getTitle();
@ -106,7 +108,6 @@ public class AlbumView extends UpdateView
viewHolder.artist.setText(artist); viewHolder.artist.setText(artist);
viewHolder.artist.setVisibility(artist == null ? View.GONE : View.VISIBLE); viewHolder.artist.setVisibility(artist == null ? View.GONE : View.VISIBLE);
viewHolder.star.setImageDrawable(starred ? starDrawable : starHollowDrawable); 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())) if (Util.isOffline(this.context) || "-1".equals(album.getId()))
{ {