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

Robert Stone git at videolan.org
Thu Nov 5 06:55:10 CET 2020


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Wed Nov  4 20:17:27 2020 -0800| [43292a0e0f27f1d1f39ee74da2599a4ee21bd3e1] | committer: Nicolas Pomepuy

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.

> https://code.videolan.org/videolan/vlc-android/commit/43292a0e0f27f1d1f39ee74da2599a4ee21bd3e1
---

 .../org/videolan/vlc/media/MediaSessionBrowser.kt  |  4 +-
 .../org/videolan/vlc/util/ThumbnailsProvider.kt    | 86 ++++++++++++----------
 2 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
index 3f8656bad..d78dfd5d2 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
@@ -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)
                     }
                 }
             }
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt b/application/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
index 1738f483a..0344d207d 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
@@ -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 at 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 at 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)



More information about the Android mailing list