[Android] Fix status bar not hidden in sub activities on orientation change

Nicolas Pomepuy git at videolan.org
Mon Mar 28 12:37:29 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Mar 28 07:57:42 2022 +0200| [4043d612a6714de50ce321ac44b8900df11fbf0b] | committer: Duncan McNamara

Fix status bar not hidden in sub activities on orientation change

Fixes #2454

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

 .../videolan/vlc/gui/AudioPlayerContainerActivity.kt   | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

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 f0378d1ca..7aa763e81 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
@@ -209,7 +209,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
         playerBehavior = from(audioPlayerContainer) as PlayerBehavior<*>
         val bottomBehavior = bottomBar?.let { BottomNavigationBehavior.from(it) as BottomNavigationBehavior<View> }
                 ?: null
-        if (bottomIsHiddden) bottomBehavior?.setCollapsed()
+        if (bottomIsHiddden) bottomBehavior?.setCollapsed() else hideStatusIfNeeded(playerBehavior.state)
         playerBehavior.peekHeight = resources.getDimensionPixelSize(R.dimen.player_peek_height)
         updateFragmentMargins()
         playerBehavior.setPeekHeightListener {
@@ -236,12 +236,7 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
 
             override fun onStateChanged(bottomSheet: View, newState: Int) {
                 onPlayerStateChanged(bottomSheet, newState)
-                if (!needsTopInset()) {
-                    WindowInsetsControllerCompat(window, window.decorView).apply {
-                        systemBarsBehavior = if (newState == STATE_EXPANDED) WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE else WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
-                        if (newState == STATE_EXPANDED) hide(WindowInsetsCompat.Type.statusBars()) else show(WindowInsetsCompat.Type.statusBars())
-                    }
-                }
+                hideStatusIfNeeded(newState)
                 audioPlayer.onStateChanged(newState)
                 if (newState == STATE_COLLAPSED || newState == STATE_HIDDEN) removeTipViewIfDisplayed()
                 updateFragmentMargins(newState)
@@ -253,6 +248,15 @@ open class AudioPlayerContainerActivity : BaseActivity(), KeycodeListener {
         if (playlistTipsDelegate.currentTip != null) lockPlayer(true)
     }
 
+    private fun hideStatusIfNeeded(newState: Int) {
+        if (!needsTopInset()) {
+            WindowInsetsControllerCompat(window, window.decorView).apply {
+                systemBarsBehavior = if (newState == STATE_EXPANDED) WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE else WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
+                if (newState == STATE_EXPANDED) hide(WindowInsetsCompat.Type.statusBars()) else show(WindowInsetsCompat.Type.statusBars())
+            }
+        }
+    }
+
     override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
         if (playerKeyListenerDelegate.onKeyDown(keyCode, event)) return true
         return super.onKeyDown(keyCode, event)



More information about the Android mailing list