[Android] Set selection on video thumb instead of background

Geoffrey Métais git at videolan.org
Thu Nov 17 16:51:15 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 17 14:04:33 2016 +0100| [2e02887b7f6c6d001004ef5d72e187fb02f0f9f6] | committer: Alexandre Perraud

Set selection on video thumb instead of background

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

 vlc-android/res/layout/video_grid_card.xml            |  2 +-
 vlc-android/res/layout/video_list_card.xml            |  5 ++---
 .../org/videolan/vlc/gui/video/VideoListAdapter.java  | 19 +++++++++++--------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/vlc-android/res/layout/video_grid_card.xml b/vlc-android/res/layout/video_grid_card.xml
index d3fb48f..1112cd1 100644
--- a/vlc-android/res/layout/video_grid_card.xml
+++ b/vlc-android/res/layout/video_grid_card.xml
@@ -55,7 +55,7 @@
                 android:id="@+id/ml_item_thumbnail"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:scaleType="center"
+                android:scaleType="fitXY"
                 vlc:media="@{media}"
                 vlc:binding="@{holder.binding}"
                 android:src="@drawable/black_gradient"
diff --git a/vlc-android/res/layout/video_list_card.xml b/vlc-android/res/layout/video_list_card.xml
index 4f6deba..ce42a40 100644
--- a/vlc-android/res/layout/video_list_card.xml
+++ b/vlc-android/res/layout/video_list_card.xml
@@ -55,11 +55,10 @@
             android:layout_alignParentLeft="true"
             android:layout_alignParentStart="true"
             android:layout_centerVertical="true"
-            android:background="?attr/background_default_darker"
             vlc:media="@{media}"
             vlc:binding="@{holder.binding}"
-            android:scaleType="@{scaleType}"
-            android:src="@{cover}" />
+            android:scaleType="fitXY"
+            android:background="@{cover}" />
 
         <TextView
             android:id="@+id/ml_item_title"
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 7acb0b0..6eb1a03 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -84,7 +84,6 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
 
     @Override
     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-        boolean listMode = viewType == TYPE_LIST;
         LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         View v = inflater.inflate(mListMode ? R.layout.video_list_card : R.layout.video_grid_card, parent, false);
         if (!mListMode) {
@@ -93,7 +92,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
             params.height = params.width*10/16;
             v.setLayoutParams(params);
         }
-        return new ViewHolder(v, listMode);
+        return new ViewHolder(v);
     }
 
     @Override
@@ -105,7 +104,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         fillView(holder, media);
         holder.binding.setVariable(BR.media, media);
         boolean isSelected = mActionMode && mSelectedItems.contains(position);
-        holder.setViewBackground(mActionMode && isSelected);
+        holder.setOverlay(mActionMode && isSelected);
     }
 
     @MainThread
@@ -274,7 +273,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         return super.getItemViewType(position);
     }
 
-    public void setActionMode(boolean actionMode) {
+    void setActionMode(boolean actionMode) {
         mActionMode = actionMode;
         if (!actionMode) {
             LinkedList<Integer> positions = new LinkedList<>(mSelectedItems);
@@ -285,13 +284,13 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     }
 
     public class ViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnFocusChangeListener {
-        boolean listmode;
         public ViewDataBinding binding;
+        private ImageView thumbView;
 
-        public ViewHolder(View itemView, boolean listMode) {
+        public ViewHolder(View itemView) {
             super(itemView);
             binding = DataBindingUtil.bind(itemView);
-            this.listmode = listMode;
+            thumbView = (ImageView) itemView.findViewById(R.id.ml_item_thumbnail);
             binding.setVariable(BR.holder, this);
             itemView.setOnLongClickListener(this);
             itemView.setOnFocusChangeListener(this);
@@ -335,7 +334,11 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
                 mSelectedItems.add(position);
             else
                 mSelectedItems.remove(position);
-            setViewBackground(itemView.hasFocus() || mSelectedItems.contains(position));
+            setOverlay(itemView.hasFocus() || mSelectedItems.contains(position));
+        }
+
+        private void setOverlay(boolean selected) {
+            thumbView.setImageResource(selected ? R.drawable.ic_action_mode_select_1610 : mListMode ? 0 : R.drawable.black_gradient);
         }
 
         @Override



More information about the Android mailing list