Add backup in setting

This commit is contained in:
Chris Li 2016-06-14 11:34:11 -04:00
parent ebf3873c7d
commit 46ce5785c9
7 changed files with 171 additions and 114 deletions

View File

@ -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) {

View File

@ -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)
}
}

View File

@ -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")}

View File

@ -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
}
}
}

View File

@ -36,7 +36,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>59</string>
<string>78</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View File

@ -73,6 +73,7 @@
<segue destination="PfB-ub-Ykr" kind="show" identifier="ReadingFontSize" id="1VW-Tc-AMT"/>
<segue destination="Ua4-kV-xc7" kind="show" identifier="MiscAbout" id="05I-Ac-hUg"/>
<segue destination="wed-Gd-0Tc" kind="show" identifier="AdjustLayout" id="gfS-dL-oh5"/>
<segue destination="cXQ-cR-uO9" kind="show" identifier="LibraryBackup" id="wMK-ai-X9p"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="h5i-dV-ulp" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -153,6 +154,34 @@
</objects>
<point key="canvasLocation" x="1747" y="309"/>
</scene>
<!--Library BackupTBVC-->
<scene sceneID="6AL-0N-M52">
<objects>
<tableViewController id="cXQ-cR-uO9" customClass="LibraryBackupTBVC" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="IAD-HF-Xla">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="DHw-r6-s29">
<rect key="frame" x="0.0" y="113.5" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="DHw-r6-s29" id="Trt-tT-e3y">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="cXQ-cR-uO9" id="mem-Ji-dbL"/>
<outlet property="delegate" destination="cXQ-cR-uO9" id="092-cl-RHY"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Nf5-hK-Dv0" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2420" y="309"/>
</scene>
<!--Font SizeTBVC-->
<scene sceneID="ppG-nb-eq1">
<objects>

View File

@ -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 = "<group>"; };
97E609F81D103DED00EBCB9D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
97E60A011D10423A00EBCB9D /* ShadowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowView.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
@ -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 = "<group>";
@ -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 */,