[Android] Now PLaying tile on TV + UI update refactoring

Geoffrey Métais git at videolan.org
Tue Jul 21 16:01:17 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 21 16:00:35 2015 +0200| [1c3150694081a20690e235dcc9336adc3ee42adc] | committer: Geoffrey Métais

Now PLaying tile on TV + UI update refactoring

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

 vlc-android/res/values/strings.xml                 |    1 +
 .../org/videolan/vlc/gui/tv/MainTvActivity.java    |   31 +++++++++++++++-----
 .../videolan/vlc/gui/tv/browser/MusicFragment.java |    1 +
 3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 1887ff9..cdbfa19 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -351,6 +351,7 @@
     <string name="playlist_deleted">Playlist deleted</string>
     <string name="file_deleted">File deleted</string>
     <string name="no_subs_found">No subtitles in this directory</string>
+    <string name="music_now_playing">Now Playing</string>
 
     <string-array name="hardware_acceleration_list">
         <item>@string/automatic</item>
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index 4defe35..7dbeb08 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -97,6 +97,7 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     Drawable mDefaultBackground;
     Activity mContext;
     private Object mSelectedItem;
+    private AsyncUpdate mUpdateTask;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -140,10 +141,8 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
         /*
          * skip browser and show directly Audio Player if a song is playing
          */
-        if (service.isPlaying()) {
-            if (!service.canSwitchToVideo())
-                startActivity(new Intent(this, AudioPlayerActivity.class));
-            finish();
+        if (service.isPlaying() && !service.canSwitchToVideo()) {
+            updateList();
         }
     }
 
@@ -161,9 +160,6 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
         if (sThumbnailer != null)
             sThumbnailer.setVideoBrowser(this);
 
-        if (mMediaLibrary.isWorking()) //Display UI while MediaLib is scanning
-            updateList();
-
         mBrowseFragment.setBrandColor(getResources().getColor(R.color.orange800));
     }
 
@@ -232,7 +228,12 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     }
 
     public void updateList() {
-        new AsyncUpdate().execute();
+        if (mUpdateTask == null || mUpdateTask.getStatus() == AsyncTask.Status.FINISHED) {
+            mUpdateTask = new AsyncUpdate();
+            mUpdateTask.execute();
+        } else {
+            mUpdateTask.AskRefresh();
+        }
         checkThumbs();
     }
 
@@ -295,6 +296,10 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     @Override
     public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
         if (row.getId() == HEADER_CATEGORIES) {
+            if (((CardPresenter.SimpleCard)item).getId() == MusicFragment.CATEGORY_NOW_PLAYING){ //NOW PLAYING CARD
+                startActivity(new Intent(this, AudioPlayerActivity.class));
+                return;
+            }
             CardPresenter.SimpleCard card = (CardPresenter.SimpleCard) item;
             Intent intent = new Intent(mContext, VerticalGridActivity.class);
             intent.putExtra(BROWSER_TYPE, HEADER_CATEGORIES);
@@ -316,10 +321,15 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     }
 
     public class AsyncUpdate extends AsyncTask<Void, Void, Void> {
+        private boolean askRefresh = false;
 
         public AsyncUpdate() {
         }
 
+        public void AskRefresh() { //Ask for refresh while update is ongoing
+            askRefresh = true;
+        }
+
         @Override
         protected void onPreExecute() {
             mRowsAdapter.clear();
@@ -336,6 +346,8 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
             //Music sections
             mCategoriesAdapter = new ArrayObjectAdapter(new CardPresenter(mContext));
             final HeaderItem musicHeader = new HeaderItem(HEADER_CATEGORIES, getString(R.string.audio));
+            if (mService != null && mService.hasMedia() && !mService.canSwitchToVideo())
+                mCategoriesAdapter.add(new CardPresenter.SimpleCard(MusicFragment.CATEGORY_NOW_PLAYING, getString(R.string.music_now_playing), R.drawable.ic_play_circle_big_o));
             mCategoriesAdapter.add(new CardPresenter.SimpleCard(MusicFragment.CATEGORY_ARTISTS, getString(R.string.artists), R.drawable.ic_artist_big));
             mCategoriesAdapter.add(new CardPresenter.SimpleCard(MusicFragment.CATEGORY_ALBUMS, getString(R.string.albums), R.drawable.ic_album_big));
             mCategoriesAdapter.add(new CardPresenter.SimpleCard(MusicFragment.CATEGORY_GENRES, getString(R.string.genres), R.drawable.ic_genre_big));
@@ -393,6 +405,9 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
         protected void onPostExecute(Void result) {
             if (!mMediaLibrary.isWorking())
                 mProgressBar.setVisibility(View.GONE);
+            if (askRefresh) { //in case new event occured while loading view
+                mHandler.sendEmptyMessage(VideoListHandler.MEDIA_ITEMS_UPDATED);
+            }
         }
     }
 
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/MusicFragment.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/MusicFragment.java
index 590bef1..c66934b 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/MusicFragment.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/browser/MusicFragment.java
@@ -55,6 +55,7 @@ public class MusicFragment extends MediaLibBrowserFragment {
     public static final long FILTER_ARTIST = 3;
     public static final long FILTER_GENRE = 4;
 
+    public static final int CATEGORY_NOW_PLAYING = 0;
     public static final int CATEGORY_ARTISTS = 1;
     public static final int CATEGORY_ALBUMS = 2;
     public static final int CATEGORY_GENRES = 3;



More information about the Android mailing list