Skip to content

Commit

Permalink
Add icloud backups setting
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniCarlo committed Nov 19, 2021
1 parent 1fdcf54 commit 044e19b
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 61 deletions.
2 changes: 2 additions & 0 deletions BookPlayer/Base.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"book_time_current_title" = "Current Book Time: %@";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
16 changes: 11 additions & 5 deletions BookPlayer/Loading/LoadingViewModel.swift
Expand Up @@ -136,12 +136,18 @@ class LoadingViewModel: BaseViewModel<LoadingCoordinator> {
userDefaults?.set(true, forKey: Constants.UserDefaults.fileProtectionMigration.rawValue)
}

// Exclude Processed folder from phone backups
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = true
var processedFolderURL = DataManager.getProcessedFolderURL()
// Default to include Processed folder in phone backups,
// when migrating between phones, having the folder excluded have generated issues for users,
// this can be set to false from within the app settings
if UserDefaults.standard.object(forKey: Constants.UserDefaults.iCloudBackupsEnabled.rawValue) == nil {
UserDefaults.standard.set(true, forKey: Constants.UserDefaults.iCloudBackupsEnabled.rawValue)

try? processedFolderURL.setResourceValues(resourceValues)
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = false
var processedFolderURL = DataManager.getProcessedFolderURL()

try? processedFolderURL.setResourceValues(resourceValues)
}

// Set system theme as default
if UserDefaults.standard.object(forKey: Constants.UserDefaults.systemThemeVariantEnabled.rawValue) == nil {
Expand Down
74 changes: 57 additions & 17 deletions BookPlayer/Settings/Base.lproj/Settings.storyboard

Large diffs are not rendered by default.

89 changes: 51 additions & 38 deletions BookPlayer/Settings/SettingsViewController.swift
Expand Up @@ -22,26 +22,27 @@ class SettingsViewController: BaseTableViewController<SettingsCoordinator, Setti
MFMailComposeViewControllerDelegate,
TelemetryProtocol,
Storyboarded {
@IBOutlet weak var autoplayLibrarySwitch: UISwitch!
@IBOutlet weak var disableAutolockSwitch: UISwitch!
@IBOutlet weak var autolockDisabledOnlyWhenPoweredSwitch: UISwitch!
@IBOutlet weak var autolockDisabledOnlyWhenPoweredLabel: UILabel!
@IBOutlet weak var themeLabel: UILabel!
@IBOutlet weak var appIconLabel: UILabel!
@IBOutlet weak var autoplayLibrarySwitch: UISwitch!
@IBOutlet weak var disableAutolockSwitch: UISwitch!
@IBOutlet weak var autolockDisabledOnlyWhenPoweredSwitch: UISwitch!
@IBOutlet weak var iCloudBackupsSwitch: UISwitch!
@IBOutlet weak var autolockDisabledOnlyWhenPoweredLabel: UILabel!
@IBOutlet weak var themeLabel: UILabel!
@IBOutlet weak var appIconLabel: UILabel!

var iconObserver: NSKeyValueObservation!

enum SettingsSection: Int {
case plus = 0, theme, playback, storage, autoplay, autolock, siri, support, credits
case plus = 0, theme, playback, storage, autoplay, autolock, siri, backups, support, credits
}

let storageIndexPath = IndexPath(row: 0, section: 3)
let lastPlayedShortcutPath = IndexPath(row: 0, section: 6)
let sleepTimerShortcutPath = IndexPath(row: 1, section: 6)

let supportSection: Int = 7
let githubLinkPath = IndexPath(row: 0, section: 7)
let supportEmailPath = IndexPath(row: 1, section: 7)
let supportSection: Int = 8
let githubLinkPath = IndexPath(row: 0, section: 8)
let supportEmailPath = IndexPath(row: 1, section: 8)

var version: String = "0.0.0"
var build: String = "0"
Expand Down Expand Up @@ -75,16 +76,7 @@ class SettingsViewController: BaseTableViewController<SettingsCoordinator, Setti
NotificationCenter.default.addObserver(self, selector: #selector(self.donationMade), name: .donationMade, object: nil)
}

self.autoplayLibrarySwitch.addTarget(self, action: #selector(self.autoplayToggleDidChange), for: .valueChanged)
self.disableAutolockSwitch.addTarget(self, action: #selector(self.disableAutolockDidChange), for: .valueChanged)
self.autolockDisabledOnlyWhenPoweredSwitch.addTarget(self, action: #selector(self.autolockOnlyWhenPoweredDidChange), for: .valueChanged)

// Set initial switch positions
self.autoplayLibrarySwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.autoplayEnabled.rawValue), animated: false)
self.disableAutolockSwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabled.rawValue), animated: false)
self.autolockDisabledOnlyWhenPoweredSwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabledOnlyWhenPowered.rawValue), animated: false)
self.autolockDisabledOnlyWhenPoweredSwitch.isEnabled = UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabled.rawValue)
self.autolockDisabledOnlyWhenPoweredLabel.isEnabled = UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabled.rawValue)
self.setupSwitchValues()

