[Android] Fix media cache key for non indexed files

Nicolas Pomepuy git at videolan.org
Fri Sep 2 06:04:42 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Aug 12 08:05:56 2022 +0200| [5da205d7c71287f1b7b4db71922609c169a9fef8] | committer: Nicolas Pomepuy

Fix media cache key for non indexed files

Fixes #2600

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

 .../vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt   | 8 ++++++--
 .../vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt   | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index cddcd8375..1e30a2ba7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -27,7 +27,10 @@ import androidx.databinding.OnRebindCallback
 import androidx.databinding.ViewDataBinding
 import androidx.leanback.widget.ImageCardView
 import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
-import kotlinx.coroutines.*
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.isActive
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.Folder
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
@@ -74,10 +77,11 @@ fun loadImage(v: View, item: MediaLibraryItem?, imageWidth: Int = 0, tv: Boolean
     }
     val isGroup = isMedia && item.itemType == MediaLibraryItem.TYPE_VIDEO_GROUP
     val isFolder = !isMedia && item.itemType == MediaLibraryItem.TYPE_FOLDER
+    val cacheWidth = if (imageWidth != 0) imageWidth else v.width
     val cacheKey = when {
         isGroup -> "videogroup:${item.title}"
         isFolder -> "folder:${(item as Folder).mMrl.sanitizePath()}"
-        else -> ThumbnailsProvider.getMediaCacheKey(isMedia, item, imageWidth.toString())
+        else -> ThumbnailsProvider.getMediaCacheKey(isMedia, item, cacheWidth.toString())
     }
     val bitmap = if (cacheKey !== null) BitmapCache.getBitmapFromMemCache(cacheKey) else null
     if (bitmap !== null) updateImageView(bitmap, v, binding, tv = tv, card = card)
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 83bf8adaa..7b6aaa875 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
@@ -92,7 +92,7 @@ object ThumbnailsProvider {
             }
         }
         if (bitmap != null) {
-            BitmapCache.addBitmapToMemCache(thumbPath, bitmap)
+            BitmapCache.addBitmapToMemCache(getMediaCacheKey(true, media, width.toString()), bitmap)
             if (hasCache) {
                 media.setThumbnail(thumbPath)
                 BitmapUtil.saveOnDisk(bitmap, thumbPath)



More information about the Android mailing list