From 1f13c0a67f54a4ce87fe65f5699a42b63b11f15b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 23 Aug 2022 09:37:10 +0200 Subject: [PATCH] fix status bar --- .../libretube/activities/MainActivity.kt | 32 +++++++++++++++++++ .../libretube/views/CustomExoPlayerView.kt | 8 ++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index d54f59104..95066ffa8 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -494,6 +494,8 @@ class MainActivity : BaseActivity() { private fun unsetFullscreen() { window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) + showSystemBars() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT @@ -512,6 +514,36 @@ class MainActivity : BaseActivity() { } } + /** + * hide the status bar + */ + fun hideSystemBars() { + if (resources.configuration.orientation != Configuration.ORIENTATION_LANDSCAPE) return + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.insetsController?.hide(WindowInsets.Type.statusBars()) + } else { + @Suppress("DEPRECATION") + window.setFlags( + WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN + ) + } + } + + /** + * show the status bar + */ + fun showSystemBars() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.insetsController?.show(WindowInsets.Type.statusBars()) + } else { + @Suppress("DEPRECATION") + window.clearFlags( + WindowManager.LayoutParams.FLAG_FULLSCREEN + ) + } + } + override fun onUserLeaveHint() { super.onUserLeaveHint() supportFragmentManager.fragments.forEach { fragment -> diff --git a/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt index c5f6a1fa9..1b70e4d21 100644 --- a/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/views/CustomExoPlayerView.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.util.AttributeSet import android.view.MotionEvent +import com.github.libretube.activities.MainActivity import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.interfaces.DoubleTapInterface import com.github.libretube.util.DoubleTapListener @@ -31,7 +32,7 @@ internal class CustomExoPlayerView( if (isControllerFullyVisible) hideController() else showController() } - val doubleTouchListener = object : DoubleTapListener() { + private val doubleTouchListener = object : DoubleTapListener() { override fun onDoubleClick() { doubleTapListener?.onEvent(xPos) } @@ -46,6 +47,11 @@ internal class CustomExoPlayerView( setOnClickListener(doubleTouchListener) } + override fun hideController() { + (context as? MainActivity)?.hideSystemBars() + super.hideController() + } + override fun onTouchEvent(event: MotionEvent): Boolean { // save the x position of the touch event xPos = event.x