Fix two taps required for interacting with player controls

This commit is contained in:
anilbeesetti 2023-03-29 09:24:39 +05:30
parent 3fd5e2144d
commit 7c72c4bea1
2 changed files with 35 additions and 17 deletions

View File

@ -20,25 +20,24 @@ 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)
activity.hideSystemBars()
} else {
controller.show(flags)
activity.showSystemBars()
}
}
}
controller.systemBarsBehavior = if (isFullscreen) {
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
} else {
WindowInsetsControllerCompat.BEHAVIOR_SHOW_BARS_BY_TOUCH
fun Activity.hideSystemBars() {
WindowCompat.getInsetsController(window, window.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars())
}
}
val layoutFlag = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
if (isFullscreen) {
window.setFlags(layoutFlag, layoutFlag)
} else {
window.clearFlags(layoutFlag)
}
fun Activity.showSystemBars() {
WindowCompat.getInsetsController(window, window.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
show(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.navigationBars())
}
}

View File

@ -32,6 +32,8 @@ import com.github.libretube.helpers.AudioHelper
import com.github.libretube.helpers.BrightnessHelper
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.helpers.WindowHelper
import com.github.libretube.helpers.hideSystemBars
import com.github.libretube.helpers.showSystemBars
import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.interfaces.OnlinePlayerOptions
@ -202,6 +204,23 @@ internal class CustomExoPlayerView(
override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) {}
})
setControllerVisibilityListener(
ControllerVisibilityListener { visibility ->
playerViewModel?.isFullscreen?.value?.let { isFullscreen ->
if (isFullscreen) {
when (visibility) {
View.VISIBLE -> {
activity.showSystemBars()
}
View.GONE -> {
activity.hideSystemBars()
}
}
}
}
}
)
playerViewModel?.isFullscreen?.observe(viewLifecycleOwner!!) { isFullscreen ->
WindowHelper.toggleFullscreen(activity, isFullscreen)
}