[Android] Add support for group title. Use common playlist thumbnail identifier.

Robert Stone git at videolan.org
Tue Apr 27 05:32:37 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon Apr 26 20:57:46 2021 -0700| [2b0bcc7ba580fb251713f7b92437123b9b696015] | committer: Robert Stone

Add support for group title. Use common playlist thumbnail identifier.
Optimize calls to Medialibrary.

> https://code.videolan.org/videolan/vlc-android/commit/2b0bcc7ba580fb251713f7b92437123b9b696015
---

 .../main/java/org/videolan/television/ui/TvUtil.kt |  2 +-
 .../src/org/videolan/vlc/gui/PlaylistActivity.kt   |  5 +++--
 .../org/videolan/vlc/media/MediaSessionBrowser.kt  | 24 ++++++++++------------
 3 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt b/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
index a3f6785f4..a79db877d 100644
--- a/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
@@ -347,7 +347,7 @@ fun CoroutineScope.updateBackground(activity: Activity, bm: BackgroundManager?,
             bm?.drawable = BitmapDrawable(activity.resources, blurred)
         } else if (item.itemType == MediaLibraryItem.TYPE_PLAYLIST) {
             val blurred = withContext(Dispatchers.IO) {
-                var cover: Bitmap? = ThumbnailsProvider.getPlaylistImage("playlist:${item.id}", item.tracks.toList(), 512)
+                var cover: Bitmap? = ThumbnailsProvider.getPlaylistImage("playlist:${item.id}_512", item.tracks.toList(), 512)
                         ?: return at withContext null
                 cover = cover?.let { BitmapUtil.centerCrop(it, it.width, (it.width / screenRatio).toInt()) }
                 UiTools.blurBitmap(cover, 10f)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
index b4e38c7ee..5a42b75aa 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
@@ -137,10 +137,11 @@ open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler<Med
 
         lifecycleScope.launch {
             val cover = withContext(Dispatchers.IO) {
+                val width = getScreenWidth()
                 if (!playlist.artworkMrl.isNullOrEmpty()) {
-                    AudioUtil.fetchCoverBitmap(Uri.decode(playlist.artworkMrl), getScreenWidth())
+                    AudioUtil.fetchCoverBitmap(Uri.decode(playlist.artworkMrl), width)
                 } else {
-                    ThumbnailsProvider.getPlaylistImage("playlist:${playlist.id}", playlist.tracks.toList(), getScreenWidth())
+                    ThumbnailsProvider.getPlaylistImage("playlist:${playlist.id}_$width", playlist.tracks.toList(), width)
                 }
             }
             if (cover != null) {
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 3c3b5f96c..d51dcf8ca 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
@@ -58,7 +58,6 @@ import org.videolan.vlc.extensions.ExtensionManagerService.ExtensionManagerActiv
 import org.videolan.vlc.extensions.ExtensionsManager
 import org.videolan.vlc.extensions.api.VLCExtensionItem
 import org.videolan.vlc.getFileUri
-import org.videolan.vlc.gui.helpers.AudioUtil
 import org.videolan.vlc.gui.helpers.UiTools.getDefaultAudioDrawable
 import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
 import org.videolan.vlc.isPathValid
@@ -176,7 +175,7 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                 }
                 results = extensionItems
             } else {
-                val ml by lazy(LazyThreadSafetyMode.NONE) { Medialibrary.getInstance() }
+                val ml = Medialibrary.getInstance()
                 when (parentId) {
                     ID_ROOT -> {
                         //List of Extensions
@@ -431,7 +430,6 @@ class MediaSessionBrowser : ExtensionManagerActivity {
             val artworkToUriCache = HashMap<String, Uri>()
             var results: ArrayList<MediaBrowserCompat.MediaItem> = ArrayList()
             results.ensureCapacity(list.size.coerceAtMost(MAX_RESULT_SIZE))
-            val ml by lazy(LazyThreadSafetyMode.NONE) { Medialibrary.getInstance() }
             /* Iterate over list */
             for (libraryItem in list) {
                 if (libraryItem.itemType == MediaLibraryItem.TYPE_MEDIA
@@ -459,10 +457,12 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                         item.setSubtitle(res.getString(R.string.track_number, libraryItem.tracksCount))
                     }
                     MediaLibraryItem.TYPE_ARTIST -> {
-                        item.setSubtitle(res.getQuantityString(R.plurals.albums_quantity, ml.getArtist(libraryItem.id).albumsCount, ml.getArtist(libraryItem.id).albumsCount))
+                        val albumsCount = Medialibrary.getInstance().getArtist(libraryItem.id).albumsCount
+                        item.setSubtitle(res.getQuantityString(R.plurals.albums_quantity, albumsCount, albumsCount))
                     }
                     MediaLibraryItem.TYPE_GENRE -> {
-                        item.setSubtitle(res.getQuantityString(R.plurals.albums_quantity, ml.getGenre(libraryItem.id).albumsCount, ml.getGenre(libraryItem.id).albumsCount))
+                        val albumsCount = Medialibrary.getInstance().getGenre(libraryItem.id).albumsCount
+                        item.setSubtitle(res.getQuantityString(R.plurals.albums_quantity, albumsCount, albumsCount))
                     }
                     MediaLibraryItem.TYPE_ALBUM -> {
                         if (parentId.startsWith(ARTIST_PREFIX))
@@ -485,11 +485,7 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                         MediaLibraryItem.TYPE_GENRE -> item.setIconUri(null)
                         MediaLibraryItem.TYPE_PLAYLIST -> {
                             val cover = runBlocking(Dispatchers.IO) {
-                                if (!libraryItem.artworkMrl.isNullOrEmpty()) {
-                                    AudioUtil.fetchCoverBitmap(Uri.decode(libraryItem.artworkMrl), 256)
-                                } else {
-                                    ThumbnailsProvider.getPlaylistImage("playlist:${libraryItem.id}", libraryItem.tracks.toList(), 256)
-                                }
+                                ThumbnailsProvider.getPlaylistImage("playlist:${libraryItem.id}_256", libraryItem.tracks.toList(), 256)
                             }
                             if (cover != null) item.setIconBitmap(cover) else item.setIconUri(DEFAULT_PLAYLIST_ICON)
                         }
@@ -497,10 +493,12 @@ class MediaSessionBrowser : ExtensionManagerActivity {
                     }
                 }
                 /* Set Extras */
-                when (libraryItem.itemType) {
-                    MediaLibraryItem.TYPE_ARTIST, MediaLibraryItem.TYPE_GENRE ->
-                        item.setExtras(getContentStyle(CONTENT_STYLE_GRID_ITEM_HINT_VALUE, CONTENT_STYLE_GRID_ITEM_HINT_VALUE))
+                val extras = when (libraryItem.itemType) {
+                    MediaLibraryItem.TYPE_ARTIST, MediaLibraryItem.TYPE_GENRE -> getContentStyle(CONTENT_STYLE_GRID_ITEM_HINT_VALUE, CONTENT_STYLE_GRID_ITEM_HINT_VALUE)
+                    else -> Bundle()
                 }
+                if (groupTitle != null) extras.putString(EXTRA_CONTENT_STYLE_GROUP_TITLE_HINT, groupTitle)
+                item.setExtras(extras)
                 /* Set Flags */
                 val flags = when (libraryItem.itemType) {
                     MediaLibraryItem.TYPE_MEDIA, MediaLibraryItem.TYPE_PLAYLIST -> MediaBrowserCompat.MediaItem.FLAG_PLAYABLE



More information about the Android mailing list