Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix insets handling on Android 10 and below #1063

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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