mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
use window insets compat controller (#847)
This commit is contained in:
parent
e5f483b0b2
commit
19b1a40cf8
3 changed files with 56 additions and 80 deletions
|
@ -379,7 +379,6 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun exitFullscreen() {
|
protected fun exitFullscreen() {
|
||||||
activity?.showSystemUI()
|
|
||||||
//if (lockRotation)
|
//if (lockRotation)
|
||||||
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER
|
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER
|
||||||
|
|
||||||
|
@ -391,6 +390,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
|
||||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
|
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
|
||||||
}
|
}
|
||||||
activity?.window?.attributes = lp
|
activity?.window?.attributes = lp
|
||||||
|
activity?.showSystemUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
|
|
@ -1383,6 +1383,7 @@ class GeneratorPlayer : FullScreenPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding?.playerLoadingGoBack?.setOnClickListener {
|
binding?.playerLoadingGoBack?.setOnClickListener {
|
||||||
|
exitFullscreen()
|
||||||
player.release()
|
player.release()
|
||||||
activity?.popCurrentPage()
|
activity?.popCurrentPage()
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import androidx.core.graphics.blue
|
||||||
import androidx.core.graphics.drawable.toBitmapOrNull
|
import androidx.core.graphics.drawable.toBitmapOrNull
|
||||||
import androidx.core.graphics.green
|
import androidx.core.graphics.green
|
||||||
import androidx.core.graphics.red
|
import androidx.core.graphics.red
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.marginBottom
|
import androidx.core.view.marginBottom
|
||||||
import androidx.core.view.marginLeft
|
import androidx.core.view.marginLeft
|
||||||
import androidx.core.view.marginRight
|
import androidx.core.view.marginRight
|
||||||
|
@ -401,81 +402,35 @@ object UIHelper {
|
||||||
// Enables regular immersive mode.
|
// Enables regular immersive mode.
|
||||||
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
|
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
|
||||||
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
window.decorView.systemUiVisibility = (
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
||||||
// Set the content to appear under the system bars so that the
|
if (window.insetsController != null) {
|
||||||
// content doesn't resize when the system bars hide and show.
|
|
||||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
window!!.insetsController?.hide(WindowInsetsCompat.Type.systemBars())
|
||||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
window!!.insetsController?.systemBarsBehavior =
|
||||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
// Hide the nav bar and status bar
|
}
|
||||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
}
|
||||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
|
||||||
// or View.SYSTEM_UI_FLAG_LOW_PROFILE
|
else {
|
||||||
)
|
@Suppress("DEPRECATION")
|
||||||
// window.addFlags(View.KEEP_SCREEN_ON)
|
window.decorView.systemUiVisibility = (
|
||||||
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
// Set the content to appear under the system bars so that the
|
||||||
|
// content doesn't resize when the system bars hide and show.
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
// Hide the nav bar and status bar
|
||||||
|
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FragmentActivity.popCurrentPage() {
|
fun FragmentActivity.popCurrentPage() {
|
||||||
this.onBackPressedDispatcher.onBackPressed()
|
this.onBackPressedDispatcher.onBackPressed()
|
||||||
/*val currentFragment = supportFragmentManager.fragments.lastOrNull {
|
|
||||||
it.isVisible
|
|
||||||
} ?: return
|
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.setCustomAnimations(
|
|
||||||
R.anim.enter_anim,
|
|
||||||
R.anim.exit_anim,
|
|
||||||
R.anim.pop_enter,
|
|
||||||
R.anim.pop_exit
|
|
||||||
)
|
|
||||||
.remove(currentFragment)
|
|
||||||
.commitAllowingStateLoss()*/
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
fun FragmentActivity.popCurrentPage(isInPlayer: Boolean, isInExpandedView: Boolean, isInResults: Boolean) {
|
|
||||||
val currentFragment = supportFragmentManager.fragments.lastOrNull {
|
|
||||||
it.isVisible
|
|
||||||
}
|
|
||||||
?: //this.onBackPressedDispatcher.onBackPressed()
|
|
||||||
return
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (tvActivity == null) {
|
|
||||||
requestedOrientation = if (settingsManager?.getBoolean("force_landscape", false) == true) {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
|
||||||
} else {
|
|
||||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// No fucked animations leaving the player :)
|
|
||||||
when {
|
|
||||||
isInPlayer -> {
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
//.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
|
|
||||||
.remove(currentFragment)
|
|
||||||
.commitAllowingStateLoss()
|
|
||||||
}
|
|
||||||
isInExpandedView && !isInResults -> {
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.setCustomAnimations(
|
|
||||||
R.anim.enter_anim,//R.anim.enter_from_right,
|
|
||||||
R.anim.exit_anim,//R.anim.exit_to_right,
|
|
||||||
R.anim.pop_enter,
|
|
||||||
R.anim.pop_exit
|
|
||||||
)
|
|
||||||
.remove(currentFragment)
|
|
||||||
.commitAllowingStateLoss()
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.pop_enter, R.anim.pop_exit)
|
|
||||||
.remove(currentFragment)
|
|
||||||
.commitAllowingStateLoss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
fun Context.getStatusBarHeight(): Int {
|
fun Context.getStatusBarHeight(): Int {
|
||||||
if (isTvSettings()) {
|
if (isTvSettings()) {
|
||||||
|
@ -541,14 +496,27 @@ object UIHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.changeStatusBarState(hide: Boolean): Int {
|
fun Activity.changeStatusBarState(hide: Boolean): Int {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
return if (hide) {
|
return if (hide) {
|
||||||
window?.setFlags(
|
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
window.insetsController?.hide(WindowInsets.Type.statusBars())
|
||||||
)
|
|
||||||
|
} else {
|
||||||
|
window.setFlags(
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||||
|
)
|
||||||
|
}
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
window.insetsController?.show(WindowInsets.Type.statusBars())
|
||||||
|
|
||||||
|
} else {
|
||||||
|
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
|
}
|
||||||
|
|
||||||
this.getStatusBarHeight()
|
this.getStatusBarHeight()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -556,13 +524,20 @@ object UIHelper {
|
||||||
// Shows the system bars by removing all the flags
|
// Shows the system bars by removing all the flags
|
||||||
// except for the ones that make the content appear under the system bars.
|
// except for the ones that make the content appear under the system bars.
|
||||||
fun Activity.showSystemUI() {
|
fun Activity.showSystemUI() {
|
||||||
window.decorView.systemUiVisibility =
|
|
||||||
|
|
||||||
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
|
||||||
|
if (window.insetsController != null) {
|
||||||
|
window!!.insetsController?.show(WindowInsetsCompat.Type.systemBars())
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
window.decorView.systemUiVisibility =
|
||||||
|
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
|
||||||
|
}
|
||||||
|
|
||||||
changeStatusBarState(isEmulatorSettings())
|
changeStatusBarState(isEmulatorSettings())
|
||||||
|
|
||||||
// window.clearFlags(View.KEEP_SCREEN_ON)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.shouldShowPIPMode(isInPlayer: Boolean): Boolean {
|
fun Context.shouldShowPIPMode(isInPlayer: Boolean): Boolean {
|
||||||
|
|
Loading…
Reference in a new issue