Skip to content

Commit

Permalink
group same artist/album combinations in lru cache
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-bl committed Jun 17, 2014
1 parent 04f29a1 commit 855a2e4
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/ch/blinkenlights/android/vanilla/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,29 @@ public class Song implements Comparable<Song> {
};

private class LruCacheKey {
Long id;
long id;
long artistId;
long albumId;
String path;

public LruCacheKey(Long id, String path) {
public LruCacheKey(long id, long artistId, long albumId, String path) {
this.id = id;
this.artistId = artistId;
this.albumId = albumId;
this.path = path;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof LruCacheKey && id.equals( ((LruCacheKey)obj).id )) {
if (obj instanceof LruCacheKey && this.albumId == ((LruCacheKey)obj).albumId && this.artistId == ((LruCacheKey)obj).artistId) {
return true;
}
return false;
}

@Override
public int hashCode() {
return this.path.length();
return (int)( 0xFFFFFF & (this.artistId + this.albumId) );
}

@Override
Expand Down Expand Up @@ -135,6 +139,7 @@ public Bitmap create(LruCacheKey key)
Log.v("VanillaMusic", "Cache miss on key "+key);
try {
ParcelFileDescriptor parcelFileDescriptor = res.openFileDescriptor(uri, "r");

if (parcelFileDescriptor != null) {
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
BitmapFactory.Options bopts = new BitmapFactory.Options();
Expand Down Expand Up @@ -304,7 +309,7 @@ public Bitmap getCover(Context context)
if (sCoverCache == null)
sCoverCache = new CoverCache(context.getApplicationContext());

LruCacheKey key = new LruCacheKey(id, path);
LruCacheKey key = new LruCacheKey(id, artistId, albumId, path);
Bitmap cover = sCoverCache.get(key);

if (cover == null)
Expand Down

0 comments on commit 855a2e4

Please sign in to comment.