refactor: use WindowInsetsControllerCompat
instead of deprecated methods (#302)
* refactor: remove deprecated methods to hide system ui * fix: action bar reappear after changing the brightness * lint: run ktlintFormat * refactor: remove sdk check * fix: system bars stay visible after closing dialog * fix: add player theme to set navigationbar and statusbar colors to transparent * fix: draw behind navigationbar and statusbar * refactor: remove swipeToShowStatusBars extensions Remove fix for status bar reappearing on LineageOS after changing brightness with gesture. This can always be added back when official Android version from manufacturers also need this fix. --------- Co-authored-by: Jarne Demeulemeester <jarnedemeulemeester@gmail.com>
This commit is contained in:
parent
6b81f1fb1c
commit
8992646090
4 changed files with 39 additions and 20 deletions
|
@ -25,7 +25,8 @@
|
|||
<activity
|
||||
android:name=".PlayerActivity"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||
android:screenOrientation="sensorLandscape" />
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:theme="@style/Theme.Findroid.Player" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package dev.jdtech.jellyfin
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.media3.exoplayer.trackselection.MappingTrackSelector
|
||||
import androidx.media3.session.MediaSession
|
||||
|
@ -14,6 +18,11 @@ abstract class BasePlayerActivity : AppCompatActivity() {
|
|||
|
||||
private lateinit var mediaSession: MediaSession
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
|
@ -40,16 +49,12 @@ abstract class BasePlayerActivity : AppCompatActivity() {
|
|||
mediaSession.release()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
protected fun hideSystemUI() {
|
||||
// These methods are deprecated but we still use them because the new WindowInsetsControllerCompat has a bug which makes the action bar reappear
|
||||
window.decorView.systemUiVisibility = (
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
)
|
||||
WindowCompat.getInsetsController(window, window.decorView).apply {
|
||||
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
hide(WindowInsetsCompat.Type.systemBars())
|
||||
}
|
||||
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.attributes.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
|
@ -68,16 +73,15 @@ abstract class BasePlayerActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
protected fun configureInsets(playerControls: View) {
|
||||
playerControls
|
||||
.setOnApplyWindowInsetsListener { _, windowInsets ->
|
||||
val cutout = windowInsets.displayCutout
|
||||
playerControls.updatePadding(
|
||||
left = cutout?.safeInsetLeft ?: 0,
|
||||
top = cutout?.safeInsetTop ?: 0,
|
||||
right = cutout?.safeInsetRight ?: 0,
|
||||
bottom = cutout?.safeInsetBottom ?: 0,
|
||||
)
|
||||
return@setOnApplyWindowInsetsListener windowInsets
|
||||
}
|
||||
playerControls.setOnApplyWindowInsetsListener { _, windowInsets ->
|
||||
val cutout = windowInsets.displayCutout
|
||||
playerControls.updatePadding(
|
||||
left = cutout?.safeInsetLeft ?: 0,
|
||||
top = cutout?.safeInsetTop ?: 0,
|
||||
right = cutout?.safeInsetRight ?: 0,
|
||||
bottom = cutout?.safeInsetBottom ?: 0,
|
||||
)
|
||||
return@setOnApplyWindowInsetsListener windowInsets
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import androidx.lifecycle.repeatOnLifecycle
|
|||
import androidx.media3.common.C
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.ui.DefaultTimeBar
|
||||
import androidx.media3.ui.PlayerView
|
||||
import androidx.media3.ui.TrackSelectionDialogBuilder
|
||||
import androidx.navigation.navArgs
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
@ -57,6 +58,13 @@ class PlayerActivity : BasePlayerActivity() {
|
|||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
binding.playerView.player = viewModel.player
|
||||
binding.playerView.setControllerVisibilityListener(
|
||||
PlayerView.ControllerVisibilityListener { visibility ->
|
||||
if (visibility == View.GONE) {
|
||||
hideSystemUI()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
val playerControls = binding.playerView.findViewById<View>(R.id.player_controls)
|
||||
val lockedControls = binding.playerView.findViewById<View>(R.id.locked_player_view)
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<resources>
|
||||
<!-- Player theme -->
|
||||
<style name="Theme.Findroid.Player" parent="Base.Theme.Findroid">
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Findroid" parent="Base.Theme.Findroid" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue