[Android] Fix Playlist cover not loading

Nicolas Pomepuy git at videolan.org
Wed Jul 3 13:49:24 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Jul  3 13:44:48 2019 +0200| [5a7fd0271f19cd78509a3c332a887694931570a0] | committer: Nicolas Pomepuy

Fix Playlist cover not loading

> https://code.videolan.org/videolan/vlc-android/commit/5a7fd0271f19cd78509a3c332a887694931570a0
---

 vlc-android/res/layout/activity_media_list_tv.xml  | 23 +++++++++++-----------
 .../org/videolan/vlc/gui/helpers/ImageLoader.kt    | 16 +++++++--------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/vlc-android/res/layout/activity_media_list_tv.xml b/vlc-android/res/layout/activity_media_list_tv.xml
index 8e0d9baa8..24ec41ba6 100644
--- a/vlc-android/res/layout/activity_media_list_tv.xml
+++ b/vlc-android/res/layout/activity_media_list_tv.xml
@@ -58,18 +58,17 @@
         </FrameLayout>
 
         <ImageView
-            android:id="@+id/cover"
-            android:layout_width="0dp"
-            android:layout_height="90dp"
-            android:layout_marginStart="@dimen/tv_overscan_horizontal"
-            android:layout_marginBottom="8dp"
-            android:background="@{cover}"
-            app:imageWidth="@{imageWidth}"
-            app:layout_constraintBottom_toBottomOf="@+id/frameLayout"
-            app:layout_constraintDimensionRatio="1"
-            app:layout_constraintStart_toStartOf="parent"
-            app:mediaWithWidth="@{item}"
-            tools:srcCompat="@tools:sample/avatars" />
+                android:id="@+id/cover"
+                android:layout_width="0dp"
+                android:layout_height="90dp"
+                android:layout_marginStart="@dimen/tv_overscan_horizontal"
+                android:layout_marginBottom="8dp"
+                app:imageWidth="@{imageWidth}"
+                app:layout_constraintBottom_toBottomOf="@+id/frameLayout"
+                app:layout_constraintDimensionRatio="1"
+                app:layout_constraintStart_toStartOf="parent"
+                app:media="@{item}"
+                tools:srcCompat="@tools:sample/avatars"/>
 
         <TextView
             android:id="@+id/albumTitle"
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index 68a7073db..a6f187a38 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -43,9 +43,15 @@ private const val TAG = "ImageLoader"
 @MainThread
 @BindingAdapter(value = ["media", "imageWidth"], requireAll = false)
 fun loadImage(v: View, item: MediaLibraryItem?, imageWidth: Int = 0) {
-    if (item === null
-            || item.itemType == MediaLibraryItem.TYPE_PLAYLIST)
+    if (item === null) return
+
+    if (item.itemType == MediaLibraryItem.TYPE_PLAYLIST) {
+        if (imageWidth != 0) {
+            loadPlaylistImageWithWidth(v as ImageView, item, imageWidth)
+        }
         return
+    }
+
     val binding = DataBindingUtil.findBinding<ViewDataBinding>(v)
     if (item.itemType == MediaLibraryItem.TYPE_GENRE && !isForTV(binding)) {
         return
@@ -67,8 +73,6 @@ fun loadImage(v: View, item: MediaLibraryItem?, imageWidth: Int = 0) {
     else AppScope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding, imageWidth) }
 }
 
- at MainThread
- at BindingAdapter(value = ["bind:mediaWithWidth", "bind:imageWidth"], requireAll = true)
 fun loadPlaylistImageWithWidth(v: ImageView, item: MediaLibraryItem?, imageWidth: Int) {
     if (imageWidth == 0) return
     if (item == null) return
@@ -100,7 +104,6 @@ fun placeHolderView(v: View, item: MediaLibraryItem?) {
     } else {
         v.background = null
     }
-
 }
 
 fun isForTV(binding: ViewDataBinding?) = (binding is MediaBrowserTvItemBinding) || binding is MediaBrowserTvItemBinding
@@ -113,7 +116,6 @@ fun placeHolderImageView(v: View, item: MediaLibraryItem?) {
     } else {
         v.background = UiTools.getDefaultAudioDrawable(v.context)
     }
-
 }
 
 @BindingAdapter("icvTitle")
@@ -190,7 +192,6 @@ private suspend fun getPlaylistImage(v: View, item: MediaLibraryItem, binding: V
         binding.addOnRebindCallback(rebindCallbacks!!)
     }
 
-
     var playlistImage = if (!bindChanged) ThumbnailsProvider.getPlaylistImage("playlist:${item.id}", item.tracks.toList(), width) else null
     if (!bindChanged && playlistImage == null) playlistImage = UiTools.getDefaultAudioDrawable(VLCApplication.appContext).bitmap
     if (!bindChanged) updateImageView(playlistImage, v, binding)
@@ -198,7 +199,6 @@ private suspend fun getPlaylistImage(v: View, item: MediaLibraryItem, binding: V
     binding?.removeOnRebindCallback(rebindCallbacks!!)
 }
 
-
 @MainThread
 fun updateImageView(bitmap: Bitmap?, target: View, vdb: ViewDataBinding?) {
     if (bitmap === null || bitmap.width <= 1 || bitmap.height <= 1) return



More information about the Android mailing list