mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #3450 from anilbeesetti/fix-statusbar
Fix two taps required to interact with player when in fullscreen mode
This commit is contained in:
commit
89bc48e3f3
@ -5,7 +5,7 @@ import android.os.Build
|
||||
import android.view.WindowManager
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import com.github.libretube.ui.extensions.toggleSystemBars
|
||||
|
||||
object WindowHelper {
|
||||
fun toggleFullscreen(activity: Activity, isFullscreen: Boolean) {
|
||||
@ -20,25 +20,12 @@ object WindowHelper {
|
||||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, !isFullscreen)
|
||||
|
||||
val controller = WindowCompat.getInsetsController(window, window.decorView)
|
||||
val flags = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars()
|
||||
if (isFullscreen) {
|
||||
controller.hide(flags)
|
||||
} else {
|
||||
controller.show(flags)
|
||||
}
|
||||
|
||||
controller.systemBarsBehavior = if (isFullscreen) {
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
} else {
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
|
||||
}
|
||||
|
||||
val layoutFlag = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
||||
if (isFullscreen) {
|
||||
window.setFlags(layoutFlag, layoutFlag)
|
||||
} else {
|
||||
window.clearFlags(layoutFlag)
|
||||
}
|
||||
// Show the system bars when it is not fullscreen and hide them when it is fullscreen
|
||||
// System bars means status bar and the navigation bar
|
||||
// See: https://developer.android.com/training/system-ui/immersive#kotlin
|
||||
activity.toggleSystemBars(
|
||||
types = WindowInsetsCompat.Type.systemBars(),
|
||||
showBars = !isFullscreen
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.github.libretube.ui.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat.Type.InsetsType
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
|
||||
fun Activity.toggleSystemBars(@InsetsType types: Int, showBars: Boolean) {
|
||||
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
if (showBars) {
|
||||
show(types)
|
||||
} else {
|
||||
hide(types)
|
||||
}
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginStart
|
||||
import androidx.core.view.updateLayoutParams
|
||||
@ -34,6 +35,7 @@ import com.github.libretube.helpers.PlayerHelper
|
||||
import com.github.libretube.helpers.WindowHelper
|
||||
import com.github.libretube.obj.BottomSheetItem
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.ui.extensions.toggleSystemBars
|
||||
import com.github.libretube.ui.interfaces.OnlinePlayerOptions
|
||||
import com.github.libretube.ui.interfaces.PlayerGestureOptions
|
||||
import com.github.libretube.ui.interfaces.PlayerOptions
|
||||
@ -202,6 +204,19 @@ internal class CustomExoPlayerView(
|
||||
override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) {}
|
||||
})
|
||||
|
||||
setControllerVisibilityListener(
|
||||
ControllerVisibilityListener { visibility ->
|
||||
playerViewModel?.isFullscreen?.value?.let { isFullscreen ->
|
||||
if (!isFullscreen) return@let
|
||||
// Show status bar only not navigation bar if the player controls are visible and hide it otherwise
|
||||
activity.toggleSystemBars(
|
||||
types = WindowInsetsCompat.Type.statusBars(),
|
||||
showBars = visibility == View.VISIBLE
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
playerViewModel?.isFullscreen?.observe(viewLifecycleOwner!!) { isFullscreen ->
|
||||
WindowHelper.toggleFullscreen(activity, isFullscreen)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user