[Android] Fix card image definition
Nicolas Pomepuy
git at videolan.org
Tue Jul 2 15:36:36 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Jul 2 15:29:21 2019 +0200| [5b7b13d14fccaf598c44a0751769681906851774] | committer: Nicolas Pomepuy
Fix card image definition
> https://code.videolan.org/videolan/vlc-android/commit/5b7b13d14fccaf598c44a0751769681906851774
---
vlc-android/res/layout/audio_browser_card_item.xml | 26 +++++++++++-----------
.../org/videolan/vlc/gui/helpers/ImageLoader.kt | 13 ++++++-----
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/vlc-android/res/layout/audio_browser_card_item.xml b/vlc-android/res/layout/audio_browser_card_item.xml
index b9774892b..81b00f9a4 100644
--- a/vlc-android/res/layout/audio_browser_card_item.xml
+++ b/vlc-android/res/layout/audio_browser_card_item.xml
@@ -59,19 +59,19 @@
<!-- Image loading is handled by org.videolan.vlc.gui.helpers.ImageLoader.loadImage() -->
<ImageView
- android:id="@+id/media_cover"
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:layout_gravity="center"
- android:background="@{cover}"
- android:visibility="@{(item.getItemType() & (MediaLibraryItem.TYPE_ALBUM|MediaLibraryItem.TYPE_ARTIST|MediaLibraryItem.TYPE_MEDIA|MediaLibraryItem.TYPE_PLAYLIST)) != 0 ? View.VISIBLE : View.GONE, default=gone}"
- tools:srcCompat="@tools:sample/avatars"
- vlc:imageWidth="@{imageWidth}"
- vlc:layout_constraintDimensionRatio="1"
- vlc:layout_constraintEnd_toEndOf="parent"
- vlc:layout_constraintStart_toStartOf="parent"
- vlc:layout_constraintTop_toTopOf="parent"
- vlc:mediaWithWidth="@{item}" />
+ android:id="@+id/media_cover"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_gravity="center"
+ android:background="@{cover}"
+ android:visibility="@{(item.getItemType() & (MediaLibraryItem.TYPE_ALBUM|MediaLibraryItem.TYPE_ARTIST|MediaLibraryItem.TYPE_MEDIA|MediaLibraryItem.TYPE_PLAYLIST)) != 0 ? View.VISIBLE : View.GONE, default=gone}"
+ tools:srcCompat="@tools:sample/avatars"
+ vlc:imageWidth="@{imageWidth}"
+ vlc:layout_constraintDimensionRatio="1"
+ vlc:layout_constraintEnd_toEndOf="parent"
+ vlc:layout_constraintStart_toStartOf="parent"
+ vlc:layout_constraintTop_toTopOf="parent"
+ vlc:media="@{item}"/>
<!-- TextView must be set to singleLine
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 02ab4ffe8..68a7073db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -41,8 +41,8 @@ private const val TAG = "ImageLoader"
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
@MainThread
- at BindingAdapter("media")
-fun loadImage(v: View, item: MediaLibraryItem?) {
+ at BindingAdapter(value = ["media", "imageWidth"], requireAll = false)
+fun loadImage(v: View, item: MediaLibraryItem?, imageWidth: Int = 0) {
if (item === null
|| item.itemType == MediaLibraryItem.TYPE_PLAYLIST)
return
@@ -56,7 +56,7 @@ fun loadImage(v: View, item: MediaLibraryItem?) {
return
}
val isGroup = isMedia && (item as AbstractMediaWrapper).type == AbstractMediaWrapper.TYPE_GROUP
- val isFolder = !isMedia && item.itemType == MediaLibraryItem.TYPE_FOLDER;
+ val isFolder = !isMedia && item.itemType == MediaLibraryItem.TYPE_FOLDER
val cacheKey = when {
isGroup -> "group:${item.title}"
isFolder -> "folder:${item.title}"
@@ -64,7 +64,7 @@ fun loadImage(v: View, item: MediaLibraryItem?) {
}
val bitmap = if (cacheKey !== null) BitmapCache.getBitmapFromMemCache(cacheKey) else null
if (bitmap !== null) updateImageView(bitmap, v, binding)
- else AppScope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding) }
+ else AppScope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding, imageWidth) }
}
@MainThread
@@ -73,7 +73,7 @@ fun loadPlaylistImageWithWidth(v: ImageView, item: MediaLibraryItem?, imageWidth
if (imageWidth == 0) return
if (item == null) return
val binding = DataBindingUtil.findBinding<ViewDataBinding>(v)
- AppScope.launch { if (item.itemType == MediaLibraryItem.TYPE_PLAYLIST) getPlaylistImage(v, item, binding, imageWidth) else loadImage(v, item) }
+ AppScope.launch { getPlaylistImage(v, item, binding, imageWidth) }
}
fun getAudioIconDrawable(context: Context?, type: Int): BitmapDrawable? = context?.let {
@@ -138,7 +138,7 @@ fun downloadIcon(v: View, imageUri: Uri?) {
}
}
-private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataBinding?) {
+private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataBinding?, imageWidth: Int = 0) {
var bindChanged = false
val rebindCallbacks = if (binding !== null) object : OnRebindCallback<ViewDataBinding>() {
override fun onPreBind(binding: ViewDataBinding): Boolean {
@@ -157,6 +157,7 @@ private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataB
}
defaultImageWidthTV
}
+ imageWidth > 0 -> imageWidth
v.width > 0 -> v.width
defaultImageWidth > 0 -> defaultImageWidth
else -> {
More information about the Android
mailing list