Skip to content
Snippets Groups Projects
Commit 43292a0e authored by Robert Stone's avatar Robert Stone Committed by Nicolas Pomepuy
Browse files

Always resize single cover art image and draw overlay icon, if specified

Consistently mosaic cover art with two tracks, one with artwork, and one without.
parent 643e31cb
No related branches found
No related tags found
1 merge request!761Android Auto Menu Structure Update and Playback Enhancement Proposal
Pipeline #35083 passed with stage
in 3 minutes and 29 seconds
......@@ -517,13 +517,13 @@ class MediaSessionBrowser : ExtensionManagerActivity {
}
if (tracks.any { it.artworkMrl != null && it.artworkMrl.isNotEmpty() }) {
cover = runBlocking(Dispatchers.IO) {
val iconAddtion = when (key) {
val iconAddition = when (key) {
"shuffleAll"-> getBitmapFromDrawable(context, R.drawable.ic_auto_shuffle_circle)
"lastAdded"-> getBitmapFromDrawable(context, R.drawable.ic_auto_new_circle)
"history"-> getBitmapFromDrawable(context, R.drawable.ic_auto_history_circle)
else -> null
}
ThumbnailsProvider.getPlaylistImage(key, tracks, 256, iconAddtion)
ThumbnailsProvider.getPlaylistImage(key, tracks, 256, iconAddition)
}
}
}
......
......@@ -119,57 +119,65 @@ object ThumbnailsProvider {
val url = mediaList[0].artworkURL
val isAllSameImage = !mediaList.any { it.artworkURL != url }
if (isAllSameImage) {
val sameImage = if (isAllSameImage) obtainBitmap(mediaList[0], width)
?: return null else null
return obtainBitmap(mediaList[0], width)
}
val artworks = ArrayList<MediaWrapper>()
for (mediaWrapper in mediaList) {
val artworkAlreadyHere = artworks.any { it.artworkURL == mediaWrapper.artworkURL }
val cs = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888)
val comboImage = Canvas(cs)
if (mediaWrapper.artworkURL != null && mediaWrapper.artworkURL.isNotBlank() && !artworkAlreadyHere) {
artworks.add(mediaWrapper)
if (sameImage != null) {
/* Scale the cover art, as obtainBitmap may return a larger or smaller image size */
comboImage.drawBitmap(sameImage, Rect(0, 0, sameImage.width, sameImage.height), Rect(0, 0, width, width), null)
} else {
val artworks = ArrayList<MediaWrapper>()
for (mediaWrapper in mediaList) {
val artworkAlreadyHere = artworks.any { it.artworkURL == mediaWrapper.artworkURL }
if (mediaWrapper.artworkURL != null && mediaWrapper.artworkURL.isNotBlank() && !artworkAlreadyHere) {
artworks.add(mediaWrapper)
}
if (artworks.size > 3) {
break
}
}
if (artworks.size > 3) {
break
if (artworks.size == 2) {
artworks.add(artworks[1])
artworks.add(artworks[0])
} else if (artworks.size == 3) {
artworks.add(artworks[0])
}
}
if (artworks.size == 2) {
artworks.add(artworks[1])
artworks.add(artworks[0])
} else if (artworks.size == 3) {
artworks.add(artworks[0])
}
val images = ArrayList<Bitmap>(4)
artworks.forEach {
val image = obtainBitmap(it, width / 2)
if (image != null) {
images.add(image)
}
if (images.size >= 4) {
return@forEach
}
val images = ArrayList<Bitmap>(4)
artworks.forEach {
val image = obtainBitmap(it, width / 2)
if (image != null) {
images.add(image)
}
if (images.size >= 4) {
return@forEach
}
}
for (i in 0..3) {
if (images.size < i + 1) {
images.add(UiTools.getDefaultAudioDrawable(AppContextProvider.appContext).bitmap)
for (i in 0..3) {
if (images.size < i + 1) {
images.add(UiTools.getDefaultAudioDrawable(AppContextProvider.appContext).bitmap)
/* Place the first image on the diagonal */
if (images.size == 3) {
images.add(images[0])
}
}
}
}
val cs = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888)
val comboImage = Canvas(cs)
comboImage.drawBitmap(images[0], Rect(0, 0, images[0].width, images[0].height), Rect(0, 0, width / 2, width / 2), null)
comboImage.drawBitmap(images[1], Rect(0, 0, images[1].width, images[1].height), Rect(width / 2, 0, width, width / 2), null)
comboImage.drawBitmap(images[2], Rect(0, 0, images[2].width, images[2].height), Rect(0, width / 2, width / 2, width), null)
comboImage.drawBitmap(images[3], Rect(0, 0, images[3].width, images[3].height), Rect(width / 2, width / 2, width, width), null)
comboImage.drawBitmap(images[0], Rect(0, 0, images[0].width, images[0].height), Rect(0, 0, width / 2, width / 2), null)
comboImage.drawBitmap(images[1], Rect(0, 0, images[1].width, images[1].height), Rect(width / 2, 0, width, width / 2), null)
comboImage.drawBitmap(images[2], Rect(0, 0, images[2].width, images[2].height), Rect(0, width / 2, width / 2, width), null)
comboImage.drawBitmap(images[3], Rect(0, 0, images[3].width, images[3].height), Rect(width / 2, width / 2, width, width), null)
}
iconAddition?.let {
comboImage.drawBitmap(iconAddition, (comboImage.width.toFloat() - iconAddition.width) / 2, (comboImage.height.toFloat() - iconAddition.height) / 2, null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment