[Android] TV: Video browsing with alphabetical sorting
Geoffrey Métais
git at videolan.org
Fri Jan 15 16:38:54 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 15 16:34:41 2016 +0100| [7e3a5027617954c9205d894d92a4c3a371a6df92] | committer: Geoffrey Métais
TV: Video browsing with alphabetical sorting
> https://code.videolan.org/videolan/vlc-android/commit/7e3a5027617954c9205d894d92a4c3a371a6df92
---
.../vlc/gui/tv/browser/VerticalGridActivity.java | 6 +-
.../vlc/gui/tv/browser/VideoBrowserFragment.java | 81 ++++++++++++++++++++++
2 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java b/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
index a822fad..159df4c 100644
--- a/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
+++ b/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
@@ -47,7 +47,7 @@ public class VerticalGridActivity extends BaseTvActivity implements BrowserActiv
getWindow().setBackgroundDrawableResource(R.drawable.background);
long type = getIntent().getLongExtra(MainTvActivity.BROWSER_TYPE, -1);
if (type == MainTvActivity.HEADER_VIDEO)
- mFragment = new VideoGridFragment();
+ mFragment = new VideoBrowserFragment();
else if (type == MainTvActivity.HEADER_CATEGORIES)
mFragment = new MusicFragment();
else if (type == MainTvActivity.HEADER_NETWORK)
@@ -72,8 +72,8 @@ public class VerticalGridActivity extends BaseTvActivity implements BrowserActiv
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (mFragment instanceof NetworkBrowserFragment && (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_BUTTON_Y || keyCode == KeyEvent.KEYCODE_Y)) {
- ((NetworkBrowserFragment)mFragment).showDetails();
+ if (mFragment instanceof SortedBrowserFragment && (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_BUTTON_Y || keyCode == KeyEvent.KEYCODE_Y)) {
+ ((SortedBrowserFragment)mFragment).showDetails();
return true;
}
return super.onKeyDown(keyCode, event);
diff --git a/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VideoBrowserFragment.java b/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VideoBrowserFragment.java
new file mode 100644
index 0000000..d3239e8
--- /dev/null
+++ b/vlc-android/flavors/tv/src/org/videolan/vlc/gui/tv/browser/VideoBrowserFragment.java
@@ -0,0 +1,81 @@
+/*
+ * *************************************************************************
+ * VideoBrowserFragment.java
+ * **************************************************************************
+ * Copyright © 2016 VLC authors and VideoLAN
+ * Author: Geoffrey Métais
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * ***************************************************************************
+ */
+
+package org.videolan.vlc.gui.tv.browser;
+
+import android.os.Bundle;
+
+import org.videolan.vlc.gui.tv.MainTvActivity;
+import org.videolan.vlc.media.MediaLibrary;
+import org.videolan.vlc.media.MediaWrapper;
+import org.videolan.vlc.media.Thumbnailer;
+
+import java.util.ArrayList;
+
+public class VideoBrowserFragment extends SortedBrowserFragment {
+
+ protected static Thumbnailer sThumbnailer;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ sThumbnailer = MainTvActivity.getThumbnailer();
+ }
+
+ public void onResume() {
+ super.onResume();
+ if (sThumbnailer != null)
+ sThumbnailer.setVideoBrowser(this);
+ }
+
+ public void onPause() {
+ super.onPause();
+ /* unregister from thumbnailer */
+ if (sThumbnailer != null)
+ sThumbnailer.setVideoBrowser(null);
+ }
+
+ @Override
+ public void refresh() {
+ mMediaIndex.clear();
+ super.refresh();
+ }
+
+ @Override
+ protected void browse() {
+ ArrayList<MediaWrapper> videos = MediaLibrary.getInstance().getVideoItems();
+ MediaWrapper media;
+ for (int i = 0 ; i < videos.size() ; ++i) {
+ media = videos.get(i);
+ String letter = media.getTitle().substring(0, 1).toUpperCase();
+ if (mMediaItemMap.containsKey(letter)){
+ mMediaItemMap.get(letter).mediaList.add(media);
+ } else {
+ ListItem item = new ListItem(letter, media);
+ mMediaItemMap.put(letter, item);
+ }
+ mMediaIndex.put(media.getLocation(), Integer.valueOf(i));
+ }
+ sort();
+ }
+}
More information about the Android
mailing list