[Android] History now displays covers.

Nicolas Pomepuy git at videolan.org
Tue Feb 26 11:08:42 CET 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Feb 26 09:34:31 2019 +0100| [2c75a558e7467aeafce0b91db3b8d88bdf387471] | committer: Geoffrey Métais

History now displays covers.

> https://code.videolan.org/videolan/vlc-android/commit/2c75a558e7467aeafce0b91db3b8d88bdf387471
---

 vlc-android/res/layout/history_item.xml            | 45 ++++++++++++++--------
 .../src/org/videolan/vlc/gui/HistoryAdapter.java   | 10 +++--
 .../org/videolan/vlc/gui/helpers/ImageLoader.kt    | 18 +++++----
 3 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/vlc-android/res/layout/history_item.xml b/vlc-android/res/layout/history_item.xml
index 907b218b2..c5a5d937d 100644
--- a/vlc-android/res/layout/history_item.xml
+++ b/vlc-android/res/layout/history_item.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <layout xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:android="http://schemas.android.com/apk/res/android" >
+    xmlns:android="http://schemas.android.com/apk/res/android">
     <data>
         <import type="org.videolan.medialibrary.media.MediaWrapper"/>
         <import type="android.text.TextUtils"/>
@@ -11,6 +11,10 @@
         <variable
             name="media"
             type="MediaWrapper"/>
+
+        <variable
+            name="cover"
+            type="android.graphics.drawable.BitmapDrawable" />
         <variable
             name="bgColor"
             type="int" />
@@ -18,47 +22,54 @@
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:minHeight="@dimen/audio_browser_item_size"
         android:background="@{bgColor}"
         android:clickable="true"
         android:onClick="@{holder::onClick}"
-        android:paddingBottom="4dp"
-        android:paddingTop="4dp"
-        android:paddingLeft="@dimen/listview_side_padding"
-        android:paddingRight="@dimen/listview_side_padding"
         android:focusable="true"
         android:onLongClick="@{holder::onLongClick}"  >
+
         <ImageView
             android:id="@+id/icon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:scaleType="centerCrop"
-            android:src="@{media.type == MediaWrapper.TYPE_VIDEO ? @drawable/ic_browser_video_normal : @drawable/ic_browser_audio_normal}"
-            app:layout_constraintStart_toStartOf="parent" />
+            android:layout_width="0dp"
+            android:layout_height="@dimen/audio_browser_item_size"
+            android:layout_gravity="center"
+            android:layout_marginStart="16dp"
+            android:layout_marginTop="8dp"
+            android:layout_marginBottom="8dp"
+            android:background="@{cover}"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            app:layout_constraintDimensionRatio="1"
+            app:media="@{media}" />
 
         <TextView
             android:id="@+id/title"
+            style="@style/VLC.TextViewTitle"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:text="@{media.title}"
-            style="@style/VLC.TextViewTitle"
+            android:layout_marginStart="8dp"
             android:maxLines="1"
+            android:text="@{media.title}"
             app:layout_constraintBottom_toTopOf="@+id/subtitle"
-            app:layout_constraintTop_toTopOf="parent"
-            app:layout_constraintStart_toEndOf="@id/icon"
             app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toEndOf="@id/icon"
+            app:layout_constraintTop_toTopOf="parent"
             app:layout_constraintVertical_chainStyle="packed" />
 
         <TextView
             android:id="@+id/subtitle"
+            style="@style/VLC.TextViewDescription"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
             android:text="@{media.artist}"
-            style="@style/VLC.TextViewDescription"
             android:visibility="@{TextUtils.isEmpty(media.artist) ? View.GONE : View.VISIBLE}"
             app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintTop_toBottomOf="@id/title"
+            app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toEndOf="@id/icon"
-            app:layout_constraintEnd_toEndOf="parent"/>
+            app:layout_constraintTop_toBottomOf="@id/title" />
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 </layout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
index 9ea1e8dbf..4bba71f68 100644
--- a/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/HistoryAdapter.java
@@ -26,6 +26,7 @@ import android.view.ViewGroup;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.databinding.HistoryItemBinding;
+import org.videolan.vlc.gui.helpers.ImageLoaderKt;
 import org.videolan.vlc.gui.helpers.SelectorViewHolder;
 import org.videolan.vlc.interfaces.IEventsHandler;
 import org.videolan.vlc.util.Util;
@@ -40,6 +41,10 @@ public class HistoryAdapter extends DiffUtilAdapter<MediaWrapper, HistoryAdapter
     private IEventsHandler mEventsHandler;
     private LayoutInflater mLayoutInflater;
 
+    HistoryAdapter(IEventsHandler eventsHandler) {
+        mEventsHandler = eventsHandler;
+    }
+
     public class ViewHolder extends SelectorViewHolder<HistoryItemBinding> {
 
         public ViewHolder(HistoryItemBinding binding) {
@@ -64,9 +69,7 @@ public class HistoryAdapter extends DiffUtilAdapter<MediaWrapper, HistoryAdapter
         }
     }
 
-    HistoryAdapter(IEventsHandler eventsHandler) {
-        mEventsHandler = eventsHandler;
-    }
+
 
     List<MediaWrapper> getSelection() {
         final List<MediaWrapper> selection = new LinkedList<>();
@@ -89,6 +92,7 @@ public class HistoryAdapter extends DiffUtilAdapter<MediaWrapper, HistoryAdapter
         final MediaWrapper media = getItem(position);
         boolean isSelected = media.hasStateFlags(MediaLibraryItem.FLAG_SELECTED);
         holder.binding.setMedia(media);
+        holder.binding.setCover(ImageLoaderKt.getIconDrawableMediaWrapper(media.getType()));
         holder.selectView(isSelected);
     }
 
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 30e8d2882..2493b334e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -53,13 +53,17 @@ fun loadImage(v: View, item: MediaLibraryItem?) {
     else AppScope.launch { getImage(v, findInLibrary(item, isMedia, isGroup), binding) }
 }
 
-fun getIconDrawable(type: Int): BitmapDrawable? {
-    return when (type) {
-        MediaLibraryItem.TYPE_ALBUM -> UiTools.Resources.DEFAULT_COVER_ALBUM_DRAWABLE
-        MediaLibraryItem.TYPE_ARTIST -> UiTools.Resources.DEFAULT_COVER_ARTIST_DRAWABLE
-        MediaLibraryItem.TYPE_MEDIA -> UiTools.Resources.DEFAULT_COVER_AUDIO_DRAWABLE
-        else -> null
-    }
+fun getIconDrawable(type: Int): BitmapDrawable? = when (type) {
+    MediaLibraryItem.TYPE_ALBUM -> UiTools.Resources.DEFAULT_COVER_ALBUM_DRAWABLE
+    MediaLibraryItem.TYPE_ARTIST -> UiTools.Resources.DEFAULT_COVER_ARTIST_DRAWABLE
+    MediaLibraryItem.TYPE_MEDIA -> UiTools.Resources.DEFAULT_COVER_AUDIO_DRAWABLE
+    else -> null
+}
+
+fun getIconDrawableMediaWrapper(type: Int): BitmapDrawable? = when (type) {
+    MediaWrapper.TYPE_AUDIO -> UiTools.Resources.DEFAULT_COVER_AUDIO_DRAWABLE
+    MediaWrapper.TYPE_VIDEO -> UiTools.Resources.DEFAULT_COVER_VIDEO_DRAWABLE
+    else -> null
 }
 
 private var placeholderTvBg : Drawable? = null



More information about the Android mailing list