[Android] History on TV

Geoffrey Métais git at videolan.org
Mon Jan 25 11:15:30 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 25 11:14:59 2016 +0100| [e010d3bed6b8da2e4a76c46c394dd41c8bfa6a97] | committer: Geoffrey Métais

History on TV

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

 .../org/videolan/vlc/gui/tv/MainTvActivity.java    | 45 +++++++++++++++++-----
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index ad55ab1..9407c3b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -55,6 +55,7 @@ import org.videolan.vlc.StartActivity;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.AudioUtil;
 import org.videolan.vlc.gui.preferences.PreferencesActivity;
+import org.videolan.vlc.gui.preferences.PreferencesFragment;
 import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
 import org.videolan.vlc.gui.tv.browser.BaseTvActivity;
 import org.videolan.vlc.gui.tv.browser.MusicFragment;
@@ -83,6 +84,7 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     public static final long HEADER_NETWORK = 2;
     public static final long HEADER_DIRECTORIES = 3;
     public static final long HEADER_MISC = 4;
+    public static final long HEADER_HISTORY = 5;
 
     private static final int ACTIVITY_RESULT_PREFERENCES = 1;
 
@@ -94,12 +96,9 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     private ProgressBar mProgressBar;
     private static Thumbnailer sThumbnailer;
     ArrayObjectAdapter mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
-    ArrayObjectAdapter mVideoAdapter;
-    ArrayObjectAdapter mCategoriesAdapter;
-    ArrayObjectAdapter mBrowserAdapter;
-    ArrayObjectAdapter mOtherAdapter;
+    ArrayObjectAdapter mVideoAdapter, mCategoriesAdapter, mHistoryAdapter, mBrowserAdapter, mOtherAdapter;
     View mRootContainer;
-    final ArrayMap<String, Integer> mVideoIndex = new ArrayMap<String, Integer>();
+    final ArrayMap<String, Integer> mVideoIndex = new ArrayMap<>(), mHistoryIndex = new ArrayMap<>();
     Drawable mDefaultBackground;
     Activity mContext;
     private Object mSelectedItem;
@@ -305,6 +304,11 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
                 mVideoAdapter.notifyArrayItemRangeChanged(mVideoIndex.get(item.getLocation()).intValue(), 1);
             }
         }
+        if (mHistoryAdapter != null && mHistoryIndex != null && item != null) {
+            if (mHistoryIndex.containsKey(item.getLocation())) {
+                mHistoryAdapter.notifyArrayItemRangeChanged(mHistoryIndex.get(item.getLocation()).intValue(), 1);
+            }
+        }
     }
 
     private Handler mHandler = new VideoListHandler(this);
@@ -326,11 +330,9 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
             intent.putExtra(BROWSER_TYPE, HEADER_CATEGORIES);
             intent.putExtra(MusicFragment.AUDIO_CATEGORY, card.getId());
             startActivity(intent);
-        } else if (row.getId() == HEADER_VIDEO)
-            TvUtil.openMedia(mContext, item, row);
-        else if (row.getId() == HEADER_MISC)
+        } else if (row.getId() == HEADER_MISC)
             startActivityForResult(new Intent(this, org.videolan.vlc.gui.tv.preferences.PreferencesActivity.class), ACTIVITY_RESULT_PREFERENCES);
-        else if (row.getId() == HEADER_NETWORK || row.getId() == HEADER_DIRECTORIES) {
+        else {
             TvUtil.openMedia(mContext, item, row);
         }
     }
@@ -343,7 +345,8 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
 
     public class AsyncUpdate extends AsyncTask<Void, Void, Void> {
         private boolean askRefresh = false;
-        ArrayList<MediaWrapper> videoList;
+        boolean showHistory;
+        ArrayList<MediaWrapper> videoList, history;
 
         public AsyncUpdate() {
         }
@@ -354,8 +357,11 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
 
         @Override
         protected void onPreExecute() {
+
+            showHistory = mSettings.getBoolean(PreferencesFragment.PLAYBACK_HISTORY, true);
             mRowsAdapter.clear();
             mProgressBar.setVisibility(View.VISIBLE);
+            mHistoryIndex.clear();
 
             //Video Section
             mVideoIndex.clear();
@@ -414,6 +420,8 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
         @Override
         protected Void doInBackground(Void... params) {
             videoList = mMediaLibrary.getVideoItems();
+            if (showHistory)
+                history = MediaDatabase.getInstance().getHistory();
             return null;
         }
 
@@ -438,6 +446,23 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
                     }
                 });
             }
+            if (showHistory && !history.isEmpty()){
+                mHistoryAdapter = new ArrayObjectAdapter(
+                        new CardPresenter(mContext));
+                final HeaderItem historyHeader = new HeaderItem(HEADER_HISTORY, getString(R.string.history));
+                mRootContainer.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        MediaWrapper item;
+                        for (int i = 0; i < history.size(); ++i) {
+                            item = history.get(i);
+                            mHistoryAdapter.add(item);
+                            mHistoryIndex.put(item.getLocation(), Integer.valueOf(i));
+                        }
+                        mRowsAdapter.add(2, new ListRow(historyHeader, mHistoryAdapter));
+                    }
+                });
+            }
             if (!mMediaLibrary.isWorking())
                 mProgressBar.setVisibility(View.GONE);
             if (askRefresh) { //in case new event occured while loading view



More information about the Android mailing list