mirror of
https://github.com/yattee/yattee.git
synced 2024-12-12 21:30:32 +05:30
orientation fullscreen code cleanup
Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
parent
b0264aaabe
commit
2185718d50
@ -137,6 +137,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen
|
@Default(.rotateToLandscapeOnEnterFullScreen) private var rotateToLandscapeOnEnterFullScreen
|
||||||
|
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@Published var currentChapterIndex: Int?
|
@Published var currentChapterIndex: Int?
|
||||||
@ -209,7 +210,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
isOrientationLocked = Defaults[.isOrientationLocked]
|
isOrientationLocked = Defaults[.isOrientationLocked]
|
||||||
|
|
||||||
if isOrientationLocked, Defaults[.lockPortraitWhenBrowsing] {
|
if isOrientationLocked, lockPortraitWhenBrowsing {
|
||||||
lockedOrientation = UIInterfaceOrientationMask.portrait
|
lockedOrientation = UIInterfaceOrientationMask.portrait
|
||||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||||
} else if isOrientationLocked {
|
} else if isOrientationLocked {
|
||||||
@ -564,7 +565,7 @@ final class PlayerModel: ObservableObject {
|
|||||||
|
|
||||||
if !presentingPlayer {
|
if !presentingPlayer {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
if Defaults[.lockPortraitWhenBrowsing] {
|
if lockPortraitWhenBrowsing {
|
||||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||||
} else {
|
} else {
|
||||||
Orientation.lockOrientation(.allButUpsideDown)
|
Orientation.lockOrientation(.allButUpsideDown)
|
||||||
@ -1155,10 +1156,20 @@ final class PlayerModel: ObservableObject {
|
|||||||
let lockOrientation = rotateToLandscapeOnEnterFullScreen.interfaceOrientation
|
let lockOrientation = rotateToLandscapeOnEnterFullScreen.interfaceOrientation
|
||||||
if currentVideoIsLandscape {
|
if currentVideoIsLandscape {
|
||||||
if initiatedByButton {
|
if initiatedByButton {
|
||||||
Orientation.lockOrientation(self.isOrientationLocked ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) : .landscape)
|
Orientation.lockOrientation(isOrientationLocked
|
||||||
|
? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft)
|
||||||
|
: .landscape)
|
||||||
}
|
}
|
||||||
let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape ? OrientationTracker.shared.currentInterfaceOrientation : self.rotateToLandscapeOnEnterFullScreen.interfaceOrientation
|
let orientation = OrientationTracker.shared.currentDeviceOrientation.isLandscape
|
||||||
Orientation.lockOrientation(self.isOrientationLocked ? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft) : .landscape, andRotateTo: orientation)
|
? OrientationTracker.shared.currentInterfaceOrientation
|
||||||
|
: rotateToLandscapeOnEnterFullScreen.interfaceOrientation
|
||||||
|
|
||||||
|
Orientation.lockOrientation(
|
||||||
|
isOrientationLocked
|
||||||
|
? (lockOrientation == .landscapeRight ? .landscapeRight : .landscapeLeft)
|
||||||
|
: .landscape,
|
||||||
|
andRotateTo: orientation
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls {
|
if activeBackend == .appleAVPlayer, avPlayerUsesSystemControls {
|
||||||
@ -1169,8 +1180,8 @@ final class PlayerModel: ObservableObject {
|
|||||||
if Defaults[.lockPortraitWhenBrowsing] {
|
if Defaults[.lockPortraitWhenBrowsing] {
|
||||||
lockedOrientation = UIInterfaceOrientationMask.portrait
|
lockedOrientation = UIInterfaceOrientationMask.portrait
|
||||||
}
|
}
|
||||||
let rotationOrientation = Defaults[.lockPortraitWhenBrowsing] ? UIInterfaceOrientation.portrait : nil
|
let rotationOrientation = lockPortraitWhenBrowsing ? UIInterfaceOrientation.portrait : nil
|
||||||
Orientation.lockOrientation(Defaults[.lockPortraitWhenBrowsing] ? .portrait : .allButUpsideDown, andRotateTo: rotationOrientation)
|
Orientation.lockOrientation(lockPortraitWhenBrowsing ? .portrait : .allButUpsideDown, andRotateTo: rotationOrientation)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import CoreMotion
|
import CoreMotion
|
||||||
import Defaults
|
|
||||||
import Logging
|
import Logging
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ final class OrientationModel {
|
|||||||
var orientationDebouncer = Debouncer(.milliseconds(300))
|
var orientationDebouncer = Debouncer(.milliseconds(300))
|
||||||
var orientationObserver: Any?
|
var orientationObserver: Any?
|
||||||
|
|
||||||
|
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
||||||
|
@Default(.enterFullscreenInLandscape) private var enterFullscreenInLandscape
|
||||||
|
|
||||||
private var player = PlayerModel.shared
|
private var player = PlayerModel.shared
|
||||||
|
|
||||||
func startOrientationUpdates() {
|
func startOrientationUpdates() {
|
||||||
@ -25,7 +28,7 @@ final class OrientationModel {
|
|||||||
self.logger.info("Notification received: Device orientation changed.")
|
self.logger.info("Notification received: Device orientation changed.")
|
||||||
|
|
||||||
// We only allow .portrait and are not showing the player
|
// 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 {
|
else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -42,7 +45,7 @@ final class OrientationModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only take action if the player is active and presenting
|
// 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 {
|
else {
|
||||||
self.logger.info("Only updating orientation without actions.")
|
self.logger.info("Only updating orientation without actions.")
|
||||||
return
|
return
|
||||||
@ -52,7 +55,7 @@ final class OrientationModel {
|
|||||||
self.orientationDebouncer.callback = {
|
self.orientationDebouncer.callback = {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if orientation.isLandscape {
|
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.logger.info("Entering fullscreen because orientation is landscape.")
|
||||||
self.player.controls.presentingControls = false
|
self.player.controls.presentingControls = false
|
||||||
self.player.enterFullScreen(showControls: false)
|
self.player.enterFullScreen(showControls: false)
|
||||||
@ -63,7 +66,7 @@ final class OrientationModel {
|
|||||||
if self.player.playingFullScreen {
|
if self.player.playingFullScreen {
|
||||||
self.player.exitFullScreen(showControls: false)
|
self.player.exitFullScreen(showControls: false)
|
||||||
}
|
}
|
||||||
if Defaults[.lockPortraitWhenBrowsing] {
|
if self.lockPortraitWhenBrowsing {
|
||||||
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
Orientation.lockOrientation(.portrait, andRotateTo: .portrait)
|
||||||
} else {
|
} else {
|
||||||
Orientation.lockOrientation(OrientationTracker.shared.currentInterfaceOrientationMask, andRotateTo: orientation)
|
Orientation.lockOrientation(OrientationTracker.shared.currentInterfaceOrientationMask, andRotateTo: orientation)
|
||||||
|
Loading…
Reference in New Issue
Block a user