CoverView improvements
Cancel stale pending generate jobs---these can build up if skipping songs rapidly. Avoid calling touch on worker thread---no advantage to doing so and builds up jobs. Load songs in more optimal order (current, then next, then previous).
This commit is contained in:
parent
518e16ffc4
commit
bb39b8677e
@ -317,18 +317,13 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
if (song == null || song.id == -1)
|
||||
return;
|
||||
|
||||
Bitmap bitmap = mBitmapCache.get(song.id);
|
||||
if (bitmap == null) {
|
||||
bitmap = CoverBitmap.createBitmap(getContext(), mCoverStyle, song, getWidth(), getHeight(), mBitmapCache.discardOldest());
|
||||
Bitmap bitmap = CoverBitmap.createBitmap(getContext(), mCoverStyle, song, getWidth(), getHeight(), mBitmapCache.discardOldest());
|
||||
if (bitmap != null) {
|
||||
mBitmaps[i] = bitmap;
|
||||
mBitmapCache.put(song.id, bitmap);
|
||||
} else {
|
||||
mBitmaps[i] = bitmap;
|
||||
mBitmapCache.touch(song.id);
|
||||
}
|
||||
|
||||
postInvalidate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Song at position <code>i</code> to <code>song</code>, generating
|
||||
@ -340,10 +335,16 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
if (song == null) {
|
||||
mBitmaps[i] = null;
|
||||
} else {
|
||||
mBitmaps[i] = mBitmapCache.get(song.id);
|
||||
Bitmap bitmap = mBitmapCache.get(song.id);
|
||||
if (bitmap != null) {
|
||||
mBitmaps[i] = bitmap;
|
||||
mBitmapCache.touch(song.id);
|
||||
} else {
|
||||
mBitmaps[i] = null;
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_GENERATE_BITMAP, i, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query all songs. Must be called on the UI thread.
|
||||
@ -352,8 +353,10 @@ public final class CoverView extends View implements Handler.Callback {
|
||||
*/
|
||||
public void querySongs(PlaybackService service)
|
||||
{
|
||||
for (int i = 3; --i != -1; )
|
||||
setSong(i, service.getSong(i - 1));
|
||||
mHandler.removeMessages(MSG_GENERATE_BITMAP);
|
||||
setSong(1, service.getSong(0));
|
||||
setSong(2, service.getSong(1));
|
||||
setSong(0, service.getSong(-1));
|
||||
resetScroll();
|
||||
invalidate();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user