[Android] Implement right-click support on media items

Geoffrey Métais git at videolan.org
Tue Dec 12 17:13:05 CET 2017


vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 12 11:02:35 2017 +0100| [51b4e5df8dcab7083187eace79671f04f10c731e] | committer: Geoffrey Métais

Implement right-click support on media items

(cherry picked from commit a4dcf76503fc3bbb90452d4e99e26b9cc7ec20f2)

> https://code.videolan.org/videolan/vlc-android/commit/51b4e5df8dcab7083187eace79671f04f10c731e
---

 .../videolan/vlc/gui/audio/AudioBrowserAdapter.java   | 19 +++++++++----------
 .../org/videolan/vlc/gui/audio/PlaylistAdapter.java   | 12 +++++++++---
 .../videolan/vlc/gui/browser/BaseBrowserAdapter.java  |  7 +++++++
 .../org/videolan/vlc/gui/video/VideoListAdapter.java  |  8 ++++++++
 4 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index 462a0f96d..df0bb8437 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -34,6 +34,7 @@ import android.view.ViewGroup;
 import android.widget.Filter;
 import android.widget.Filterable;
 
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.medialibrary.media.DummyItem;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
@@ -421,8 +422,14 @@ public class AudioBrowserAdapter extends SortableAdapter<MediaLibraryItem, Audio
         MediaItemViewHolder(AudioBrowserItemBinding binding) {
             super(binding);
             binding.setHolder(this);
-            if (mDefaultCover != null)
-                binding.setCover(mDefaultCover);
+            if (mDefaultCover != null) binding.setCover(mDefaultCover);
+            if (AndroidUtil.isMarshMallowOrLater) itemView.setOnContextClickListener(new View.OnContextClickListener() {
+                @Override
+                public boolean onContextClick(View v) {
+                    onMoreClick(v);
+                    return true;
+                }
+            });
         }
 
         public void onClick(View v) {
@@ -460,14 +467,6 @@ public class AudioBrowserAdapter extends SortableAdapter<MediaLibraryItem, Audio
         protected boolean isSelected() {
             return getItem(getLayoutPosition()).hasStateFlags(FLAG_SELECTED);
         }
-
-//        private void setViewBackground(boolean focused, boolean selected) {
-//            int selectionColor = selected || focused ? UiTools.ITEM_SELECTION_ON : 0;
-//            if (selectionColor != this.selectionColor) {
-//                itemView.setBackgroundColor(selectionColor);
-//                this.selectionColor = selectionColor;
-//            }
-//        }
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
index 798bbb5a7..247b28362 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -28,7 +28,6 @@ import android.databinding.DataBindingUtil;
 import android.os.Message;
 import android.support.annotation.MainThread;
 import android.support.v4.app.Fragment;
-import android.support.v7.util.DiffUtil;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -37,6 +36,7 @@ import android.widget.Filter;
 import android.widget.Filterable;
 import android.widget.Toast;
 
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
@@ -46,7 +46,6 @@ import org.videolan.vlc.gui.BaseQueuedAdapter;
 import org.videolan.vlc.gui.helpers.UiTools;
 import org.videolan.vlc.interfaces.SwipeDragHelperAdapter;
 import org.videolan.vlc.media.MediaUtils;
-import org.videolan.vlc.util.MediaItemDiffCallback;
 import org.videolan.vlc.util.WeakHandler;
 
 import java.util.ArrayList;
@@ -178,13 +177,20 @@ public class PlaylistAdapter extends BaseQueuedAdapter<MediaWrapper, PlaylistAda
         mService = service;
     }
 
-    public class ViewHolder extends RecyclerView.ViewHolder{
+    public class ViewHolder extends RecyclerView.ViewHolder {
         PlaylistItemBinding binding;
 
         public ViewHolder(View v) {
             super(v);
             binding = DataBindingUtil.bind(v);
             binding.setHolder(this);
+            if (AndroidUtil.isMarshMallowOrLater) itemView.setOnContextClickListener(new View.OnContextClickListener() {
+                @Override
+                public boolean onContextClick(View v) {
+                    onMoreClick(v);
+                    return true;
+                }
+            });
         }
         public void onClick(View v, MediaWrapper media){
             int position = getMediaPosition(media);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index 91260a1e3..e17b1e994 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -168,6 +168,13 @@ public class BaseBrowserAdapter extends SortableAdapter<MediaLibraryItem, BaseBr
                     return true;
                 }
             });
+            if (AndroidUtil.isMarshMallowOrLater) itemView.setOnContextClickListener(new View.OnContextClickListener() {
+                @Override
+                public boolean onContextClick(View v) {
+                    onMoreClick(v);
+                    return true;
+                }
+            });
         }
 
         void setContextMenuListener() {
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 9cd97c46c..62575df60 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -38,6 +38,7 @@ import android.widget.Filterable;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.medialibrary.Tools;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
@@ -304,6 +305,13 @@ public class VideoListAdapter extends SortableAdapter<MediaWrapper, VideoListAda
             thumbView = itemView.findViewById(R.id.ml_item_thumbnail);
             binding.setVariable(BR.holder, this);
             binding.setVariable(BR.cover, AsyncImageLoader.DEFAULT_COVER_VIDEO_DRAWABLE);
+            if (AndroidUtil.isMarshMallowOrLater) itemView.setOnContextClickListener(new View.OnContextClickListener() {
+                @Override
+                public boolean onContextClick(View v) {
+                    onMoreClick(v);
+                    return true;
+                }
+            });
         }
 
         public void onClick(View v) {



More information about the Android mailing list