[Android] Safer playlist check before update

Geoffrey Métais git at videolan.org
Thu Jan 7 10:39:56 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan  7 10:39:34 2016 +0100| [a470a915e545f9859c4bcec9e1b7af51444f1e86] | committer: Geoffrey Métais

Safer playlist check before update

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

 .../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 03e0cac..c05a671 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -363,14 +363,23 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
         mShuffle.setVisibility(mediaLocations != null && mediaLocations.size() > 2 ? View.VISIBLE : View.INVISIBLE);
         mTimeline.setOnSeekBarChangeListener(mTimelineListner);
 
-        boolean needsRefresh = (mPlaylistAdapter.getItemCount() != 0) ^ mService.hasMedia();
-
-        if (refresh || needsRefresh)
+        if (refresh || playlistDiffer())
             updateList();
         else
             mPlaylistAdapter.setCurrentIndex(mService.getCurrentMediaPosition());
     }
 
+    private boolean playlistDiffer() {
+        List<MediaWrapper> serviceList = mService.getMedias();
+        List<MediaWrapper> adapterList = mPlaylistAdapter.getMedias();
+        if (serviceList.size() != adapterList.size())
+            return true;
+        for (int i = 0 ; i < serviceList.size() ; ++i)
+            if (serviceList.get(i) != adapterList.get(i))
+                return true;
+        return false;
+    }
+
     @Override
     public void updateProgress() {
         if (mService == null)



More information about the Android mailing list