[Android] Limit full list refresh in audio player

Geoffrey Métais git at videolan.org
Wed Jan 6 16:47:29 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan  6 16:46:32 2016 +0100| [2f3f70540cb16bf9e259fb9d6d693d2d0f043cc4] | committer: Geoffrey Métais

Limit full list refresh in audio player

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

 .../src/org/videolan/vlc/gui/audio/AudioPlayer.java       | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
index da1f36d..03e0cac 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -274,7 +274,7 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
         popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
             @Override
             public boolean onMenuItemClick(MenuItem item) {
-                if(item.getItemId() == R.id.audio_player_mini_remove) {
+                if (item.getItemId() == R.id.audio_player_mini_remove) {
                     if (mService != null) {
                         mService.remove(position);
                         return true;
@@ -299,6 +299,10 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
 
     @Override
     public void update() {
+        update(false);
+    }
+
+    public void update(boolean refresh) {
         if (mService == null || getActivity() == null)
             return;
 
@@ -359,7 +363,12 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
         mShuffle.setVisibility(mediaLocations != null && mediaLocations.size() > 2 ? View.VISIBLE : View.INVISIBLE);
         mTimeline.setOnSeekBarChangeListener(mTimelineListner);
 
-        updateList();
+        boolean needsRefresh = (mPlaylistAdapter.getItemCount() != 0) ^ mService.hasMedia();
+
+        if (refresh || needsRefresh)
+            updateList();
+        else
+            mPlaylistAdapter.setCurrentIndex(mService.getCurrentMediaPosition());
     }
 
     @Override
@@ -678,7 +687,7 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
         super.onConnected(service);
         mService.addCallback(this);
         mPlaylistAdapter.setService(service);
-        update();
+        update(true);
     }
 
     @Override



More information about the Android mailing list