[Android] Context menu for all files in browser

Geoffrey Métais git at videolan.org
Tue Jan 5 18:37:06 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan  5 18:35:54 2016 +0100| [2486424fbe3099886f111150e283bf8d26487f7c] | committer: Geoffrey Métais

Context menu for all files in browser

> https://code.videolan.org/videolan/vlc-android/commit/2486424fbe3099886f111150e283bf8d26487f7c
---

 vlc-android/res/menu/directory_view_file.xml          |  3 ---
 .../videolan/vlc/gui/browser/BaseBrowserAdapter.java  | 19 ++++++++-----------
 .../videolan/vlc/gui/browser/BaseBrowserFragment.java | 18 +++++++-----------
 3 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/vlc-android/res/menu/directory_view_file.xml b/vlc-android/res/menu/directory_view_file.xml
index 33cf628..39e7aa5 100644
--- a/vlc-android/res/menu/directory_view_file.xml
+++ b/vlc-android/res/menu/directory_view_file.xml
@@ -15,7 +15,4 @@
     <item
         android:id="@+id/directory_view_play_audio"
         android:title="@string/play_as_audio" />
-    <item
-        android:id="@+id/directory_view_play_video"
-        android:title="@string/play_as_video" />
 </menu>
\ No newline at end of file
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 41b26f8..a3b283f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -101,19 +101,15 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
     private void onBindMediaViewHolder(final RecyclerView.ViewHolder holder, int position) {
         final MediaViewHolder vh = (MediaViewHolder) holder;
         final MediaWrapper media = (MediaWrapper) getItem(position);
-        boolean hasContextMenu = (media.getType() == MediaWrapper.TYPE_AUDIO ||
-                media.getType() == MediaWrapper.TYPE_VIDEO ||
-                media.getType() == MediaWrapper.TYPE_DIR );
         vh.binding.setMedia(media);
-        vh.binding.setHasContextMenu(hasContextMenu);
         vh.binding.setType(TYPE_MEDIA);
+        vh.binding.setHasContextMenu(true);
         vh.binding.setProtocole(getProtocol(media));
         vh.binding.executePendingBindings();
 
         vh.icon.setBackgroundResource(getIconResId(media));
-        if (hasContextMenu) {
-            vh.setContextMenuListener();
-        }
+
+        vh.setContextMenuListener();
     }
 
     @Override
@@ -147,6 +143,10 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             v.findViewById(R.id.layout_item).setTag(R.id.layout_item, this);
         }
 
+        public void setContextMenuListener() {
+            itemView.setOnLongClickListener(this);
+        }
+
         public void onClick(View v){
             openMediaFromView(this, v);
         }
@@ -163,13 +163,10 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             }
         }
 
-        public void onMoreClick(View v){
+        public void onMoreClick(View v) {
             fragment.openContextMenu(getLayoutPosition());
         }
 
-        public void setContextMenuListener() {
-            itemView.setOnLongClickListener(this);
-        }
         @Override
         public boolean onLongClick(View v) {
             fragment.mRecyclerView.openContextMenu(getLayoutPosition());
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 987d9dd..fd3a990 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -50,7 +50,6 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.gui.SecondaryActivity;
 import org.videolan.vlc.gui.helpers.UiTools;
-import org.videolan.vlc.gui.video.VideoPlayerActivity;
 import org.videolan.vlc.gui.view.ContextMenuRecyclerView;
 import org.videolan.vlc.gui.view.DividerItemDecoration;
 import org.videolan.vlc.gui.view.SwipeRefreshLayout;
@@ -316,7 +315,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             public void run() {
                 FileUtils.deleteFile(mw.getUri().getPath());
                 MediaDatabase.getInstance().removeMedia(mw.getUri());
-                mHandler.obtainMessage(BrowserFragmentHandler.MSG_REFRESH).sendToTarget();
             }
         });
     }
@@ -372,13 +370,8 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
     protected void setContextMenu(MenuInflater inflater, Menu menu, int position) {
         MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
         boolean canWrite = this instanceof FileBrowserFragment && FileUtils.canWrite(mw.getUri().getPath());
-        boolean isAudio = mw.getType() == MediaWrapper.TYPE_AUDIO;
         boolean isVideo = mw.getType() == MediaWrapper.TYPE_VIDEO;
-        if (isAudio || isVideo) {
-            inflater.inflate(R.menu.directory_view_file, menu);
-            menu.findItem(R.id.directory_view_delete).setVisible(canWrite);
-            menu.findItem(R.id.directory_view_info).setVisible(isVideo);
-        } else if (mw.getType() == MediaWrapper.TYPE_DIR) {
+        if (mw.getType() == MediaWrapper.TYPE_DIR) {
             boolean isEmpty = mMediaLists.get(position) == null || mMediaLists.get(position).isEmpty();
             if (canWrite || !isEmpty) {
                 inflater.inflate(R.menu.directory_view_dir, menu);
@@ -393,6 +386,11 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
                 menu.findItem(R.id.directory_view_play_folder).setVisible(!isEmpty);
                 menu.findItem(R.id.directory_view_delete).setVisible(canWrite);
             }
+        } else {
+            inflater.inflate(R.menu.directory_view_file, menu);
+            menu.findItem(R.id.directory_view_delete).setVisible(canWrite);
+            menu.findItem(R.id.directory_view_info).setVisible(isVideo);
+            menu.findItem(R.id.directory_view_play_audio).setVisible(isVideo);
         }
     }
 
@@ -426,6 +424,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
                 return true;
             }
             case R.id.directory_view_delete:
+                mAdapter.removeItem(position, true);
                 UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
                     @Override
                     public void run() {
@@ -446,9 +445,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
                 }
                 return true;
             }
-            case  R.id.directory_view_play_video:
-                VideoPlayerActivity.start(getActivity(), mw.getUri());
-                return true;
             case R.id.directory_view_play_folder:
                 ArrayList<MediaWrapper> mediaList = new ArrayList<MediaWrapper>();
                 for (MediaWrapper mediaItem : mMediaLists.get(position)){



More information about the Android mailing list