[Android] Postpone initial audio player cover mode after the behavior layout
Nicolas Pomepuy
git at videolan.org
Thu Nov 18 08:09:37 UTC 2021
vlc-android | branch: 3.4.x | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Nov 15 08:53:45 2021 +0100| [0bd3732c6651cfc81fb683b40c1b367eab5e749e] | committer: Nicolas Pomepuy
Postpone initial audio player cover mode after the behavior layout
Fixes #2241
(cherry picked from commit dd9f484b23da2b66d084b37ce8385fe0184dd921)
> https://code.videolan.org/videolan/vlc-android/commit/0bd3732c6651cfc81fb683b40c1b367eab5e749e
---
.../src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt | 7 +++++++
.../vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 1 -
.../src/org/videolan/vlc/gui/helpers/PlayerBehavior.kt | 9 +++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
index e0b585843..8ff8be7ba 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
@@ -171,6 +171,13 @@ open class AudioPlayerContainerActivity : BaseActivity() {
if (bottomIsHiddden) bottomBehavior?.setCollapsed()
playerBehavior.peekHeight = resources.getDimensionPixelSize(R.dimen.player_peek_height)
updateFragmentMargins()
+ playerBehavior.setLayoutListener {
+ // [AudioPlayer.showCover] applies a new [ConstraintSet]. It cannot be done in [AudioPlayer.onCreate] because it would compete with
+ // [BottomSheetBehavior.onLayoutChild] and prevent any scroll event to be forwarded by the ConstraintLayout views (the bookmark list for example)
+ // That why we wait that the layout has been done to perform this. See https://code.videolan.org/videolan/vlc-android/-/issues/2241#note_291050
+ audioPlayer.showCover(settings.getBoolean("audio_player_show_cover", false))
+ if (playerBehavior.state == STATE_COLLAPSED) audioPlayer.onSlide(0f)
+ }
playerBehavior.addBottomSheetCallback(object : BottomSheetCallback() {
override fun onSlide(bottomSheet: View, slideOffset: Float) {
audioPlayer.onSlide(slideOffset)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 82d2cc08b..512f9843d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -164,7 +164,6 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
registerForContextMenu(binding.songsList)
userVisibleHint = true
- showCover(settings.getBoolean("audio_player_show_cover", false))
binding.playlistSwitch.setImageResource(if (isShowingCover()) R.drawable.ic_playlist_audio else R.drawable.ic_playlist_audio_on)
binding.timeline.setOnSeekBarChangeListener(timelineListener)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerBehavior.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerBehavior.kt
index 632adbaba..a3034afb9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerBehavior.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerBehavior.kt
@@ -10,12 +10,15 @@ import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.tools.dp
+import java.util.concurrent.atomic.AtomicBoolean
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
class PlayerBehavior<V : View> : com.google.android.material.bottomsheet.BottomSheetBehavior<V> {
private var lock = false
private var listener : ((top:Int) -> Unit)? = null
+ private var layoutListener : (() -> Unit)? = null
+ private var layoutDone = AtomicBoolean(false)
constructor() {
isHideable = true
@@ -42,6 +45,10 @@ class PlayerBehavior<V : View> : com.google.android.material.bottomsheet.BottomS
this.listener = null
}
+ fun setLayoutListener(listener : () -> Unit) {
+ this.layoutListener = listener
+ }
+
fun lock(lock: Boolean) {
this.lock = lock
}
@@ -145,6 +152,8 @@ class PlayerBehavior<V : View> : com.google.android.material.bottomsheet.BottomS
super.onLayoutChild(parent, child, layoutDirection)
} catch (ignored: IndexOutOfBoundsException) {
false
+ } finally {
+ if (!layoutDone.getAndSet(true)) layoutListener?.invoke()
}
override fun onTouchEvent(parent: CoordinatorLayout, child: V, event: MotionEvent): Boolean {
More information about the Android
mailing list