diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt index 181d129ff..5d0cf0348 100644 --- a/app/src/main/java/com/github/libretube/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/MainActivity.kt @@ -2,16 +2,20 @@ package com.github.libretube import android.content.res.Configuration import android.content.res.Resources +import android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log -import android.view.Menu -import android.view.MenuItem -import android.view.View +import android.view.* import android.widget.FrameLayout import androidx.appcompat.widget.Toolbar import androidx.constraintlayout.motion.widget.MotionLayout import androidx.core.text.HtmlCompat +import androidx.core.view.ViewCompat +import androidx.core.view.ViewCompat.getWindowInsetsController +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat +import androidx.core.view.WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE import androidx.fragment.app.Fragment import androidx.navigation.NavController import androidx.navigation.Navigation @@ -111,18 +115,66 @@ class MainActivity : AppCompatActivity() { val orientation = newConfig.orientation if (orientation == Configuration.ORIENTATION_PORTRAIT) { println("Portrait") + unsetFullscreen() //findViewById(R.id.playerMotionLayout).getTransition(R.id.yt_transition).isEnabled = true } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { println("Landscape") - window.decorView.apply { + setFullscreen() +/* window.decorView.apply { // Hide both the navigation bar and the status bar. // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as // a general rule, you should design your app to hide the status bar whenever you // hide the navigation bar. systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN - } - //findViewById(R.id.playerMotionLayout).getTransition(R.id.yt_transition).isEnabled = false + }*/ + } + } + private fun hideSystemBars() { + val windowInsetsController = + getWindowInsetsController(window.decorView) ?: return + // Configure the behavior of the hidden system bars + windowInsetsController.systemBarsBehavior = + BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + // Hide both the status bar and the navigation bar + //windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) + } + private fun setFullscreen() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + window.attributes.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.setDecorFitsSystemWindows(false) + window.insetsController?.apply { + hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()) + systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + @Suppress("DEPRECATION") + window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN + or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + or View.SYSTEM_UI_FLAG_IMMERSIVE + or View.SYSTEM_UI_FLAG_LAYOUT_STABLE + or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) + } + } + private fun unsetFullscreen(){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + window.attributes.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.setDecorFitsSystemWindows(false) + window.insetsController?.apply { + show(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()) + systemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT + } + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + @Suppress("DEPRECATION") + window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_VISIBLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE) } } }