[Android] TV: Add 'Download Subtitles' option for videos

Geoffrey Métais git at videolan.org
Mon Apr 18 16:07:07 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr 18 14:54:25 2016 +0200| [84399175ea04a3347829b6c90cbc1f9b833e1122] | committer: Geoffrey Métais

TV: Add 'Download Subtitles' option for videos

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

 .../vlc/gui/tv/MediaItemDetailsFragment.java       | 36 ++++++++++++++++------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index e1c0fe1..1899e37 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -44,10 +44,13 @@ import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.gui.PlaybackServiceFragment;
 import org.videolan.vlc.gui.helpers.AudioUtil;
+import org.videolan.vlc.gui.helpers.BitmapUtil;
 import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
 import org.videolan.vlc.media.MediaDatabase;
 import org.videolan.vlc.media.MediaLibrary;
+import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.media.MediaWrapper;
+import org.videolan.vlc.util.FileUtils;
 
 import java.util.ArrayList;
 
@@ -59,6 +62,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
     private static final int ID_FAVORITE_ADD = 3;
     private static final int ID_FAVORITE_DELETE = 4;
     private static final int ID_BROWSE = 5;
+    private static final int ID_DL_SUBS = 6;
     private ArrayObjectAdapter mRowsAdapter;
     private MediaItemDetails mMedia;
     private MediaWrapper mMediaWrapper;
@@ -66,12 +70,6 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
     private PlaybackService mService;
 
     @Override
-    public void onStop() {
-        super.onStop();
-        PlaybackServiceFragment.unregisterPlaybackService(this, this);
-    }
-
-    @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
@@ -85,6 +83,12 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
         }
     }
 
+    @Override
+    public void onStop() {
+        super.onStop();
+        PlaybackServiceFragment.unregisterPlaybackService(this, this);
+    }
+
     private void buildDetails() {
         Bundle extras = getActivity().getIntent().getExtras();
         mMedia = extras.getParcelable("item");
@@ -135,6 +139,10 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
                         break;
                     case ID_BROWSE:
                         TvUtil.openMedia(getActivity(), media, null);
+                        break;
+                    case ID_DL_SUBS:
+                        MediaUtils.getSubs(getActivity(), media);
+                        break;
                 }
             }
         });
@@ -142,8 +150,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
         selector.addClassPresenter(ListRow.class,
                 new ListRowPresenter());
         mRowsAdapter = new ArrayObjectAdapter(selector);
-
-        if (media.getType() == MediaWrapper.TYPE_DIR) {
+        if (media.getType() == MediaWrapper.TYPE_DIR && FileUtils.canSave(media)) {
             mDb = MediaDatabase.getInstance();
             detailsOverview.setImageDrawable(getResources().getDrawable(TextUtils.equals(media.getUri().getScheme(),"file")
                     ? R.drawable.ic_menu_folder_big
@@ -155,7 +162,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
             else
                 detailsOverview.addAction(actionAdd);
 
-        } else {
+        } else if (media.getType() == MediaWrapper.TYPE_AUDIO) {
             // Add images and action buttons to the details view
             Bitmap cover = AudioUtil.getCover(getActivity(), MediaLibrary.getInstance().getMediaItem(mMedia.getLocation()), 480);
             if (cover == null)
@@ -165,6 +172,17 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
 
             detailsOverview.addAction(new Action(ID_PLAY, "Play"));
             detailsOverview.addAction(new Action(ID_LISTEN, "Listen"));
+        } else if (media.getType() == MediaWrapper.TYPE_VIDEO) {
+            // Add images and action buttons to the details view
+            Bitmap cover = BitmapUtil.getPicture(media);
+            if (cover == null)
+                detailsOverview.setImageDrawable(res.getDrawable(R.drawable.background_cone));
+            else
+                detailsOverview.setImageBitmap(getActivity(), cover);
+
+            detailsOverview.addAction(new Action(ID_PLAY, "Play"));
+            if (FileUtils.canWrite(media.getUri()))
+                detailsOverview.addAction(new Action(ID_DL_SUBS, "Download Subtitles"));
         }
         mRowsAdapter.add(detailsOverview);
 



More information about the Android mailing list