[Android] Hide audio player on lists scroll

Geoffrey Métais git at videolan.org
Tue Jan 22 14:27:11 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jan 22 14:10:20 2019 +0100| [6b290fb9763fded1c2361ab94a1a59aa9cb069df] | committer: Geoffrey Métais

Hide audio player on lists scroll

see #729

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

 .../vlc/gui/AudioPlayerContainerActivity.java      | 25 ++++++++++++++++------
 .../vlc/gui/helpers/BottomSheetBehavior.java       | 18 +++++++++++++++-
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index ef8a5ca5a..3053dc600 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -28,7 +28,6 @@ import android.media.AudioManager;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
-import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
@@ -242,15 +241,20 @@ public class AudioPlayerContainerActivity extends BaseActivity {
     /**
      * Show the audio player.
      */
-    public synchronized void showAudioPlayer() {
+    public void showAudioPlayer() {
+        mActivityHandler.sendEmptyMessageDelayed(ACTION_SHOW_PLAYER, 100L);
+    }
+
+    private void showAudioPlayerImpl() {
         if (!isAudioPlayerReady()) initAudioPlayer();
-        if (mAudioPlayerContainer.getVisibility() == View.GONE) {
+        if (mAudioPlayerContainer.getVisibility() != View.VISIBLE) {
             mAudioPlayerContainer.setVisibility(View.VISIBLE);
         }
         if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
             mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
         }
         mBottomSheetBehavior.setHideable(false);
+        mBottomSheetBehavior.lock(false);
     }
 
     /**
@@ -278,6 +282,10 @@ public class AudioPlayerContainerActivity extends BaseActivity {
      * Hide the audio player.
      */
     public void hideAudioPlayer() {
+        mActivityHandler.sendEmptyMessage(ACTION_HIDE_PLAYER);
+    }
+
+    private void hideAudioPlayerImpl() {
         if (!isAudioPlayerReady()) return;
         mBottomSheetBehavior.setHideable(true);
         mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
@@ -366,8 +374,11 @@ public class AudioPlayerContainerActivity extends BaseActivity {
         PlaylistManager.Companion.getShowAudioPlayer().observe(this, new Observer<Boolean>() {
             @Override
             public void onChanged(@Nullable Boolean showPlayer) {
-                if (showPlayer) mActivityHandler.sendEmptyMessageDelayed(ACTION_SHOW_PLAYER, 100L);
-                else mActivityHandler.sendEmptyMessage(ACTION_HIDE_PLAYER);
+                if (showPlayer) showAudioPlayer();
+                else {
+                    hideAudioPlayer();
+                    if (mBottomSheetBehavior != null) mBottomSheetBehavior.lock(true);
+                }
             }
         });
         MediaParsingService.Companion.getProgress().observe(this, new Observer<ScanProgress>() {
@@ -416,13 +427,13 @@ public class AudioPlayerContainerActivity extends BaseActivity {
                     owner.showProgressBar();
                     break;
                 case ACTION_SHOW_PLAYER:
-                    owner.showAudioPlayer();
+                    owner.showAudioPlayerImpl();
                     owner.updateContainerPadding(true);
                     owner.applyMarginToProgressBar(owner.mBottomSheetBehavior.getPeekHeight());
                     break;
                 case ACTION_HIDE_PLAYER:
                     removeMessages(ACTION_SHOW_PLAYER);
-                    owner.hideAudioPlayer();
+                    owner.hideAudioPlayerImpl();
                     owner.updateContainerPadding(false);
                     owner.applyMarginToProgressBar(0);
                     break;
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java b/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java
index f41bd55bb..05748f74c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/BottomSheetBehavior.java
@@ -5,6 +5,8 @@ import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
 
+import org.videolan.vlc.gui.AudioPlayerContainerActivity;
+
 import androidx.annotation.NonNull;
 import androidx.coordinatorlayout.widget.CoordinatorLayout;
 
@@ -13,7 +15,9 @@ public class BottomSheetBehavior<V extends View> extends com.google.android.mate
     public static final String TAG = "VLC/BottomSheetBehavior";
     private boolean lock = false;
 
-    public BottomSheetBehavior() {}
+    public BottomSheetBehavior() {
+        setHideable(true);
+    }
 
     public BottomSheetBehavior(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -34,6 +38,18 @@ public class BottomSheetBehavior<V extends View> extends com.google.android.mate
         }
     }
 
+    @Override
+    public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull V child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
+        if (lock) return;
+        if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
+            final AudioPlayerContainerActivity activity = (AudioPlayerContainerActivity) child.getContext();
+            activity.hideAudioPlayer();
+        } else if (dyConsumed < 0 && getState() == BottomSheetBehavior.STATE_HIDDEN) {
+            final AudioPlayerContainerActivity activity = (AudioPlayerContainerActivity) child.getContext();
+            activity.showAudioPlayer();
+        }
+    }
+
     @Override
     public void onStopNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull V child, @NonNull View target, int type) {
         if (lock) return;



More information about the Android mailing list