guard
let version = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String,
Expand All @@ -97,6 +89,21 @@ class SettingsViewController: BaseTableViewController<SettingsCoordinator, Setti
self.build = build
}

func setupSwitchValues() {
self.autoplayLibrarySwitch.addTarget(self, action: #selector(self.autoplayToggleDidChange), for: .valueChanged)
self.disableAutolockSwitch.addTarget(self, action: #selector(self.disableAutolockDidChange), for: .valueChanged)
self.autolockDisabledOnlyWhenPoweredSwitch.addTarget(self, action: #selector(self.autolockOnlyWhenPoweredDidChange), for: .valueChanged)
self.iCloudBackupsSwitch.addTarget(self, action: #selector(self.iCloudBackupsDidChange), for: .valueChanged)

// Set initial switch positions
self.iCloudBackupsSwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.iCloudBackupsEnabled.rawValue), animated: false)
self.autoplayLibrarySwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.autoplayEnabled.rawValue), animated: false)
self.disableAutolockSwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabled.rawValue), animated: false)
self.autolockDisabledOnlyWhenPoweredSwitch.setOn(UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabledOnlyWhenPowered.rawValue), animated: false)
self.autolockDisabledOnlyWhenPoweredSwitch.isEnabled = UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabled.rawValue)
self.autolockDisabledOnlyWhenPoweredLabel.isEnabled = UserDefaults.standard.bool(forKey: Constants.UserDefaults.autolockDisabled.rawValue)
}

@objc func donationMade() {
self.tableView.reloadData()
}
Expand All @@ -118,6 +125,10 @@ class SettingsViewController: BaseTableViewController<SettingsCoordinator, Setti
self.sendSignal(.disableAutolockOnPowerAction, with: ["isOn": "\(self.autolockDisabledOnlyWhenPoweredSwitch.isOn)"])
}

@objc func iCloudBackupsDidChange() {
self.viewModel.toggleFileBackupsPreference(self.iCloudBackupsSwitch.isOn)
}

