From 46ce5785c95eea2c8ca13751b682f346d0b899b8 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Tue, 14 Jun 2016 11:34:11 -0400 Subject: [PATCH] Add backup in setting --- Kiwix-iOS/AppDelegate.swift | 1 - Kiwix-iOS/Controller/LibraryBackupTBVC.swift | 54 ++++++++++ Kiwix-iOS/Controller/SettingTBVC.swift | 84 ++++++++++++++- Kiwix-iOS/Controller/SettingTBVCD.swift | 107 ------------------- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Setting.storyboard | 29 +++++ Kiwix.xcodeproj/project.pbxproj | 8 +- 7 files changed, 171 insertions(+), 114 deletions(-) create mode 100644 Kiwix-iOS/Controller/LibraryBackupTBVC.swift delete mode 100644 Kiwix-iOS/Controller/SettingTBVCD.swift diff --git a/Kiwix-iOS/AppDelegate.swift b/Kiwix-iOS/AppDelegate.swift index 6757bc91..e3da4a47 100644 --- a/Kiwix-iOS/AppDelegate.swift +++ b/Kiwix-iOS/AppDelegate.swift @@ -57,7 +57,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(AppDelegate.recordActiveSession), userInfo: nil, repeats: false) ZIMMultiReader.sharedInstance.rescan() - FileManager.setSkipBackupAttribute(true, url: FileManager.docDirURL) } func applicationWillTerminate(application: UIApplication) { diff --git a/Kiwix-iOS/Controller/LibraryBackupTBVC.swift b/Kiwix-iOS/Controller/LibraryBackupTBVC.swift new file mode 100644 index 00000000..29759e03 --- /dev/null +++ b/Kiwix-iOS/Controller/LibraryBackupTBVC.swift @@ -0,0 +1,54 @@ +// +// LibraryBackupTBVC.swift +// Kiwix +// +// Created by Chris Li on 6/14/16. +// Copyright © 2016 Chris. All rights reserved. +// + +import UIKit + +class LibraryBackupTBVC: UITableViewController { + + let toggle = UISwitch() + + override func viewDidLoad() { + super.viewDidLoad() + title = NSLocalizedString("Backup", comment: "Setting: Backup local files title") + toggle.addTarget(self, action: #selector(LibraryBackupTBVC.switcherValueChanged(_:)), forControlEvents: .ValueChanged) + toggle.on = !(FileManager.getSkipBackupAttribute(item: FileManager.docDirURL) ?? false) + } + + // MARK: - Table view data source + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + return 1 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 1 + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) + + cell.textLabel?.text = LocalizedStrings.libraryBackup + cell.accessoryView = toggle + + return cell + } + + override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + return NSLocalizedString("When turned off, iOS will not backup zim files and index folders to iCloud or iTunes.", + comment: "Setting: Backup local files comment") + "\n\n" + + NSLocalizedString("Note: Large zim file collection can take up a lot of space in backup. You may want to turn this off if you use iCloud for backup.", comment: "Setting: Backup local files comment") + } + + // MARK: - Actions + + func switcherValueChanged(switcher: UISwitch) { + guard switcher == toggle else {return} + FileManager.setSkipBackupAttribute(!switcher.on, url: FileManager.docDirURL) + } + +} diff --git a/Kiwix-iOS/Controller/SettingTBVC.swift b/Kiwix-iOS/Controller/SettingTBVC.swift index 1300d6b0..a5b59ac5 100644 --- a/Kiwix-iOS/Controller/SettingTBVC.swift +++ b/Kiwix-iOS/Controller/SettingTBVC.swift @@ -11,7 +11,7 @@ import UIKit class SettingTBVC: UITableViewController { let sectionHeader = [LocalizedStrings.library, LocalizedStrings.reading, LocalizedStrings.misc] - let cellTextlabels = [[LocalizedStrings.libraryAutoRefresh, LocalizedStrings.libraryUseCellularData], + let cellTextlabels = [[LocalizedStrings.libraryAutoRefresh, LocalizedStrings.libraryUseCellularData, LocalizedStrings.libraryBackup], [LocalizedStrings.fontSize, LocalizedStrings.adjustLayout], [LocalizedStrings.rateKiwix, LocalizedStrings.about]] @@ -33,6 +33,87 @@ class SettingTBVC: UITableViewController { tableView.reloadData() } + // MARK: - Table view data source + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + return sectionHeader.count + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return cellTextlabels[section].count + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) + + cell.textLabel?.text = cellTextlabels[indexPath.section][indexPath.row] + cell.detailTextLabel?.text = { + switch indexPath { + case NSIndexPath(forRow: 0, inSection: 0): + return Preference.libraryAutoRefreshDisabled ? LocalizedStrings.disabled : + dateComponentsFormatter.stringFromTimeInterval(Preference.libraryRefreshInterval) + case NSIndexPath(forRow: 1, inSection: 0): + return Preference.libraryRefreshAllowCellularData ? LocalizedStrings.on : LocalizedStrings.off + case NSIndexPath(forRow: 2, inSection: 0): + guard let skipBackup = FileManager.getSkipBackupAttribute(item: FileManager.docDirURL) else {return ""} + return skipBackup ? LocalizedStrings.off: LocalizedStrings.on + case NSIndexPath(forRow: 0, inSection: 1): + return String.formattedPercentString(Preference.webViewZoomScale / 100) + case NSIndexPath(forRow: 1, inSection: 1): + return Preference.webViewInjectJavascriptToAdjustPageLayout ? LocalizedStrings.on : LocalizedStrings.off + default: + return nil + } + }() + + return cell + } + + // MARK: - Table View Delegate + + override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + return sectionHeader[section] + } + + override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + if section == tableView.numberOfSections - 1 { + return String(format: LocalizedStrings.versionString, NSBundle.shortVersionString) + } else { + return nil + } + } + + override func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + guard section == tableView.numberOfSections - 1 else {return} + if let view = view as? UITableViewHeaderFooterView { + view.textLabel?.textAlignment = .Center + } + } + + override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + defer {tableView.deselectRowAtIndexPath(indexPath, animated: true)} + let cell = tableView.cellForRowAtIndexPath(indexPath) + guard let text = cell?.textLabel?.text else {return} + switch text { + case LocalizedStrings.libraryAutoRefresh: + performSegueWithIdentifier("LibraryAutoRefresh", sender: self) + case LocalizedStrings.libraryUseCellularData: + performSegueWithIdentifier("LibraryUseCellularData", sender: self) + case LocalizedStrings.libraryBackup: + performSegueWithIdentifier("LibraryBackup", sender: self) + case LocalizedStrings.fontSize: + performSegueWithIdentifier("ReadingFontSize", sender: self) + case LocalizedStrings.adjustLayout: + performSegueWithIdentifier("AdjustLayout", sender: self) + case LocalizedStrings.rateKiwix: + showRateKiwixAlert(showRemindLater: false) + case LocalizedStrings.about: + performSegueWithIdentifier("MiscAbout", sender: self) + default: + break + } + } + // MARK: - Rate Kiwix func showRateKiwixIfNeeded() { @@ -97,6 +178,7 @@ extension LocalizedStrings { //MARK: - Table Cell Text class var libraryAutoRefresh: String {return NSLocalizedString("Auto Refresh", comment: "Setting: Library Auto Refresh")} class var libraryUseCellularData: String {return NSLocalizedString("Refresh Using Cellular Data", comment: "Setting: Library Use Cellular Data")} + class var libraryBackup: String {return NSLocalizedString("Backup Local Files", comment: "Setting: Backup Local Files")} class var fontSize: String {return NSLocalizedString("Font Size", comment: "Setting: Font Size")} class var adjustLayout: String {return NSLocalizedString("Adjust Layout", comment: "Setting: Adjust Layout")} class var booksToInclude: String {return NSLocalizedString("Books To Include", comment: "Setting: Books To Include")} diff --git a/Kiwix-iOS/Controller/SettingTBVCD.swift b/Kiwix-iOS/Controller/SettingTBVCD.swift deleted file mode 100644 index 7772fe92..00000000 --- a/Kiwix-iOS/Controller/SettingTBVCD.swift +++ /dev/null @@ -1,107 +0,0 @@ -// -// SettingTBVCD.swift -// Kiwix -// -// Created by Chris on 1/3/16. -// Copyright © 2016 Chris. All rights reserved. -// - -import UIKit - -extension SettingTBVC { - // MARK: - Table view data source - - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { - return sectionHeader.count - } - - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return cellTextlabels[section].count - } - - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) - - cell.textLabel?.text = cellTextlabels[indexPath.section][indexPath.row] - cell.detailTextLabel?.text = { - switch indexPath { - case NSIndexPath(forRow: 0, inSection: 0): - if Preference.libraryAutoRefreshDisabled { - return LocalizedStrings.disabled - } else { - return dateComponentsFormatter.stringFromTimeInterval(Preference.libraryRefreshInterval) - } - case NSIndexPath(forRow: 1, inSection: 0): - return Preference.libraryRefreshAllowCellularData ? LocalizedStrings.on : LocalizedStrings.off - case NSIndexPath(forRow: 0, inSection: 1): - return String.formattedPercentString(Preference.webViewZoomScale / 100) - case NSIndexPath(forRow: 1, inSection: 1): - return Preference.webViewInjectJavascriptToAdjustPageLayout ? LocalizedStrings.on : LocalizedStrings.off - default: - return nil - } - }() - - return cell - } - - // MARK: - Table View Delegate - - override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - return sectionHeader[section] - } - - override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { - if section == tableView.numberOfSections - 1 { - return String(format: LocalizedStrings.versionString, NSBundle.shortVersionString) - } else { - return nil - } - } - - override func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { - guard section == tableView.numberOfSections - 1 else {return} - if let view = view as? UITableViewHeaderFooterView { - view.textLabel?.textAlignment = .Center - } - } - - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { - defer {tableView.deselectRowAtIndexPath(indexPath, animated: true)} - let cell = tableView.cellForRowAtIndexPath(indexPath) - guard let text = cell?.textLabel?.text else {return} - switch text { - case LocalizedStrings.libraryAutoRefresh: - performSegueWithIdentifier("LibraryAutoRefresh", sender: self) - case LocalizedStrings.libraryUseCellularData: - performSegueWithIdentifier("LibraryUseCellularData", sender: self) - case LocalizedStrings.fontSize: - performSegueWithIdentifier("ReadingFontSize", sender: self) - case LocalizedStrings.adjustLayout: - performSegueWithIdentifier("AdjustLayout", sender: self) - case LocalizedStrings.rateKiwix: - showRateKiwixAlert(showRemindLater: false) - case LocalizedStrings.about: - performSegueWithIdentifier("MiscAbout", sender: self) - - // case LocalizedStrings.homePage:[ ] - // self.performSegueWithIdentifier("HomePage", sender: self) - // case LocalizedStrings.readingOptimization: - // self.performSegueWithIdentifier("ReadingOptimization", sender: self) - // case LocalizedStrings.booksToInclude: - // self.performSegueWithIdentifier("SearchRange", sender: self) - // case LocalizedStrings.rateKiwix: - // self.goRateInAppStore() - // case LocalizedStrings.emailFeedback: - // self.sendEmailFeedback() - // case LocalizedStrings.about: - // self.performSegueWithIdentifier("About", sender: self) - // case "Toggle feedback alert": - // self.showRateUsPrompt() - // case "File Browser": - // self.showFileManager() - default: - break - } - } -} \ No newline at end of file diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 727ba187..529a2970 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 59 + 78 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Setting.storyboard b/Kiwix-iOS/Storyboard/Setting.storyboard index 9af01164..57f48940 100644 --- a/Kiwix-iOS/Storyboard/Setting.storyboard +++ b/Kiwix-iOS/Storyboard/Setting.storyboard @@ -73,6 +73,7 @@ + @@ -153,6 +154,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index 471b6e4f..104bd3e8 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -82,7 +82,6 @@ 971A103F1D022C42007FC62C /* LibraryAutoRefreshTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A103D1D022C42007FC62C /* LibraryAutoRefreshTBVC.swift */; }; 971A10401D022C42007FC62C /* LibraryUseCellularDataTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A103E1D022C42007FC62C /* LibraryUseCellularDataTBVC.swift */; }; 971A10431D022C54007FC62C /* SettingTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10411D022C54007FC62C /* SettingTBVC.swift */; }; - 971A10441D022C54007FC62C /* SettingTBVCD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10421D022C54007FC62C /* SettingTBVCD.swift */; }; 971A10461D022CB2007FC62C /* SearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10451D022CB2007FC62C /* SearchVC.swift */; }; 971A104A1D022CBE007FC62C /* SearchResultTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10471D022CBE007FC62C /* SearchResultTBVC.swift */; }; 971A104B1D022CBE007FC62C /* SearchScopeSelectTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10481D022CBE007FC62C /* SearchScopeSelectTBVC.swift */; }; @@ -271,6 +270,7 @@ 97E609F71D103DED00EBCB9D /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97E609F51D103DED00EBCB9D /* MainInterface.storyboard */; }; 97E609FB1D103DED00EBCB9D /* Kiwix-iOSWidget.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 97E609EF1D103DED00EBCB9D /* Kiwix-iOSWidget.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 97E60A021D10423A00EBCB9D /* ShadowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E60A011D10423A00EBCB9D /* ShadowView.swift */; }; + 97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E60A051D10504000EBCB9D /* LibraryBackupTBVC.swift */; }; 97E891691CA976E90001CA32 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E891681CA976E90001CA32 /* FileManager.swift */; }; AEFF409D8D5B53BC90700424 /* Pods_Kiwix_OSX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DBAF14EE0505901A1570F23F /* Pods_Kiwix_OSX.framework */; }; BECDBCEF4720E3E86FE63989 /* Pods_Kiwix_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CEA715EBFC96C75E73447A7 /* Pods_Kiwix_iOS.framework */; }; @@ -400,7 +400,6 @@ 971A103D1D022C42007FC62C /* LibraryAutoRefreshTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LibraryAutoRefreshTBVC.swift; path = "Kiwix-iOS/Controller/LibraryAutoRefreshTBVC.swift"; sourceTree = SOURCE_ROOT; }; 971A103E1D022C42007FC62C /* LibraryUseCellularDataTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LibraryUseCellularDataTBVC.swift; path = "Kiwix-iOS/Controller/LibraryUseCellularDataTBVC.swift"; sourceTree = SOURCE_ROOT; }; 971A10411D022C54007FC62C /* SettingTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingTBVC.swift; path = "Kiwix-iOS/Controller/SettingTBVC.swift"; sourceTree = SOURCE_ROOT; }; - 971A10421D022C54007FC62C /* SettingTBVCD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingTBVCD.swift; path = "Kiwix-iOS/Controller/SettingTBVCD.swift"; sourceTree = SOURCE_ROOT; }; 971A10451D022CB2007FC62C /* SearchVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchVC.swift; path = "Kiwix-iOS/Controller/SearchVC.swift"; sourceTree = SOURCE_ROOT; }; 971A10471D022CBE007FC62C /* SearchResultTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchResultTBVC.swift; path = "Kiwix-iOS/Controller/SearchResultTBVC.swift"; sourceTree = SOURCE_ROOT; }; 971A10481D022CBE007FC62C /* SearchScopeSelectTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchScopeSelectTBVC.swift; path = "Kiwix-iOS/Controller/SearchScopeSelectTBVC.swift"; sourceTree = SOURCE_ROOT; }; @@ -549,6 +548,7 @@ 97E609F61D103DED00EBCB9D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; 97E609F81D103DED00EBCB9D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 97E60A011D10423A00EBCB9D /* ShadowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowView.swift; sourceTree = ""; }; + 97E60A051D10504000EBCB9D /* LibraryBackupTBVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LibraryBackupTBVC.swift; path = "Kiwix-iOS/Controller/LibraryBackupTBVC.swift"; sourceTree = SOURCE_ROOT; }; 97E891681CA976E90001CA32 /* FileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FileManager.swift; path = Kiwix/FileManager.swift; sourceTree = ""; }; B14E5F8A97964014F99EAD4E /* Pods-Kiwix-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kiwix-iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Kiwix-iOS/Pods-Kiwix-iOS.debug.xcconfig"; sourceTree = ""; }; B3B41D59F4B010C559B18D3D /* Pods-Kiwix-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kiwix-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Kiwix-iOS/Pods-Kiwix-iOS.release.xcconfig"; sourceTree = ""; }; @@ -989,7 +989,6 @@ isa = PBXGroup; children = ( 971A10411D022C54007FC62C /* SettingTBVC.swift */, - 971A10421D022C54007FC62C /* SettingTBVCD.swift */, 97C01FCA1C39B7F100D010E5 /* Library */, 97C01FD21C39BF4E00D010E5 /* Reading */, 971A10351D022B02007FC62C /* AboutVC.swift */, @@ -1239,6 +1238,7 @@ children = ( 971A103D1D022C42007FC62C /* LibraryAutoRefreshTBVC.swift */, 971A103E1D022C42007FC62C /* LibraryUseCellularDataTBVC.swift */, + 97E60A051D10504000EBCB9D /* LibraryBackupTBVC.swift */, ); name = Library; sourceTree = ""; @@ -1845,7 +1845,6 @@ 971A105A1D022DAD007FC62C /* LibraryLocalTBVC.swift in Sources */, 97E60A021D10423A00EBCB9D /* ShadowView.swift in Sources */, 979CB6BD1D05C520005E1BA1 /* Operation.swift in Sources */, - 971A10441D022C54007FC62C /* SettingTBVCD.swift in Sources */, 971A10671D022E0A007FC62C /* MainVCOtherD.swift in Sources */, 978C58981C1CD86E0077AE47 /* Book.swift in Sources */, 978C58961C1CD86E0077AE47 /* Language.swift in Sources */, @@ -1867,6 +1866,7 @@ 979CB6771D05C44F005E1BA1 /* MutuallyExclusive.swift in Sources */, 970C3DCA1CBD79450026A240 /* MigrationPolicy.swift in Sources */, 97E891691CA976E90001CA32 /* FileManager.swift in Sources */, + 97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */, 974570F41C2DABB500680E43 /* ZIMMultiReaderAPI.swift in Sources */, 979CB6511D05C44F005E1BA1 /* PassbookCapability.swift in Sources */, 971A104C1D022CBE007FC62C /* SearchTabController.swift in Sources */,