[Android] Video list items visual selection

Geoffrey Métais git at videolan.org
Fri Nov 18 14:02:03 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov 18 11:27:13 2016 +0100| [07fe050d265f7efee5aa0436453dee565a713baf] | committer: Geoffrey Métais

Video list items visual selection

> https://code.videolan.org/videolan/vlc-android/commit/07fe050d265f7efee5aa0436453dee565a713baf
---

 vlc-android/res/layout/video_list_card.xml         | 114 +++++++++++----------
 .../videolan/vlc/gui/video/VideoListAdapter.java   |   3 +
 2 files changed, 64 insertions(+), 53 deletions(-)

diff --git a/vlc-android/res/layout/video_list_card.xml b/vlc-android/res/layout/video_list_card.xml
index ce42a40..a613d73 100644
--- a/vlc-android/res/layout/video_list_card.xml
+++ b/vlc-android/res/layout/video_list_card.xml
@@ -15,6 +15,10 @@
             type="String" />
 
         <variable
+            name="bgColor"
+            type="int" />
+
+        <variable
             name="max"
             type="int" />
 
@@ -39,73 +43,77 @@
             type="org.videolan.vlc.gui.video.VideoListAdapter.ViewHolder" />
     </data>
 
-    <RelativeLayout
+    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:clickable="true"
         android:focusable="true"
         android:onClick="@{(view) -> holder.onClick(view, media)}"
-        android:longClickable="true"  >
+        android:longClickable="true"
+        android:paddingTop="5dp"
+        android:paddingBottom="5dp"
+        android:orientation="horizontal">
         <!-- Image loading is handled by org.videolan.vlc.gui.helpers.AsyncImageLoader.loadPicture() -->
         <ImageView
             android:id="@+id/ml_item_thumbnail"
             android:layout_width="120dp"
             android:layout_height="75dp"
-            android:layout_margin="5dp"
-            android:layout_alignParentLeft="true"
-            android:layout_alignParentStart="true"
-            android:layout_centerVertical="true"
             vlc:media="@{media}"
             vlc:binding="@{holder.binding}"
             android:scaleType="fitXY"
             android:background="@{cover}" />
 
-        <TextView
-            android:id="@+id/ml_item_title"
+        <RelativeLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:layout_alignParentTop="true"
-            android:layout_toRightOf="@+id/ml_item_thumbnail"
-            android:layout_toEndOf="@+id/ml_item_thumbnail"
-            android:layout_toLeftOf="@+id/item_more"
-            android:layout_toStartOf="@+id/item_more"
-            android:layout_above="@+id/ml_item_resolution"
-            android:ellipsize="end"
-            android:fontFamily="sans-serif-light"
-            android:gravity="center_vertical"
-            android:maxLines="2"
-            android:paddingLeft="@dimen/half_default_margin"
-            android:paddingStart="@dimen/half_default_margin"
-            android:text="@{media.title}"
-            android:textColor="?attr/list_title"
-            android:textSize="17sp" />
-
-        <ImageView
-            android:id="@+id/item_more"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_alignParentRight="true"
-            android:layout_alignParentEnd="true"
-            android:layout_above="@+id/ml_item_time"
-            android:clickable="true"
-            android:contentDescription="@string/more_actions"
-            android:onClick="@{holder::onMoreClick}"
-            android:scaleType="fitCenter"
-            android:src="@drawable/ic_more" />
+            android:background="@{bgColor}">
+            <TextView
+                android:id="@+id/ml_item_title"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_alignParentTop="true"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentStart="true"
+                android:layout_toLeftOf="@+id/item_more"
+                android:layout_toStartOf="@+id/item_more"
+                android:layout_above="@+id/ml_item_resolution"
+                android:ellipsize="end"
+                android:fontFamily="sans-serif-light"
+                android:gravity="center_vertical"
+                android:maxLines="2"
+                android:paddingLeft="@dimen/half_default_margin"
+                android:paddingStart="@dimen/half_default_margin"
+                android:text="@{media.title}"
+                android:textColor="?attr/list_title"
+                android:textSize="17sp" />
+
+            <ImageView
+                android:id="@+id/item_more"
+                android:layout_width="wrap_content"
+                android:layout_height="match_parent"
+                android:layout_alignParentRight="true"
+                android:layout_alignParentEnd="true"
+                android:layout_alignTop="@+id/ml_item_title"
+                android:layout_above="@+id/ml_item_time"
+                android:clickable="true"
+                android:contentDescription="@string/more_actions"
+                android:onClick="@{holder::onMoreClick}"
+                android:scaleType="center"
+                android:src="@drawable/ic_more" />
 
             <TextView
                 android:id="@+id/ml_item_time"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_toRightOf="@+id/ml_item_thumbnail"
