[Android] Auto scroll playlist on track change

Geoffrey Métais git at videolan.org
Thu Jan 7 11:45:36 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan  7 11:43:37 2016 +0100| [f8c08749d5db630ceffacec88e118f8494eeb302] | committer: Geoffrey Métais

Auto scroll playlist on track change

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

 .../src/org/videolan/vlc/gui/audio/AudioPlayer.java   | 19 ++++++++++---------
 .../org/videolan/vlc/gui/audio/PlaylistAdapter.java   |  2 ++
 .../videolan/vlc/gui/video/VideoPlayerActivity.java   |  5 +++++
 3 files changed, 17 insertions(+), 9 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 1261bc0..742363f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -365,8 +365,12 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
 
         if (refresh || playlistDiffer())
             updateList();
-        else
-            mPlaylistAdapter.setCurrentIndex(mService.getCurrentMediaPosition());
+        mPlaylist.post(new Runnable() {
+            @Override
+            public void run() {
+                mPlaylistAdapter.setCurrentIndex(mService.getCurrentMediaPosition());
+            }
+        });
     }
 
     private boolean playlistDiffer() {
@@ -433,14 +437,11 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
             mPlaylistAdapter.notifyDataSetChanged();
         else
             mPlaylistAdapter.notifyItemRangeChanged(0, count);
+    }
 
-        final int selectionIndex = currentIndex;
-        mPlaylist.post(new Runnable() {
-            @Override
-            public void run() {
-                mPlaylistAdapter.setCurrentIndex(selectionIndex);
-            }
-        });
+    @Override
+    public void onSelectionSet(int position) {
+        mPlaylist.scrollToPosition(position);
     }
 
     OnSeekBarChangeListener mTimelineListner = new OnSeekBarChangeListener() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
index 8157bbe..a0fd1ad 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/PlaylistAdapter.java
@@ -57,6 +57,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
     public interface IPlayer {
         void onPopupMenu(View view, int position);
         void updateList();
+        void onSelectionSet(int position);
     }
     private static final String TAG = "VLC/PlaylistAdapter";
     PlaybackService mService = null;
@@ -146,6 +147,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
         mCurrentIndex = position;
         notifyItemChanged(former);
         notifyItemChanged(position);
+        mAudioPlayer.onSelectionSet(position);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 2bef442..3acce90 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2122,6 +2122,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     }
 
     @Override
+    public void onSelectionSet(int position) {
+        mPlaylist.scrollToPosition(position);
+    }
+
+    @Override
     public void onClick(View v) {
         switch (v.getId()) {
             case R.id.playlist_toggle:



More information about the Android mailing list