[Android] [PATCH 03/10] Option to load all video in Video view

Geoffrey Métais geoffrey.metais at gmail.com
Fri Nov 27 13:24:58 CET 2015


And ability to load a whole media group
---
 vlc-android/res/layout/video_grid_card.xml          |  7 +------
 vlc-android/res/layout/video_list_card.xml          |  7 +------
 vlc-android/res/menu/video_group_contextual.xml     |  7 +++++++
 vlc-android/res/menu/video_list.xml                 |  3 +++
 .../videolan/vlc/gui/video/VideoGridFragment.java   | 21 ++++++++++++++++++---
 .../videolan/vlc/gui/video/VideoListAdapter.java    | 12 +++++++-----
 .../src/org/videolan/vlc/media/MediaGroup.java      |  8 ++++++--
 .../src/org/videolan/vlc/media/MediaUtils.java      |  9 ++-------
 8 files changed, 45 insertions(+), 29 deletions(-)
 create mode 100644 vlc-android/res/menu/video_group_contextual.xml

diff --git a/vlc-android/res/layout/video_grid_card.xml b/vlc-android/res/layout/video_grid_card.xml
index 1b6da01..8638866 100644
--- a/vlc-android/res/layout/video_grid_card.xml
+++ b/vlc-android/res/layout/video_grid_card.xml
@@ -31,10 +31,6 @@
             type="String" />
 
         <variable
-            name="group"
-            type="boolean" />
-
-        <variable
             name="cover"
             type="android.graphics.drawable.BitmapDrawable" />
 
@@ -118,8 +114,7 @@
                         android:onClick="@{handler.onMoreClick}"
                         android:scaleType="fitCenter"
                         android:src="@drawable/ic_more"
-                        android:tag="@{position}"
-                        android:visibility="@{group ? View.INVISIBLE : View.VISIBLE}" />
+                        android:tag="@{position}" />
 
                 </LinearLayout>
 
diff --git a/vlc-android/res/layout/video_list_card.xml b/vlc-android/res/layout/video_list_card.xml
index 705d1a1..730d9b2 100644
--- a/vlc-android/res/layout/video_list_card.xml
+++ b/vlc-android/res/layout/video_list_card.xml
@@ -31,10 +31,6 @@
             type="String" />
 
         <variable
-            name="group"
-            type="boolean" />
-
-        <variable
             name="cover"
             type="android.graphics.drawable.BitmapDrawable" />
 
@@ -105,8 +101,7 @@
                     android:onClick="@{handler.onMoreClick}"
                     android:scaleType="fitCenter"
                     android:src="@drawable/ic_more"
-                    android:tag="@{position}"
-                    android:visibility="@{group ? View.INVISIBLE : View.VISIBLE}" />
+                    android:tag="@{position}" />
 
                 <LinearLayout
                     android:id="@+id/info_layout"
diff --git a/vlc-android/res/menu/video_group_contextual.xml b/vlc-android/res/menu/video_group_contextual.xml
new file mode 100644
index 0000000..3badd7e
--- /dev/null
+++ b/vlc-android/res/menu/video_group_contextual.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/video_group_play"
+        android:title="@string/play" />
+</menu>
\ No newline at end of file
diff --git a/vlc-android/res/menu/video_list.xml b/vlc-android/res/menu/video_list.xml
index ffd4d5c..873e32a 100644
--- a/vlc-android/res/menu/video_list.xml
+++ b/vlc-android/res/menu/video_list.xml
@@ -5,6 +5,9 @@
         android:title="@string/play_from_start"
         android:visible="false" />
     <item
+        android:id="@+id/video_list_play_all"
+        android:title="@string/play_all" />
+    <item
         android:id="@+id/video_list_play_audio"
         android:title="@string/play_as_audio" />
     <item
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 311ecaf..e94f8e0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -279,6 +279,17 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
             case R.id.video_list_play_audio:
                 playAudio(media);
                 return true;
+            case R.id.video_list_play_all:
+                ArrayList<MediaWrapper> playList = new ArrayList<>();
+                for (MediaWrapper mw : mVideoAdapter.getAll()) {
+                    if (mw instanceof MediaGroup) {
+                        for (MediaWrapper item : ((MediaGroup) mw).getAll())
+                            playList.add(item);
+                    } else
+                        playList.add(mw);
+                }
+                MediaUtils.openList(getActivity(), playList, position);
+                return true;
             case R.id.video_list_info:
                 Activity activity = getActivity();
                 if (activity instanceof MainActivity)
@@ -297,6 +308,9 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
                 Message msg = mDeleteHandler.obtainMessage(DELETE_MEDIA, position, 0);
                 mDeleteHandler.sendMessageDelayed(msg, DELETE_DURATION);
                 return true;
+            case R.id.video_group_play:
+                MediaUtils.openList(getActivity(), ((MediaGroup) media).getAll(), 0);
+
         }
         return false;
     }
