From 7c72c4bea146bad5b66ca5040030ae5a739f5250 Mon Sep 17 00:00:00 2001 From: anilbeesetti Date: Wed, 29 Mar 2023 09:24:39 +0530 Subject: [PATCH] Fix two taps required for interacting with player controls --- .../github/libretube/helpers/WindowHelper.kt | 33 +++++++++---------- .../libretube/ui/views/CustomExoPlayerView.kt | 19 +++++++++++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/WindowHelper.kt b/app/src/main/java/com/github/libretube/helpers/WindowHelper.kt index 8fc0a1cb1..fe9604c65 100644 --- a/app/src/main/java/com/github/libretube/helpers/WindowHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/WindowHelper.kt @@ -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) - } - - 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) + activity.showSystemBars() } } } + +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()) + } +} + +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()) + } +} diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 2716dbb72..ef8c1b870 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -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) }