-                android:layout_toEndOf="@+id/ml_item_thumbnail"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentStart="true"
                 android:layout_above="@+id/ml_item_progress"
-                android:background="@color/transparent"
                 android:fontFamily="sans-serif-light"
                 android:gravity="start"
-                android:layout_marginLeft="@dimen/half_default_margin"
-                android:layout_marginStart="@dimen/half_default_margin"
+                android:paddingLeft="@dimen/half_default_margin"
+                android:paddingStart="@dimen/half_default_margin"
                 android:text="@{time}"
+                android:layout_alignWithParentIfMissing="true"
                 android:textColor="?attr/list_subtitle"
                 android:textSize="14sp" />
 
@@ -118,9 +126,9 @@
                 android:layout_toRightOf="@+id/ml_item_time"
                 android:layout_toEndOf="@+id/ml_item_time"
                 android:layout_above="@+id/ml_item_progress"
-                android:layout_marginRight="@dimen/half_default_margin"
-                android:layout_marginEnd="@dimen/half_default_margin"
-                android:background="@color/transparent"
+                android:paddingRight="@dimen/half_default_margin"
+                android:paddingEnd="@dimen/half_default_margin"
+                android:layout_alignWithParentIfMissing="true"
                 android:fontFamily="sans-serif-light"
                 android:gravity="end"
                 android:text="@{resolution}"
@@ -132,14 +140,13 @@
                 style="@android:style/Widget.ProgressBar.Horizontal"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:layout_toRightOf="@+id/ml_item_thumbnail"
-                android:layout_toEndOf="@+id/ml_item_thumbnail"
-                android:layout_alignBottom="@+id/ml_item_thumbnail"
-                android:layout_marginBottom="2dip"
-                android:layout_marginLeft="@dimen/half_default_margin"
-                android:layout_marginRight="@dimen/half_default_margin"
-                android:layout_marginTop="1dp"
-                android:focusable="false"
+                android:layout_alignParentLeft="true"
+                android:layout_alignParentStart="true"
+                android:layout_alignParentBottom="true"
+                android:paddingBottom="2dip"
+                android:paddingLeft="@dimen/half_default_margin"
+                android:paddingRight="@dimen/half_default_margin"
+                android:paddingTop="1dp"
                 android:indeterminate="false"
                 android:max="@{max}"
                 android:maxHeight="2dip"
@@ -147,5 +154,6 @@
                 android:progress="@{progress}"
                 android:progressDrawable="?attr/gridview_progressbar"
                 android:visibility="@{max == 0 ? View.INVISIBLE : View.VISIBLE}" />
-    </RelativeLayout>
+        </RelativeLayout>
+    </LinearLayout>
 </layout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 509509e..f55ce8f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -28,6 +28,7 @@ import android.databinding.ViewDataBinding;
 import android.preference.PreferenceManager;
 import android.support.annotation.MainThread;
 import android.support.annotation.Nullable;
+import android.support.v4.content.ContextCompat;
 import android.support.v4.util.SimpleArrayMap;
 import android.support.v7.util.SortedList;
 import android.support.v7.widget.GridLayoutManager;
@@ -105,6 +106,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         holder.binding.setVariable(BR.media, media);
         boolean isSelected = mActionMode && mSelectedItems.contains(position);
         holder.setOverlay(mActionMode && isSelected);
+        holder.binding.setVariable(BR.bgColor, ContextCompat.getColor(holder.itemView.getContext(), mListMode && isSelected ? R.color.orange200transparent : R.color.transparent));
     }
 
     @MainThread
@@ -335,6 +337,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
             else
                 mSelectedItems.remove(position);
             setOverlay(itemView.hasFocus() || mSelectedItems.contains(position));
+            binding.setVariable(BR.bgColor, ContextCompat.getColor(itemView.getContext(), mListMode && selected ? R.color.orange200transparent : R.color.transparent));
         }
 
         private void setOverlay(boolean selected) {



More information about the Android mailing list