-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework fullscreen/insets handling and fix deprecations
- Loading branch information
1 parent
a0ea262
commit cea6224
Showing
5 changed files
with
91 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/jellyfin/mobile/player/ui/PlayerFullscreenHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jellyfin.mobile.player.ui | ||
|
||
import android.view.Window | ||
import androidx.core.view.WindowCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.core.view.WindowInsetsControllerCompat | ||
|
||
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 | ||
} | ||
|
||
fun enableFullscreen() { | ||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) | ||
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE | ||
} | ||
|
||
fun disableFullscreen() { | ||
WindowCompat.setDecorFitsSystemWindows(window, true) | ||
windowInsetsController.show(WindowInsetsCompat.Type.systemBars()) | ||
} | ||
|
||
fun toggleFullscreen() { | ||
if (isFullscreen) disableFullscreen() else enableFullscreen() | ||
} | ||
} |
29 changes: 1 addition & 28 deletions
29
app/src/main/java/org/jellyfin/mobile/utils/extensions/Activity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/jellyfin/mobile/utils/extensions/Window.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.jellyfin.mobile.utils.extensions | ||
|
||
import android.view.Window | ||
import android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | ||
|
||
inline var Window.keepScreenOn: Boolean | ||
get() = attributes.flags.hasFlag(FLAG_KEEP_SCREEN_ON) | ||
set(value) = if (value) addFlags(FLAG_KEEP_SCREEN_ON) else clearFlags(FLAG_KEEP_SCREEN_ON) |