[Android] Fix context menu for regular browser

Geoffrey Métais git at videolan.org
Tue May 12 16:39:18 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 12 16:21:06 2015 +0200| [090f40cdd00c01c508621bb9bfe31978c4009586] | committer: Geoffrey Métais

Fix context menu for regular browser

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=090f40cdd00c01c508621bb9bfe31978c4009586
---

 .../videolan/vlc/gui/browser/BaseBrowserAdapter.java    |    5 +++--
 .../videolan/vlc/gui/browser/FileBrowserFragment.java   |   10 ----------
 .../vlc/gui/browser/StorageBrowserFragment.java         |   15 ++++++++++++++-
 3 files changed, 17 insertions(+), 13 deletions(-)

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 0299503..2518e17 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -61,9 +61,11 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
     MediaDatabase mDbManager;
     LinkedList<String> mMediaDirsLocation;
     List<String> mCustomDirsLocation;
+    String mEmptyDirectoryString;
 
     public BaseBrowserAdapter(BaseBrowserFragment fragment){
         this.fragment = fragment;
+        mEmptyDirectoryString = fragment.getString(R.string.directory_empty);
     }
 
     @Override
@@ -98,7 +100,7 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
         final MediaWrapper media = (MediaWrapper) getItem(position);
         boolean hasContextMenu = (media.getType() == MediaWrapper.TYPE_AUDIO ||
                 media.getType() == MediaWrapper.TYPE_VIDEO ||
-                (media.getType() == MediaWrapper.TYPE_DIR && Util.canWrite(media.getLocation())));
+                (media.getType() == MediaWrapper.TYPE_DIR && !TextUtils.equals(media.getDescription(), mEmptyDirectoryString)));
         vh.checkBox.setVisibility(View.GONE);
         vh.title.setText(media.getTitle());
         if (!TextUtils.isEmpty(media.getDescription())) {
@@ -262,7 +264,6 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
             mMediaDirsLocation.add(dir.getPath());
         }
         mCustomDirsLocation = Arrays.asList(CustomDirectories.getCustomDirectories());
-        mMediaDirsLocation.addAll(mCustomDirsLocation);
     }
 
     public void addAll(ArrayList<MediaWrapper> mediaList){
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
index 06ea047..7d018e8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -172,16 +172,6 @@ public class FileBrowserFragment extends BaseBrowserFragment {
         mAlertDialog = builder.show();
     }
 
-    protected void setContextMenu(MenuInflater inflater, Menu menu, int position) {
-        if (mRoot) {
-            BaseBrowserAdapter.Storage storage = (BaseBrowserAdapter.Storage) mAdapter.getItem(position);
-            boolean isCustom = CustomDirectories.contains(storage.getPath());
-            if (isCustom)
-                inflater.inflate(R.menu.directory_custom_dir, menu);
-        } else
-            super.setContextMenu(inflater, menu, position);
-    }
-
     @Override
     protected boolean handleContextItemSelected(MenuItem item, int position) {
         if (mRoot) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
index 060702c..7fbb6ea 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
@@ -28,6 +28,8 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
@@ -36,6 +38,7 @@ import org.videolan.libvlc.Media;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.CustomDirectories;
 
 public class StorageBrowserFragment extends FileBrowserFragment implements View.OnClickListener {
 
@@ -46,7 +49,6 @@ public class StorageBrowserFragment extends FileBrowserFragment implements View.
 
     public StorageBrowserFragment(){
         mHandler = new BrowserFragmentHandler(this);
-        mAdapter = new StorageBrowserAdapter(this);
         ROOT = AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY;
     }
 
@@ -58,6 +60,7 @@ public class StorageBrowserFragment extends FileBrowserFragment implements View.
     @Override
     public void onCreate(Bundle bundle) {
         super.onCreate(bundle);
+        mAdapter = new StorageBrowserAdapter(this);
         if (bundle == null)
             bundle = getArguments();
         if (bundle != null){
@@ -134,6 +137,16 @@ public class StorageBrowserFragment extends FileBrowserFragment implements View.
         ft.commit();
     }
 
+    protected void setContextMenu(MenuInflater inflater, Menu menu, int position) {
+        if (mRoot) {
+            BaseBrowserAdapter.Storage storage = (BaseBrowserAdapter.Storage) mAdapter.getItem(position);
+            boolean isCustom = CustomDirectories.contains(storage.getPath());
+            if (isCustom)
+                inflater.inflate(R.menu.directory_custom_dir, menu);
+        } else
+            super.setContextMenu(inflater, menu, position);
+    }
+
     @Override
     public void onClick(View v) {
         if (v.getId() == R.id.fab_add_custom_dir){



More information about the Android mailing list