[Android] Propagate expansion state to audioplayer fragment

Geoffrey Métais git at videolan.org
Thu Jan 12 17:15:40 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jan 12 16:43:48 2017 +0100| [b900d6969d1d135030dee3a31353b9894bfa12a6] | committer: Geoffrey Métais

Propagate expansion state to audioplayer fragment

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

 .../vlc/gui/AudioPlayerContainerActivity.java       |  6 +-----
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.java | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index 6dfa65e..e2f7654 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -329,19 +329,15 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
     private class AudioPlayerBottomSheetCallback extends BottomSheetBehavior.BottomSheetCallback {
         @Override
         public void onStateChanged(@NonNull View bottomSheet, int newState) {
+            mAudioPlayer.onStateChanged(newState);
             switch (newState) {
                 case BottomSheetBehavior.STATE_COLLAPSED:
                     mBottomSheetBehavior.setHideable(false);
-                    mAudioPlayer.setHeaderVisibilities(false, false, true, true, true, false);
-                    mAudioPlayer.setUserVisibleHint(false);
                     removeTipViewIfDisplayed();
                     mFragmentContainer.setPadding(0, 0, 0, mBottomSheetBehavior.getPeekHeight());
                     break;
                 case BottomSheetBehavior.STATE_EXPANDED:
                     mBottomSheetBehavior.setHideable(false);
-                    mAudioPlayer.setHeaderVisibilities(true, true, false, false, false, true);
-                    mAudioPlayer.setUserVisibleHint(true);
-                    mAudioPlayer.showPlaylistTips();
                     break;
                 case BottomSheetBehavior.STATE_HIDDEN:
                     removeTipViewIfDisplayed();
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 bd8f987..3be6d0e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -32,6 +32,7 @@ import android.os.Message;
 import android.preference.PreferenceManager;
 import android.support.annotation.Nullable;
 import android.support.annotation.RequiresPermission;
+import android.support.design.widget.BottomSheetBehavior;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.FragmentActivity;
 import android.support.v4.app.FragmentManager;
@@ -86,6 +87,7 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
     private boolean mHeaderPlayPauseVisible;
     private boolean mProgressBarVisible;
     private boolean mHeaderTimeVisible;
+    private int mPlayerState;
 
     // Tips
     private static final String PREF_PLAYLIST_TIPS_SHOWN = "playlist_tips_shown";
@@ -270,7 +272,8 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
 
     @Override
     public void onSelectionSet(int position) {
-        mBinding.songsList.smoothScrollToPosition(position);
+        if (mPlayerState != BottomSheetBehavior.STATE_COLLAPSED && mPlayerState != BottomSheetBehavior.STATE_HIDDEN)
+            mBinding.songsList.smoothScrollToPosition(position);
     }
 
     OnSeekBarChangeListener mTimelineListner = new OnSeekBarChangeListener() {
@@ -652,6 +655,22 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
             activity.showTipViewIfNeeded(R.id.audio_player_tips, PREF_AUDIOPLAYER_TIPS_SHOWN);
     }
 
+    public void onStateChanged(int newState) {
+        mPlayerState = newState;
+        switch (newState) {
+                case BottomSheetBehavior.STATE_COLLAPSED:
+                    setHeaderVisibilities(false, false, true, true, true, false);
+                    setUserVisibleHint(false);
+                    break;
+                case BottomSheetBehavior.STATE_EXPANDED:
+                    setHeaderVisibilities(true, true, false, false, false, true);
+                    setUserVisibleHint(true);
+                    showPlaylistTips();
+                    mPlaylistAdapter.setCurrentIndex(mService.getCurrentMediaPosition());
+                    break;
+        }
+    }
+
     /*
      * Override this method to prefent NPE on mFragmentManager reference.
      */



More information about the Android mailing list