Skip to content

Commit

Permalink
Fix insets handling on Android 10 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 authored and nielsvanvelzen committed May 17, 2023
1 parent dff63a3 commit 17b37fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ class PlayerFragment : Fragment() {

// Insets handling
ViewCompat.setOnApplyWindowInsetsListener(playerBinding.root) { _, insets ->
val systemInsets = insets.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.systemBars())
playerFullscreenHelper.onWindowInsetsChanged(insets)

val systemInsets = when {
AndroidVersion.isAtLeastR -> insets.getInsetsIgnoringVisibility(WindowInsetsCompat.Type.systemBars())
else -> insets.getInsets(WindowInsetsCompat.Type.systemBars())
}
playerControlsView.updatePadding(
top = systemInsets.top,
left = systemInsets.left,
Expand Down Expand Up @@ -301,6 +304,12 @@ class PlayerFragment : Fragment() {
viewModel.skipToNext()
}

fun onPopupDismissed() {
if (!AndroidVersion.isAtLeastR) {
updateFullscreenState(resources.configuration)
}
}

fun onUserLeaveHint() {
if (AndroidVersion.isAtLeastN && viewModel.playerOrNull?.isPlaying == true) {
requireActivity().enterPictureInPicture()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package org.jellyfin.mobile.player.ui

import android.view.View
import android.view.Window
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import org.jellyfin.mobile.utils.AndroidVersion
import org.jellyfin.mobile.utils.extensions.hasFlag

class PlayerFullscreenHelper(private val window: Window) {
private val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
var isFullscreen: Boolean = false
private set

fun onWindowInsetsChanged(insets: WindowInsetsCompat) {
isFullscreen = !insets.isVisible(WindowInsetsCompat.Type.statusBars()) // systemBars() doesn't work here
isFullscreen = when {
AndroidVersion.isAtLeastR -> {
// Type.systemBars() doesn't work here because this would also check for the navigation bar
// which doesn't exist on all devices
!insets.isVisible(WindowInsetsCompat.Type.statusBars())
}
else -> {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility.hasFlag(View.SYSTEM_UI_FLAG_FULLSCREEN)
}
}
}

fun enableFullscreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class PlayerMenus(

override fun onDismiss(menu: PopupMenu) {
fragment.suppressControllerAutoHide(false)
fragment.onPopupDismissed()
}

private fun formatBitrate(bitrate: Double): String {
Expand Down

0 comments on commit 17b37fc

Please sign in to comment.