[Android] TV: Show sorted view for Songs more than 24
Geoffrey Métais
git at videolan.org
Wed Feb 10 16:35:23 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 10 16:33:46 2016 +0100| [90605cdcf24dbfa29f9045062b0c672899a1fd85] | committer: Geoffrey Métais
TV: Show sorted view for Songs more than 24
> https://code.videolan.org/videolan/vlc-android/commit/90605cdcf24dbfa29f9045062b0c672899a1fd85
---
.../vlc/gui/tv/browser/SongsBrowserFragment.java | 98 ++++++++++++++++++++++
.../vlc/gui/tv/browser/VerticalGridActivity.java | 8 +-
2 files changed, 105 insertions(+), 1 deletion(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java
new file mode 100644
index 0000000..bef2c31
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SongsBrowserFragment.java
@@ -0,0 +1,98 @@
+/*
+ * ************************************************************************
+ * SongsBrowserFragment.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.annotation.TargetApi;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.v17.leanback.widget.Presenter;
+import android.support.v17.leanback.widget.Row;
+import android.support.v17.leanback.widget.RowPresenter;
+import android.text.TextUtils;
+
+import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.gui.helpers.MediaComparators;
+import org.videolan.vlc.gui.tv.TvUtil;
+import org.videolan.vlc.media.MediaLibrary;
+import org.videolan.vlc.media.MediaWrapper;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.TreeMap;
+
+ at TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+public class SongsBrowserFragment extends SortedBrowserFragment {
+
+ private ArrayList<MediaWrapper> mSongs;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void browse() {
+ mSongs = MediaLibrary.getInstance().getAudioItems();
+ MediaWrapper media;
+ for (int i = 0 ; i < mSongs.size() ; ++i) {
+ media = mSongs.get(i);
+ addMedia(media);
+ mMediaIndex.put(media.getLocation(), i);
+ }
+ sort();
+ }
+
+ protected void sort(){
+ VLCApplication.runBackground(new Runnable() {
+ @Override
+ public void run() {
+ Collections.sort(mSongs, MediaComparators.byName);
+ mMediaItemMap = new TreeMap<>(mMediaItemMap); //sort sections
+ for (ListItem item : mMediaItemMap.values()) {
+ Collections.sort(item.mediaList, MediaComparators.byName);
+ }
+ mHandler.sendEmptyMessage(UPDATE_DISPLAY);
+ }
+ });
+ }
+
+ @Override
+ public void onItemClicked(Presenter.ViewHolder viewHolder, final Object item, RowPresenter.ViewHolder viewHolder1, Row row) {
+ VLCApplication.runBackground(new Runnable() {
+ @Override
+ public void run() {
+ int position = 0;
+ String location = ((MediaWrapper)item).getLocation();
+ for (int i = 0; i < mSongs.size(); ++i) {
+ if (TextUtils.equals(location, mSongs.get(i).getLocation())) {
+ position = i;
+ break;
+ }
+ }
+ TvUtil.playAudioList(getActivity(), mSongs, position);
+ }
+ });
+ }
+}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
index d52568f..2b5d677 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
@@ -33,10 +33,12 @@ import org.videolan.vlc.R;
import org.videolan.vlc.gui.tv.MainTvActivity;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserActivityInterface;
import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface;
+import org.videolan.vlc.media.MediaLibrary;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class VerticalGridActivity extends BaseTvActivity implements BrowserActivityInterface {
+ private static final int GRID_LIMIT = 24;
BrowserFragmentInterface mFragment;
ProgressBar mContentLoadingProgressBar;
TextView mEmptyView;
@@ -52,7 +54,11 @@ public class VerticalGridActivity extends BaseTvActivity implements BrowserActiv
if (type == MainTvActivity.HEADER_VIDEO)
mFragment = new VideoBrowserFragment();
else if (type == MainTvActivity.HEADER_CATEGORIES)
- mFragment = new MusicFragment();
+ if (getIntent().getLongExtra(MusicFragment.AUDIO_CATEGORY, MusicFragment.CATEGORY_SONGS) == MusicFragment.CATEGORY_SONGS &&
+ MediaLibrary.getInstance().getAudioItems().size() > GRID_LIMIT)
+ mFragment = new SongsBrowserFragment();
+ else
+ mFragment = new MusicFragment();
else if (type == MainTvActivity.HEADER_NETWORK)
mFragment = new NetworkBrowserFragment();
else if (type == MainTvActivity.HEADER_DIRECTORIES)
More information about the Android
mailing list