Skip to content

Commit

Permalink
Merge pull request #1174 from TortugaPower/lock-orientation
Browse files Browse the repository at this point in the history
Add new lock orientation setting
  • Loading branch information
GianniCarlo authored Sep 10, 2024
2 parents f76dcad + 2f6b664 commit 05ce0d3
Show file tree
Hide file tree
Showing 29 changed files with 116 additions and 18 deletions.
10 changes: 10 additions & 0 deletions BookPlayer/AppTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class AppTabBarController: UITabBarController {

private var disposeBag = Set<AnyCancellable>()
private var themedStatusBarStyle: UIStatusBarStyle?
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UserDefaults.standard.object(forKey: Constants.UserDefaults.orientationLock) != nil,
let orientation = UIDeviceOrientation(rawValue: UserDefaults.standard.integer(forKey: Constants.UserDefaults.orientationLock)) {
return (orientation == .landscapeLeft || orientation == .landscapeRight)
? .landscape
: .portrait
} else {
return .all
}
}

public var isMiniPlayerVisible: Bool { !self.miniPlayer.isHidden }

Expand Down
1 change: 1 addition & 0 deletions BookPlayer/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@ We're working hard on providing a seamless experience, if possible, please conta
"Skip forward ${interval}" = "Skip forward ${interval}";
"intent_custom_skiprewind_title" = "Rewind with interval";
"Rewind ${interval}" = "Rewind ${interval}";
"settings_lock_orientation_title" = "Orientation Locked";
72 changes: 54 additions & 18 deletions BookPlayer/Settings/Base.lproj/Settings.storyboard

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions BookPlayer/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SettingsViewController: UITableViewController, MVVMControllerProtocol, MFM
@IBOutlet weak var iCloudBackupsSwitch: UISwitch!
@IBOutlet weak var crashReportsSwitch: UISwitch!
@IBOutlet weak var allowCellularDataSwitch: UISwitch!
@IBOutlet weak var lockOrientationSwitch: UISwitch!
@IBOutlet weak var skanSwitch: UISwitch!
@IBOutlet weak var themeLabel: UILabel!
@IBOutlet weak var appIconLabel: UILabel!
Expand Down Expand Up @@ -120,6 +121,7 @@ class SettingsViewController: UITableViewController, MVVMControllerProtocol, MFM
iCloudBackupsSwitch.addTarget(self, action: #selector(self.iCloudBackupsDidChange), for: .valueChanged)
crashReportsSwitch.addTarget(self, action: #selector(crashReportsAccessDidChange), for: .valueChanged)
skanSwitch.addTarget(self, action: #selector(skanPreferenceDidChange), for: .valueChanged)
lockOrientationSwitch.addTarget(self, action: #selector(orientationLockDidChange), for: .valueChanged)

// Set initial switch positions
allowCellularDataSwitch.setOn(
Expand All @@ -138,6 +140,10 @@ class SettingsViewController: UITableViewController, MVVMControllerProtocol, MFM
UserDefaults.standard.bool(forKey: Constants.UserDefaults.skanAttributionDisabled),
animated: false
)
lockOrientationSwitch.setOn(
UserDefaults.standard.object(forKey: Constants.UserDefaults.orientationLock) != nil,
animated: false
)
}

@objc func donationMade() {
Expand All @@ -160,6 +166,15 @@ class SettingsViewController: UITableViewController, MVVMControllerProtocol, MFM
viewModel.toggleSKANPreference(skanSwitch.isOn)
}

@objc func orientationLockDidChange() {
viewModel.toggleOrientationLockPreference(lockOrientationSwitch.isOn)
if #available(iOS 16.0, *) {
setNeedsUpdateOfSupportedInterfaceOrientations()
} else {
Self.attemptRotationToDeviceOrientation()
}
}

func bindDataItems() {
self.viewModel.observeEvents()
.receive(on: DispatchQueue.main)
Expand Down
12 changes: 12 additions & 0 deletions BookPlayer/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ class SettingsViewModel: ViewModelProtocol {
UserDefaults.standard.set(flag, forKey: Constants.UserDefaults.skanAttributionDisabled)
}

/// Handle registering the value in `UserDefaults`
func toggleOrientationLockPreference(_ flag: Bool) {
if flag {
UserDefaults.standard.set(
UIDevice.current.orientation.rawValue,
forKey: Constants.UserDefaults.orientationLock
)
} else {
UserDefaults.standard.removeObject(forKey: Constants.UserDefaults.orientationLock)
}
}

func showPro() {
onTransition?(.pro)
}
Expand Down
1 change: 1 addition & 0 deletions BookPlayer/ar.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "التخطي للأمام ${interval}";
"intent_custom_skiprewind_title" = "الترجيع مع الفاصل الزمني";
"Rewind ${interval}" = "ترجيع ${interval}";
"settings_lock_orientation_title" = "الاتجاه مغلق";
1 change: 1 addition & 0 deletions BookPlayer/cs.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Přeskočit vpřed ${interval}";
"intent_custom_skiprewind_title" = "Přetočit s intervalem";
"Rewind ${interval}" = "Přetočit ${interval}";
"settings_lock_orientation_title" = "Orientace uzamčena";
1 change: 1 addition & 0 deletions BookPlayer/da.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Spring frem ${interval}";
"intent_custom_skiprewind_title" = "Spol tilbage med interval";
"Rewind ${interval}" = "Spol ${interval} tilbage";
"settings_lock_orientation_title" = "Orientering låst";
1 change: 1 addition & 0 deletions BookPlayer/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Vorwärts springen ${interval}";
"intent_custom_skiprewind_title" = "Rücklauf mit Pause";
"Rewind ${interval}" = "Zurückspulen ${interval}";
"settings_lock_orientation_title" = "Ausrichtung gesperrt";
1 change: 1 addition & 0 deletions BookPlayer/el.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Μετάβαση προς τα εμπρός ${interval}";
"intent_custom_skiprewind_title" = "Πίσω με μεσοδιάστημα";
"Rewind ${interval}" = "Επαναφορά ${interval}";
"settings_lock_orientation_title" = "Ο προσανατολισμός είναι κλειδωμένος";
1 change: 1 addition & 0 deletions BookPlayer/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@ We're working hard on providing a seamless experience, if possible, please conta
"Skip forward ${interval}" = "Skip forward ${interval}";
"intent_custom_skiprewind_title" = "Rewind with interval";
"Rewind ${interval}" = "Rewind ${interval}";
"settings_lock_orientation_title" = "Orientation Locked";
1 change: 1 addition & 0 deletions BookPlayer/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Saltar hacia adelante ${interval}";
"intent_custom_skiprewind_title" = "Rebobinar con intervalo";
"Rewind ${interval}" = "Rebobinar ${interval}";
"settings_lock_orientation_title" = "Orientación Bloqueada";
1 change: 1 addition & 0 deletions BookPlayer/fi.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Siirry eteenpäin ${interval}";
"intent_custom_skiprewind_title" = "Kelaa taaksepäin intervalleilla";
"Rewind ${interval}" = "Kelaa taaksepäin ${interval}";
"settings_lock_orientation_title" = "Suunta lukittu";
1 change: 1 addition & 0 deletions BookPlayer/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Avancer ${interval}";
"intent_custom_skiprewind_title" = "Rembobiner avec intervalle";
"Rewind ${interval}" = "Rembobiner ${interval}";
"settings_lock_orientation_title" = "Orientation verrouillée";
1 change: 1 addition & 0 deletions BookPlayer/hu.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Ugrás előre ${interval}";
"intent_custom_skiprewind_title" = "Visszatekerés időközzel";
"Rewind ${interval}" = "Visszatekerés ${interval}";
"settings_lock_orientation_title" = "Tájolás zárolva";
1 change: 1 addition & 0 deletions BookPlayer/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Vai avanti ${interval}";
"intent_custom_skiprewind_title" = "Riavvolgi con intervallo";
"Rewind ${interval}" = "Riavvolgi ${interval}";
"settings_lock_orientation_title" = "Orientamento bloccato";
1 change: 1 addition & 0 deletions BookPlayer/nb.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@ Vi jobber hardt for å gi deg en sømløs opplevelse. Hvis mulig, kontakt oss p
"Skip forward ${interval}" = "Hopp fremover ${interval}";
"intent_custom_skiprewind_title" = "Spol tilbake med intervall";
"Rewind ${interval}" = "Spol tilbake ${interval}";
"settings_lock_orientation_title" = "Orientering låst";
1 change: 1 addition & 0 deletions BookPlayer/nl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Vooruit springen ${interval}";
"intent_custom_skiprewind_title" = "Terugspoelen met interval";
"Rewind ${interval}" = "Terugspoelen ${interval}";
"settings_lock_orientation_title" = "Oriëntatie vergrendeld";
1 change: 1 addition & 0 deletions BookPlayer/pl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Przejdź do przodu ${interval}";
"intent_custom_skiprewind_title" = "Przewijanie do tyłu z interwałem";
"Rewind ${interval}" = "Przewiń ${interval}";
"settings_lock_orientation_title" = "Zablokowana orientacja";
1 change: 1 addition & 0 deletions BookPlayer/pt-BR.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Avançar ${interval}";
"intent_custom_skiprewind_title" = "Retroceder com intervalo";
"Rewind ${interval}" = "Retroceder ${interval}";
"settings_lock_orientation_title" = "Orientação bloqueada";
1 change: 1 addition & 0 deletions BookPlayer/pt-PT.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Avançar ${interval}";
"intent_custom_skiprewind_title" = "Retroceder com intervalo";
"Rewind ${interval}" = "Retroceder ${interval}";
"settings_lock_orientation_title" = "Orientação bloqueada";
1 change: 1 addition & 0 deletions BookPlayer/ro.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Salt înainte ${interval}";
"intent_custom_skiprewind_title" = "Derulați înapoi cu interval";
"Rewind ${interval}" = "Derulați înapoi ${interval}";
"settings_lock_orientation_title" = "Orientare blocată";
1 change: 1 addition & 0 deletions BookPlayer/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Перейти вперед ${interval}";
"intent_custom_skiprewind_title" = "Перемотка назад с интервалом";
"Rewind ${interval}" = "Перемотка назад ${interval}";
"settings_lock_orientation_title" = "Ориентация заблокирована";
1 change: 1 addition & 0 deletions BookPlayer/sk-SK.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@ Usilovne pracujeme na poskytovaní bezproblémového zážitku, ak je to možné
"Skip forward ${interval}" = "Preskočiť dopredu ${interval}";
"intent_custom_skiprewind_title" = "Pretáčanie dozadu s intervalom";
"Rewind ${interval}" = "Pretočiť ${interval}";
"settings_lock_orientation_title" = "Orientácia uzamknutá";
1 change: 1 addition & 0 deletions BookPlayer/sv.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Hoppa framåt ${interval}";
"intent_custom_skiprewind_title" = "Spola tillbaka med intervall";
"Rewind ${interval}" = "Spola tillbaka ${interval}";
"settings_lock_orientation_title" = "Orientering låst";
1 change: 1 addition & 0 deletions BookPlayer/tr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "İleri atla ${interval}";
"intent_custom_skiprewind_title" = "Aralıklı geri sarma";
"Rewind ${interval}" = "${interval} geri sar";
"settings_lock_orientation_title" = "Yönlendirme Kilitli";
1 change: 1 addition & 0 deletions BookPlayer/uk.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "Перейти вперед ${interval}";
"intent_custom_skiprewind_title" = "Перемотування назад з інтервалом";
"Rewind ${interval}" = "Перемотати ${interval}";
"settings_lock_orientation_title" = "Орієнтація заблокована";
1 change: 1 addition & 0 deletions BookPlayer/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@
"Skip forward ${interval}" = "向前跳过${interval}";
"intent_custom_skiprewind_title" = "间隔倒带";
"Rewind ${interval}" = "后退 ${interval}";
"settings_lock_orientation_title" = "方向已锁定";
1 change: 1 addition & 0 deletions Shared/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum Constants {
public static let iCloudBackupsEnabled = "userSettingsiCloudBackupsEnabled"
public static let crashReportsDisabled = "userSettingsCrashReportsDisabled"
public static let skanAttributionDisabled = "userSettingsSKANAttributionDisabled"
public static let orientationLock = "userSettingsOrientationLock"
public static let autolockDisabled = "userSettingsDisableAutolock"
public static let autolockDisabledOnlyWhenPowered = "userSettingsAutolockOnlyWhenPowered"
public static let playerListPrefersBookmarks = "userSettingsPlayerListPrefersBookmarks"
Expand Down

0 comments on commit 05ce0d3

Please sign in to comment.