[Android] Invert play and 'play all' options in browsers

Geoffrey Métais git at videolan.org
Thu Mar 24 13:45:26 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 24 11:29:43 2016 +0100| [14fa899ccee56bc1c873d62991d4339f1c66e8a2] | committer: Geoffrey Métais

Invert play and 'play all' options in browsers

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

 vlc-android/res/menu/directory_view_file.xml       |  4 ++--
 .../vlc/gui/browser/BaseBrowserAdapter.java        | 23 ++++++----------------
 .../vlc/gui/browser/BaseBrowserFragment.java       | 21 ++++++++++++++++++--
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/vlc-android/res/menu/directory_view_file.xml b/vlc-android/res/menu/directory_view_file.xml
index 5161174..b2ca4f1 100644
--- a/vlc-android/res/menu/directory_view_file.xml
+++ b/vlc-android/res/menu/directory_view_file.xml
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android" >
     <item
-        android:id="@+id/directory_view_play"
-        android:title="@string/play" />
+        android:id="@+id/directory_view_play_all"
+        android:title="@string/play_all" />
     <item
         android:id="@+id/directory_view_play_audio"
         android:title="@string/play_as_audio" />
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 80847eb..a068b7f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -307,6 +307,10 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
         }
     }
 
+    public ArrayList<Object> getAll(){
+        return mMediaList;
+    }
+
     public Object getItem(int position){
         return mMediaList.get(position);
     }
@@ -376,23 +380,8 @@ public class BaseBrowserAdapter extends  RecyclerView.Adapter<RecyclerView.ViewH
         if (mw.getType() == MediaWrapper.TYPE_DIR)
             fragment.browse(mw, holder.getAdapterPosition(), true);
         else  if (mw.getType() == MediaWrapper.TYPE_AUDIO || mw.getType() == MediaWrapper.TYPE_VIDEO) {
-            if (mw.getType() == MediaWrapper.TYPE_VIDEO && !AndroidUtil.isHoneycombOrLater()) {
-                MediaUtils.openMedia(holder.itemView.getContext(), mw);
-                return;
-            }
-            int position = 0;
-            LinkedList<MediaWrapper> mediaLocations = new LinkedList<MediaWrapper>();
-            MediaWrapper mediaItem;
-            for (Object item : mMediaList)
-                if (item instanceof MediaWrapper) {
-                    mediaItem = (MediaWrapper) item;
-                    if (mediaItem.getType() == MediaWrapper.TYPE_VIDEO || mediaItem.getType() == MediaWrapper.TYPE_AUDIO) {
-                        mediaLocations.add(mediaItem);
-                        if (mediaItem.equals(mw))
-                            position = mediaLocations.size() - 1;
-                    }
-                }
-            MediaUtils.openList(holder.itemView.getContext(), mediaLocations, position);
+                MediaUtils.openMedia(v.getContext(), mw);
+
         } else {
             MediaUtils.openStream(holder.itemView.getContext(), mw.getLocation());
         }
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 b2a55e7..9b9bb2e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -66,6 +66,7 @@ import org.videolan.vlc.util.VLCInstance;
 import org.videolan.vlc.util.WeakHandler;
 
 import java.util.ArrayList;
+import java.util.LinkedList;
 
 
 public abstract class BaseBrowserFragment extends MediaBrowserFragment implements IRefreshable, MediaBrowser.EventListener, SwipeRefreshLayout.OnRefreshListener {
@@ -423,6 +424,9 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             }
         } else {
             inflater.inflate(R.menu.directory_view_file, menu);
+            menu.findItem(R.id.directory_view_play_all).setVisible(
+                    mw.getType() == MediaWrapper.TYPE_AUDIO ||
+                    (mw.getType() == MediaWrapper.TYPE_VIDEO && AndroidUtil.isHoneycombOrLater()));
             menu.findItem(R.id.directory_view_delete).setVisible(canWrite);
             menu.findItem(R.id.directory_view_info).setVisible(type == MediaWrapper.TYPE_VIDEO || type == MediaWrapper.TYPE_AUDIO);
             menu.findItem(R.id.directory_view_play_audio).setVisible(type != MediaWrapper.TYPE_AUDIO);
@@ -450,9 +454,22 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             return super.onContextItemSelected(item);
         final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
         switch (id){
-            case R.id.directory_view_play:
+            case R.id.directory_view_play_all:
+                boolean isHoneycombOrLater = AndroidUtil.isHoneycombOrLater();
                 mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
-                MediaUtils.openMedia(getActivity(), mw);
+                int positionInPlaylist = 0;
+                LinkedList<MediaWrapper> mediaLocations = new LinkedList<MediaWrapper>();
+                MediaWrapper media;
+                for (Object file : mAdapter.getAll())
+                    if (file instanceof MediaWrapper) {
+                        media = (MediaWrapper) file;
+                        if ((isHoneycombOrLater && media.getType() == MediaWrapper.TYPE_VIDEO) || media.getType() == MediaWrapper.TYPE_AUDIO) {
+                            mediaLocations.add(media);
+                            if (media.equals(mw))
+                                positionInPlaylist = mediaLocations.size() - 1;
+                        }
+                    }
+                MediaUtils.openList(getActivity(), mediaLocations, positionInPlaylist);
                 return true;
             case R.id.directory_view_append: {
                 if (mService != null)



More information about the Android mailing list