[Android] Add Video Playlist Mode preference

Alexandre Perraud git at videolan.org
Wed Dec 7 16:31:41 CET 2016


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Fri Dec  2 18:30:29 2016 +0100| [e2e964e1045442bdafb19166d283b9b9a0912a69] | committer: Alexandre Perraud

Add Video Playlist Mode preference

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

 vlc-android/res/values/strings.xml                 |  2 ++
 vlc-android/res/xml/preferences_video.xml          |  5 +++++
 .../videolan/vlc/gui/video/VideoGridFragment.java  | 15 +-------------
 .../videolan/vlc/gui/video/VideoListAdapter.java   | 24 +++++++++++++++++++++-
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 6abcbf2..46e6f00 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -286,6 +286,8 @@
     <string name="video_min_group_length_long">Long number of letters (9)</string>
     <string name="force_list_portrait">No grid in portrait mode</string>
     <string name="force_list_portrait_summary">Show videos in list instead of grid in portrait mode</string>
+    <string name="force_play_all_summary">Play all videos, starting with the one you clicked on</string>
+    <string name="force_play_all_title">Video playlist mode</string>
     <string name="save_brightness_summary">Remember brightness level in video player</string>
     <string name="save_brightness_title">Save brightness level for video</string>
     <string name="enable_brightness_gesture_title">Brightness gesture</string>
diff --git a/vlc-android/res/xml/preferences_video.xml b/vlc-android/res/xml/preferences_video.xml
index 4490279..1c5e341 100644
--- a/vlc-android/res/xml/preferences_video.xml
+++ b/vlc-android/res/xml/preferences_video.xml
@@ -22,6 +22,11 @@
     <PreferenceCategory android:title="@string/controls_prefs_category">
         <CheckBoxPreference
             android:defaultValue="false"
+            android:key="force_play_all"
+            android:summary="@string/force_play_all_summary"
+            android:title="@string/force_play_all_title" />
+        <CheckBoxPreference
+            android:defaultValue="false"
             android:key="save_brightness"
             android:summary="@string/save_brightness_summary"
             android:title="@string/save_brightness_title" />
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 2003938..adea3a9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -236,20 +236,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
                 return true;
             case R.id.video_list_play_all:
                 ArrayList<MediaWrapper> playList = new ArrayList<>();
-                ArrayList<MediaWrapper> videos = mVideoAdapter.getAll();
-                MediaWrapper mw;
-                int offset = 0;
-                for (int i = 0; i < videos.size(); ++i) {
-                    mw = videos.get(i);
-                    if (mw instanceof MediaGroup) {
-                        for (MediaWrapper item : ((MediaGroup) mw).getAll())
-                            playList.add(item);
-                        if (i < position)
-                            offset += ((MediaGroup)mw).size()-1;
-                    } else
-                        playList.add(mw);
-                }
-                MediaUtils.openList(getActivity(), playList, position+offset);
+                MediaUtils.openList(getActivity(), playList, mVideoAdapter.getListWithPosition(playList, position));
                 return true;
             case R.id.video_list_info:
                 showInfoDialog(media);
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 4b782e0..283f7c9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -272,6 +272,22 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
         return super.getItemViewType(position);
     }
 
+    int getListWithPosition(ArrayList<MediaWrapper>  list, int position) {
+        MediaWrapper mw;
+        int offset = 0;
+        for (int i = 0; i < getAll().size(); ++i) {
+            mw = getAll().get(i);
+            if (mw instanceof MediaGroup) {
+                for (MediaWrapper item : ((MediaGroup) mw).getAll())
+                    list.add(item);
+                if (i < position)
+                    offset += ((MediaGroup)mw).size()-1;
+            } else
+                list.add(mw);
+        }
+        return position+offset;
+    }
+
     void setActionMode(boolean actionMode) {
         mActionMode = actionMode;
         if (!actionMode) {
@@ -308,7 +324,13 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
                 ((MainActivity)activity).showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, title);
             } else {
                 media.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
-                MediaUtils.openMedia(itemView.getContext(), media);
+                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+                if (settings.getBoolean("force_play_all", false)) {
+                    ArrayList<MediaWrapper> playList = new ArrayList<>();
+                    MediaUtils.openList(itemView.getContext(), playList, getListWithPosition(playList, getAdapterPosition()));
+                } else {
+                    MediaUtils.openMedia(itemView.getContext(), media);
+                }
             }
         }
 



More information about the Android mailing list