mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
orientation fullscreen code cleanup
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import CoreMotion
|
||||
import Defaults
|
||||
import Logging
|
||||
import UIKit
|
||||
|
||||
|
@@ -13,6 +13,9 @@ final class OrientationModel {
|
||||
var orientationDebouncer = Debouncer(.milliseconds(300))
|
||||
var orientationObserver: Any?
|
||||
|
||||
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
||||
@Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape
|
||||
|
||||
private var player = PlayerModel.shared
|
||||
|
||||
func startOrientationUpdates() {
|
||||
@@ -25,7 +28,7 @@ final class OrientationModel {
|
||||
self.logger.info("Notification received: Device orientation changed.")
|
||||
|
||||
// We only allow .portrait and are not showing the player
|
||||
guard (!self.player.presentingPlayer && !Defaults[.lockPortraitWhenBrowsing]) || self.player.presentingPlayer
|
||||
guard (!self.player.presentingPlayer && !self.lockPortraitWhenBrowsing) || self.player.presentingPlayer
|
||||
else {
|
||||
return
|
||||
}
|
||||
@@ -42,7 +45,7 @@ final class OrientationModel {
|
||||
}
|
||||
|
||||
// Only take action if the player is active and presenting
|
||||
guard (!self.player.isOrientationLocked && !self.player.playingInPictureInPicture) || (!Defaults[.lockPortraitWhenBrowsing] && !self.player.presentingPlayer) || (!Defaults[.lockPortraitWhenBrowsing] && self.player.presentingPlayer && !self.player.isOrientationLocked)
|
||||
guard (!self.player.isOrientationLocked && !self.player.playingInPictureInPicture) || (!self.lockPortraitWhenBrowsing && !self.player.presentingPlayer) || (!self.lockPortraitWhenBrowsing && self.player.presentingPlayer && !self.player.isOrientationLocked)
|
||||
else {
|
||||
self.logger.info("Only updating orientation without actions.")
|
||||
return
|
||||
@@ -52,7 +55,7 @@ final class OrientationModel {
|
||||
self.orientationDebouncer.callback = {
|
||||
DispatchQueue.main.async {
|
||||
if orientation.isLandscape {
|
||||
if Defaults[.enterFullscreenInLandscape], self.player.presentingPlayer {
|
||||
if self.enterFullscreenInLandscape, self.player.presentingPlayer {
|
||||
self.logger.info("Entering fullscreen because orientation is landscape.")
|
||||
self.player.controls.presentingControls = false
|
||||
self.player.enterFullScreen(showControls: false)
|
||||
@@ -63,7 +66,7 @@ final class OrientationModel {
|
||||
if self.player.playingFullScreen {
|
||||
self.player.exitFullScreen(showControls: false)
|
||||
}
|
||||
if Defaults[.lockPortraitWhenBrowsing] {
|
||||
if self.lockPortraitWhenBrowsing {
|
||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||
} else {
|
||||
Orientation.lockOrientation(OrientationTracker.shared.currentInterfaceOrientationMask, andRotateTo: orientation)
|
||||
|
Reference in New Issue
Block a user