[Android] Video browser: display the play from start function in the context menu only if the playback has already been started before

Adrien Maglo git at videolan.org
Mon Mar 17 10:45:02 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Mar 17 10:44:00 2014 +0100| [da45005673d739f45a9f7f8dc022a0ebccda894d] | committer: Adrien Maglo

Video browser: display the play from start function in the context menu only if the playback has already been started before

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

 vlc-android/res/menu/video_list.xml                        |    3 ++-
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java  |   12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/menu/video_list.xml b/vlc-android/res/menu/video_list.xml
index 82a7511..ffd4d5c 100644
--- a/vlc-android/res/menu/video_list.xml
+++ b/vlc-android/res/menu/video_list.xml
@@ -2,7 +2,8 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
     <item
         android:id="@+id/video_list_play_from_start"
-        android:title="@string/play_from_start" />
+        android:title="@string/play_from_start"
+        android:visible="false" />
     <item
         android:id="@+id/video_list_play_audio"
         android:title="@string/play_as_audio" />
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 6db15c6..2ee3874 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -59,6 +59,7 @@ import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.LayoutInflater;
+import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
@@ -320,6 +321,15 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
             return;
         MenuInflater inflater = getActivity().getMenuInflater();
         inflater.inflate(R.menu.video_list, menu);
+        setContextMenuItems(menu, media);
+    }
+
+    private void setContextMenuItems(Menu menu, Media media) {
+        long lastTime = media.getTime();
+        if (lastTime > 0) {
+            MenuItem playFromStart = menu.findItem(R.id.video_list_play_from_start);
+            playFromStart.setVisible(true);
+        }
     }
 
     @Override
@@ -340,6 +350,8 @@ public class VideoGridFragment extends SherlockGridFragment implements ISortable
 
         PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
         popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
+        Media media = mVideoAdapter.getItem(position);
+        setContextMenuItems(popupMenu.getMenu(), media);
         popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
             @Override
             public boolean onMenuItemClick(MenuItem item) {



More information about the Android mailing list