@@ -306,11 +320,12 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
         // Do not show the menu of media group.
         ContextMenuRecyclerView.RecyclerContextMenuInfo info = (ContextMenuRecyclerView.RecyclerContextMenuInfo)menuInfo;
         MediaWrapper media = mVideoAdapter.getItem(info.position);
-        if (media == null || media instanceof MediaGroup)
+        if (media == null)
             return;
         MenuInflater inflater = getActivity().getMenuInflater();
-        inflater.inflate(R.menu.video_list, menu);
-        setContextMenuItems(menu, media);
+        inflater.inflate(media instanceof MediaGroup ? R.menu.video_group_contextual : R.menu.video_list, menu);
+        if (!(media instanceof MediaGroup))
+            setContextMenuItems(menu, media);
     }
 
     private void setContextMenuItems(Menu menu, MediaWrapper mediaWrapper) {
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 5bc5063..1e1e130 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -43,6 +43,7 @@ import org.videolan.vlc.gui.helpers.AsyncImageLoader;
 import org.videolan.vlc.gui.helpers.BitmapCache;
 import org.videolan.vlc.gui.helpers.BitmapUtil;
 import org.videolan.vlc.media.MediaGroup;
+import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.media.MediaWrapper;
 import org.videolan.vlc.util.Strings;
 
@@ -238,6 +239,10 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
 
     }
 
+    public ArrayList<MediaWrapper> getAll() {
+        return mVideos;
+    }
+
     @MainThread
     public void update(MediaWrapper item) {
         int position = mVideos.indexOf(item);
@@ -252,19 +257,16 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     }
 
     private void fillView(ViewHolder holder, MediaWrapper media) {
-        boolean group;
         String text = "";
         String resolution = "";
         int max = 0;
         int progress = 0;
 
         if (media.getType() == MediaWrapper.TYPE_GROUP) {
-            group = true;
             MediaGroup mediaGroup = (MediaGroup) media;
             int size = mediaGroup.size();
             resolution = VLCApplication.getAppResources().getQuantityString(R.plurals.videos_quantity, size, size);
         } else {
-            group = false;
             /* Time / Duration */
             if (media.getLength() > 0) {
                 long lastTime = media.getTime();
@@ -282,7 +284,6 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
                 resolution = String.format("%dx%d", media.getWidth(), media.getHeight());
         }
 
-        holder.binding.setVariable(BR.group, group);
         holder.binding.setVariable(BR.resolution, resolution);
         holder.binding.setVariable(BR.time, text);
         holder.binding.setVariable(BR.max, max);
@@ -348,7 +349,8 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
     public ClickHandler mClickHandler = new ClickHandler();
     public class ClickHandler {
         public void onClick(View v){
-            MediaWrapper media = mVideos.get(((Integer) v.findViewById(R.id.item_more).getTag()).intValue());
+            int position = ((Integer) v.findViewById(R.id.item_more).getTag()).intValue();
+            MediaWrapper media = mVideos.get(position);
             if (media instanceof MediaGroup) {
                 MainActivity activity = (MainActivity) mFragment.getActivity();
                 activity.showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, media.getTitle());
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
index 1586b5d..5fe34d5 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
@@ -20,11 +20,11 @@
 
 package org.videolan.vlc.media;
 
+import org.videolan.vlc.gui.helpers.BitmapUtil;
+
 import java.util.ArrayList;
 import java.util.List;
 
-import org.videolan.vlc.gui.helpers.BitmapUtil;
-
 public class MediaGroup extends MediaWrapper {
 
     public final static String TAG = "VLC/MediaGroup";
@@ -72,6 +72,10 @@ public class MediaGroup extends MediaWrapper {
         return mMedias.get(0);
     }
 
+    public ArrayList<MediaWrapper> getAll() {
+        return mMedias;
+    }
+
     public int size() {
         return mMedias.size();
     }
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
index 2bad43a..bf9511f 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
@@ -10,7 +10,6 @@ import android.support.v4.content.LocalBroadcastManager;
 import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
-import org.videolan.vlc.gui.video.VideoPlayerActivity;
 import org.videolan.vlc.util.FileUtils;
 import org.videolan.vlc.util.Strings;
 
@@ -35,16 +34,12 @@ public class MediaUtils {
     public static void openMedia(final Context context, final MediaWrapper media){
         if (media == null)
             return;
-        if (media.getType() == MediaWrapper.TYPE_VIDEO)
-            VideoPlayerActivity.start(context, media.getUri(), media.getTitle());
-        else if (media.getType() == MediaWrapper.TYPE_AUDIO) {
-            new DialogCallback(context, new DialogCallback.Runnable() {
+        new DialogCallback(context, new DialogCallback.Runnable() {
                 @Override
                 public void run(PlaybackService service) {
                     service.load(media);
                 }
-            });
-        }
+        });
     }
 
     public static void openList(final Context context, final List<MediaWrapper> list, final int position){
-- 
2.5.0



More information about the Android mailing list