[Android] Fix cover and default cover size when switching between lists and grids
Nicolas Pomepuy
git at videolan.org
Thu Dec 12 15:32:22 CET 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Dec 12 15:27:43 2019 +0100| [09b1c510a222a3661545737271a049ae71d9fdc4] | committer: Nicolas Pomepuy
Fix cover and default cover size when switching between lists and grids
> https://code.videolan.org/videolan/vlc-android/commit/09b1c510a222a3661545737271a049ae71d9fdc4
---
.../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 139ab6948..e0cd99d24 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 bd7bc4ac2..1cbb5e66b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -73,7 +73,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)
@@ -264,7 +264,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