@IBAction func done(_ sender: UIBarButtonItem) {
self.viewModel.coordinator.didFinish()
}
Expand Down Expand Up @@ -166,26 +177,28 @@ class SettingsViewController: BaseTableViewController<SettingsCoordinator, Setti
}
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let settingsSection = SettingsSection(rawValue: section) else {
return super.tableView(tableView, titleForFooterInSection: section)
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let settingsSection = SettingsSection(rawValue: section) else {
return super.tableView(tableView, titleForFooterInSection: section)
}

switch settingsSection {
case .theme:
return "settings_appearance_title".localized
case .playback:
return "settings_playback_title".localized
case .storage:
return "settings_storage_title".localized
case .siri:
return "settings_siri_title".localized
case .support:
return "settings_support_title".localized
default:
return super.tableView(tableView, titleForHeaderInSection: section)
}
switch settingsSection {
case .theme:
return "settings_appearance_title".localized
case .playback:
return "settings_playback_title".localized
case .storage:
return "settings_storage_title".localized
case .siri:
return "settings_siri_title".localized
case .backups:
return "settings_backup_title".localized
case .support:
return "settings_support_title".localized
default:
return super.tableView(tableView, titleForHeaderInSection: section)
}
}

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
guard let settingsSection = SettingsSection(rawValue: section) else {
Expand Down
14 changes: 13 additions & 1 deletion BookPlayer/Settings/SettingsViewModel.swift
Expand Up @@ -6,6 +6,18 @@
// Copyright © 2021 Tortuga Power. All rights reserved.
//

import BookPlayerKit
import Foundation

class SettingsViewModel: BaseViewModel<SettingsCoordinator> { }
class SettingsViewModel: BaseViewModel<SettingsCoordinator> {
func toggleFileBackupsPreference(_ flag: Bool) {
UserDefaults.standard.set(flag, forKey: Constants.UserDefaults.iCloudBackupsEnabled.rawValue)

// Modify the processed folder to be considered for backups
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = !flag
var processedFolderURL = DataManager.getProcessedFolderURL()

try? processedFolderURL.setResourceValues(resourceValues)
}
}
2 changes: 2 additions & 0 deletions BookPlayer/cs.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/da.lproj/Localizable.strings
Expand Up @@ -227,3 +227,5 @@ Carl&nbsp;regarding the key settings_credits_title it's basically a section that
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/de.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/en.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"book_time_current_title" = "Current Book Time: %@";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/es.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"book_time_current_title" = "Tiempo actual del libro: %@";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/fr.lproj/Localizable.strings
Expand Up @@ -237,3 +237,5 @@ Carl&nbsp;regarding the key settings_credits_title it's basically a section that
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/hu.lproj/Localizable.strings
Expand Up @@ -257,3 +257,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"book_time_current_title" = "Current Book Time: %@";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/it.lproj/Localizable.strings
Expand Up @@ -249,3 +249,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/pl.lproj/Localizable.strings
Expand Up @@ -257,3 +257,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"book_time_current_title" = "Current Book Time: %@";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/pt-BR.lproj/Localizable.strings
Expand Up @@ -257,3 +257,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/ro.lproj/Localizable.strings
Expand Up @@ -236,3 +236,5 @@ Carl&nbsp;regarding the key settings_credits_title it's basically a section that
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/ru.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/sk-SK.lproj/Localizable.strings
Expand Up @@ -248,3 +248,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"book_time_current_title" = "Aktuálny čas audioknihy: %@";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/sv.lproj/Localizable.strings
Expand Up @@ -221,3 +221,5 @@
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/tr.lproj/Localizable.strings
Expand Up @@ -249,3 +249,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/uk.lproj/Localizable.strings
Expand Up @@ -249,3 +249,5 @@ Alessio Franceschi&nbsp;this is the label for the active sleep timer button when
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
2 changes: 2 additions & 0 deletions BookPlayer/zh-Hans.lproj/Localizable.strings
Expand Up @@ -218,3 +218,5 @@
"voiceover_continue_playback_title" = "Continue Playback";
"storage_fix_files_description" = "The link between the files and the digital book items are missing, if the corresponding item cannot be found for each file, a new one will be created";
"storage_fix_all_title" = "Fix All";
"settings_backup_title" = "iCloud Backups";
"settings_backup_files_title" = "Include book files";
1 change: 1 addition & 0 deletions Shared/Constants.swift
Expand Up @@ -25,6 +25,7 @@ public enum Constants {
case boostVolumeEnabled = "userSettingsBoostVolume"
case globalSpeedEnabled = "userSettingsGlobalSpeed"
case autoplayEnabled = "userSettingsAutoplay"
case iCloudBackupsEnabled = "userSettingsiCloudBackupsEnabled"
case autolockDisabled = "userSettingsDisableAutolock"
case autolockDisabledOnlyWhenPowered = "userSettingsAutolockOnlyWhenPowered"

Expand Down

0 comments on commit 044e19b

Please sign in to comment.