[Android] Fix cover and default cover size when switching between lists and grids
Nicolas Pomepuy
git at videolan.org
Thu Dec 12 15:33:20 CET 2019
vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Dec 12 14:27:43 2019 +0000| [3129a708bde99b9904fe6e579fa04c938ea9677e] | committer: Geoffrey Métais
Fix cover and default cover size when switching between lists and grids
(cherry picked from commit 09b1c510a222a3661545737271a049ae71d9fdc4)
> https://code.videolan.org/videolan/vlc-android/commit/3129a708bde99b9904fe6e579fa04c938ea9677e
---
.../src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt | 10 ++++++----
vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt | 4 ++--
vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt | 4 ++--
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
index 8d6a482a8..a15744945 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
@@ -82,6 +82,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
private var listImageWidth: Int
val multiSelectHelper: MultiSelectHelper<MediaLibraryItem> = MultiSelectHelper(this, UPDATE_SELECTION)
private val defaultCover: BitmapDrawable?
+ private val defaultCoverCard: BitmapDrawable?
private var focusNext = -1
private var focusListener: FocusableRecyclerView.FocusListener? = null
private lateinit var inflater: LayoutInflater
@@ -97,7 +98,8 @@ class AudioBrowserAdapter @JvmOverloads constructor(
else -> VLCApplication.appContext
}
listImageWidth = ctx.resources.getDimension(R.dimen.audio_browser_item_size).toInt()
- defaultCover = getAudioIconDrawable(ctx, type, displayInCard())
+ defaultCover = getAudioIconDrawable(ctx, type, false)
+ defaultCoverCard = getAudioIconDrawable(ctx, type, true)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AbstractMediaItemViewHolder<ViewDataBinding> {
@@ -224,7 +226,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
init {
binding.holder = this
- if (defaultCover != null) binding.cover = defaultCover
+ defaultCover?.let { binding.cover = it }
if (AndroidUtil.isMarshMallowOrLater)
itemView.setOnContextClickListener { v ->
onMoreClick(v)
@@ -277,7 +279,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
init {
binding.holder = this
binding.scaleType = ImageView.ScaleType.CENTER_INSIDE
- if (defaultCover != null) binding.cover = defaultCover
+ defaultCoverCard?.let { binding.cover = it }
if (AndroidUtil.isMarshMallowOrLater)
itemView.setOnContextClickListener { v ->
onMoreClick(v)
@@ -293,7 +295,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
}
override fun recycle() {
- if (defaultCover != null) binding.cover = defaultCover
+ defaultCoverCard?.let { binding.cover = it }
binding.mediaCover.resetFade()
binding.title.isSelected = false
}
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 99ff44b06..14e9730b6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -75,7 +75,7 @@ fun loadImage(v: View, item: MediaLibraryItem?, imageWidth: Int = 0) {
val cacheKey = when {
isGroup -> "videogroup:${item.title}"
isFolder -> "folder:${item.title}"
- else -> ThumbnailsProvider.getMediaCacheKey(isMedia, item)
+ else -> ThumbnailsProvider.getMediaCacheKey(isMedia, item, imageWidth.toString())
}
val bitmap = if (cacheKey !== null) BitmapCache.getBitmapFromMemCache(cacheKey) else null
if (bitmap !== null) updateImageView(bitmap, v, binding)
@@ -244,7 +244,7 @@ private suspend fun getPlaylistImage(v: View, item: MediaLibraryItem, binding: V
var playlistImage = if (!bindChanged) {
val tracks = withContext(Dispatchers.IO) { item.tracks.toList() }
- ThumbnailsProvider.getPlaylistImage("playlist:${item.id}", tracks, width)
+ ThumbnailsProvider.getPlaylistImage("playlist:${item.id}_$width", tracks, width)
} else null
if (!bindChanged && playlistImage == null) playlistImage = UiTools.getDefaultAudioDrawable(VLCApplication.appContext).bitmap
if (!bindChanged) updateImageView(playlistImage, v, binding)
diff --git a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
index 16354aab3..4b5e74a97 100644
--- a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
@@ -61,14 +61,14 @@ object ThumbnailsProvider {
readCoverBitmap(Uri.decode(item.artworkMrl), width)
}
- fun getMediaCacheKey(isMedia: Boolean, item: MediaLibraryItem): String? {
+ fun getMediaCacheKey(isMedia: Boolean, item: MediaLibraryItem, width: String = ""): String? {
if (isMedia && (item as AbstractMediaWrapper).type == AbstractMediaWrapper.TYPE_VIDEO && TextUtils.isEmpty(item.getArtworkMrl())) {
if (appDir == null) appDir = VLCApplication.appContext.getExternalFilesDir(null)
val hasCache = appDir != null && appDir!!.exists()
if (hasCache && cacheDir == null) cacheDir = appDir!!.absolutePath + MEDIALIB_FOLDER_NAME
return if (hasCache) StringBuilder(cacheDir!!).append('/').append(item.fileName).append(".jpg").toString() else null
}
- return item.artworkMrl
+ return "${item.artworkMrl}_$width"
}
@WorkerThread
More information about the Android
mailing list