Created
December 23, 2015 16:32
-
-
Save adrian-bl/fe851d510b4f1e61bca9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/ch/blinkenlights/android/vanilla/CoverCache.java b/src/ch/blinkenlights/android/vanilla/CoverCache.java | |
index 6c395ba..5efbc20 100644 | |
--- a/src/ch/blinkenlights/android/vanilla/CoverCache.java | |
+++ b/src/ch/blinkenlights/android/vanilla/CoverCache.java | |
@@ -71,6 +71,10 @@ public class CoverCache { | |
* Bitmask on how we are going to load coverart | |
*/ | |
public static int mCoverLoadMode = 0; | |
+ /** | |
+ * True if we are going to group song covers by album | |
+ */ | |
+ public static boolean mGroupCoversByAlbum = false; | |
/** | |
* Constructs a new BitmapCache object | |
@@ -92,7 +96,10 @@ public class CoverCache { | |
* @return a bitmap or null if no artwork was found | |
*/ | |
public Bitmap getCoverFromSong(Song song, int size) { | |
- CoverKey key = new CoverCache.CoverKey(MediaUtils.TYPE_ALBUM, song.albumId, size); | |
+ int keyType = (mGroupCoversByAlbum ? MediaUtils.TYPE_ALBUM : MediaUtils.TYPE_SONG); | |
+ long keyVal = (mGroupCoversByAlbum ? song.albumId : song.id); | |
+ CoverKey key = new CoverCache.CoverKey(keyType, keyVal, size); | |
+ | |
Bitmap cover = getStoredCover(key); | |
if (cover == null) { | |
cover = sBitmapDiskCache.createBitmap(song, size*size); | |
@@ -413,6 +420,7 @@ public class CoverCache { | |
ContentResolver res = mContext.getContentResolver(); | |
inputStream = res.openInputStream(uri); | |
sampleInputStream = res.openInputStream(uri); | |
+ Log.v("VanillaMusic", "Read album art of song "+song.id+" from "+uri); | |
} | |
if (inputStream != null) { | |
diff --git a/src/ch/blinkenlights/android/vanilla/LazyCoverView.java b/src/ch/blinkenlights/android/vanilla/LazyCoverView.java | |
index b7c12c8..d59053e 100644 | |
--- a/src/ch/blinkenlights/android/vanilla/LazyCoverView.java | |
+++ b/src/ch/blinkenlights/android/vanilla/LazyCoverView.java | |
@@ -31,6 +31,8 @@ import android.util.AttributeSet; | |
import android.util.LruCache; | |
import android.widget.ImageView; | |
+import android.util.Log; | |
+ | |
/** | |
* LazyCoverView implements a 'song-aware' ImageView | |
* | |
@@ -169,10 +171,18 @@ public class LazyCoverView extends ImageView | |
* Must be called from an UI thread | |
* | |
* @param type The Media type | |
- * @param id The id of this media type to query | |
+ * @param The Album ID of this item | |
+ * @param The Media ID of this item | |
*/ | |
- public void setCover(int type, long id) { | |
- mExpectedKey = new CoverCache.CoverKey(type, id, CoverCache.SIZE_SMALL); | |
+ public void setCover(long albumId, long id) { | |
+ | |
+ int keyType = (CoverCache.mGroupCoversByAlbum || id == 0 ? MediaUtils.TYPE_ALBUM : MediaUtils.TYPE_SONG); | |
+ long keyVal = (CoverCache.mGroupCoversByAlbum || id == 0 ? albumId : id); | |
+ | |
+ | |
+ mExpectedKey = new CoverCache.CoverKey(keyType, keyVal, CoverCache.SIZE_SMALL); | |
+// mExpectedKey = new CoverCache.CoverKey(type, id, CoverCache.SIZE_SMALL); | |
+Log.v("VanillaMusic", "QQ "+mExpectedKey); | |
if (drawFromCache(mExpectedKey, false) == false) { | |
CoverMsg payload = new CoverMsg(mExpectedKey, this); | |
sHandler.sendMessage(sHandler.obtainMessage(MSG_CREATE_COVER, payload)); | |
diff --git a/src/ch/blinkenlights/android/vanilla/MediaAdapter.java b/src/ch/blinkenlights/android/vanilla/MediaAdapter.java | |
index 37ff9e9..c68af4d 100644 | |
--- a/src/ch/blinkenlights/android/vanilla/MediaAdapter.java | |
+++ b/src/ch/blinkenlights/android/vanilla/MediaAdapter.java | |
@@ -140,10 +140,9 @@ public class MediaAdapter | |
*/ | |
private boolean mExpandable; | |
/** | |
- * Defines the media type to use for this entry | |
- * Setting this to MediaUtils.TYPE_INVALID disables cover artwork | |
+ * True if the view should show a cover for this adapter | |
*/ | |
- private int mCoverCacheType; | |
+ private boolean mShowCover; | |
/** | |
* Construct a MediaAdapter representing the given <code>type</code> of | |
@@ -171,7 +170,6 @@ public class MediaAdapter | |
} | |
- mCoverCacheType = MediaUtils.TYPE_INVALID; | |
String coverCacheKey = "0"; // SQL dummy entry | |
switch (type) { | |
@@ -191,8 +189,8 @@ public class MediaAdapter | |
mSongSort = MediaUtils.ALBUM_SORT; | |
mSortEntries = new int[] { R.string.name, R.string.artist_album, R.string.year, R.string.number_of_tracks, R.string.date_added }; | |
mSortValues = new String[] { "album_key %1$s", "artist_key %1$s,album_key %1$s", "minyear %1$s,album_key %1$s", "numsongs %1$s,album_key %1$s", "_id %1$s" }; | |
- mCoverCacheType = MediaUtils.TYPE_ALBUM; | |
coverCacheKey = BaseColumns._ID; | |
+ mShowCover = true; | |
break; | |
case MediaUtils.TYPE_SONG: | |
mStore = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; | |
@@ -204,8 +202,8 @@ public class MediaAdapter | |
mSortValues = new String[] { "title_key %1$s", "artist_key %1$s,album_key %1$s,track", "artist_key %1$s,album_key %1$s,title_key %1$s", | |
"artist_key %1$s,year %1$s,album_key %1$s, track", "album_key %1$s,track", | |
"year %1$s,title_key %1$s","_id %1$s", SORT_MAGIC_PLAYCOUNT }; | |
- mCoverCacheType = MediaUtils.TYPE_ALBUM; | |
coverCacheKey = MediaStore.Audio.Albums.ALBUM_ID; | |
+ mShowCover = true; | |
break; | |
case MediaUtils.TYPE_PLAYLIST: | |
mStore = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI; | |
@@ -485,7 +483,7 @@ public class MediaAdapter | |
holder.divider.setVisibility(mExpandable ? View.VISIBLE : View.GONE); | |
holder.arrow.setVisibility(mExpandable ? View.VISIBLE : View.GONE); | |
- holder.cover.setVisibility(mCoverCacheType != MediaUtils.TYPE_INVALID ? View.VISIBLE : View.GONE); | |
+ holder.cover.setVisibility(mShowCover ? View.VISIBLE : View.GONE); | |
} else { | |
holder = (ViewHolder)view.getTag(); | |
} | |
@@ -493,7 +491,6 @@ public class MediaAdapter | |
Cursor cursor = mCursor; | |
cursor.moveToPosition(position); | |
holder.id = cursor.getLong(0); | |
- long cacheId = cursor.getLong(1); | |
if (mFields.length > 2) { | |
String line1 = cursor.getString(2); | |
String line2 = cursor.getString(3); | |
@@ -512,8 +509,15 @@ public class MediaAdapter | |
holder.title = title; | |
} | |
- if (mCoverCacheType != MediaUtils.TYPE_INVALID) { | |
- holder.cover.setCover(mCoverCacheType, cacheId); | |
+ if (mShowCover) { | |
+ switch (mType) { | |
+ case MediaUtils.TYPE_SONG: | |
+ holder.cover.setCover(cursor.getLong(1), holder.id); | |
+ break; | |
+ case MediaUtils.TYPE_ALBUM: | |
+ holder.cover.setCover(holder.id, 0); | |
+ break; | |
+ } | |
} | |
return view; | |
diff --git a/src/ch/blinkenlights/android/vanilla/PlaylistAdapter.java b/src/ch/blinkenlights/android/vanilla/PlaylistAdapter.java | |
index 3d9c466..250d59c 100644 | |
--- a/src/ch/blinkenlights/android/vanilla/PlaylistAdapter.java | |
+++ b/src/ch/blinkenlights/android/vanilla/PlaylistAdapter.java | |
@@ -116,7 +116,7 @@ public class PlaylistAdapter extends CursorAdapter implements Handler.Callback { | |
textView.setTag(cursor.getLong(3)); | |
LazyCoverView cover = dview.getCoverView(); | |
- cover.setCover(MediaUtils.TYPE_ALBUM, cursor.getLong(4)); | |
+ cover.setCover(cursor.getLong(4), cursor.getLong(3)); | |
} | |
/** | |
diff --git a/src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java b/src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java | |
index 088a00c..eddd98c 100644 | |
--- a/src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java | |
+++ b/src/ch/blinkenlights/android/vanilla/ShowQueueAdapter.java | |
@@ -75,7 +75,7 @@ public class ShowQueueAdapter | |
sb.append(song.album+", "+song.artist); | |
sb.setSpan(new ForegroundColorSpan(Color.GRAY), song.title.length() + 1, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | |
row.getTextView().setText(sb); | |
- row.getCoverView().setCover(MediaUtils.TYPE_ALBUM, song.albumId); | |
+ row.getCoverView().setCover(song.albumId, song.id); | |
} | |
row.highlightRow(position == mHighlightRow); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment