[Android] Network: Add/Remove favorites from context menu

Geoffrey Métais git at videolan.org
Tue Feb 16 12:30:06 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb 16 12:27:45 2016 +0100| [c4f6b61c56c58499b60798653c896800498b6fe3] | committer: Geoffrey Métais

Network: Add/Remove favorites from context menu

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

 vlc-android/res/menu/directory_view_dir.xml          |  8 ++++++++
 .../vlc/gui/browser/BaseBrowserFragment.java         | 20 +++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/menu/directory_view_dir.xml b/vlc-android/res/menu/directory_view_dir.xml
index 080bafc..9ee068c 100644
--- a/vlc-android/res/menu/directory_view_dir.xml
+++ b/vlc-android/res/menu/directory_view_dir.xml
@@ -12,4 +12,12 @@
     <!--<item-->
         <!--android:id="@+id/directory_view_show_media"-->
         <!--android:title="@string/directory_show_medialib" />-->
+    <item
+        android:id="@+id/network_add_favorite"
+        android:title="@string/favorites_add"
+        android:visible="false" />
+    <item
+        android:id="@+id/network_remove_favorite"
+        android:title="@string/favorites_remove"
+        android:visible="false" />
 </menu>
\ No newline at end of file
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 9b59b6d..0045eed 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -383,7 +383,6 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         boolean canWrite = this instanceof FileBrowserFragment && FileUtils.canWrite(mw.getUri().getPath());
         if (type == MediaWrapper.TYPE_DIR) {
             boolean isEmpty = mFoldersContentLists.get(position) == null || mFoldersContentLists.get(position).isEmpty();
-            if (canWrite || !isEmpty) {
                 inflater.inflate(R.menu.directory_view_dir, menu);
 //                if (canWrite) {
 //                    boolean nomedia = new File(mw.getLocation() + "/.nomedia").exists();
@@ -395,6 +394,12 @@ 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);
+            if (this instanceof NetworkBrowserFragment) {
+                MediaDatabase db = MediaDatabase.getInstance();
+                if (db.networkFavExists(mw.getUri()))
+                    menu.findItem(R.id.network_remove_favorite).setVisible(true);
+                else
+                    menu.findItem(R.id.network_add_favorite).setVisible(true);
             }
         } else {
             inflater.inflate(R.menu.directory_view_file, menu);
@@ -423,6 +428,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
         if (! (mAdapter.getItem(position) instanceof MediaWrapper))
             return super.onContextItemSelected(item);
         final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
+        MediaDatabase db;
         switch (id){
             case R.id.directory_view_play:
                 mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
@@ -478,6 +484,18 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
 //                if (new File(mw.getLocation()+"/.nomedia").delete())
 //                    updateLib();
 //                return true;
+            case R.id.network_add_favorite:
+                db = MediaDatabase.getInstance();
+                db.addNetworkFavItem(mw.getUri(), mw.getTitle());
+                if (isRootDirectory())
+                    updateDisplay();
+                return true;
+            case R.id.network_remove_favorite:
+                db = MediaDatabase.getInstance();
+                db.deleteNetworkFav(mw.getUri());
+                if (isRootDirectory())
+                    updateDisplay();
+                return true;
         }
         return false;
     }



More information about the Android mailing list