mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 05:49:25 -04:00
commit
This commit is contained in:
parent
82de6d0707
commit
f22415e3c9
@ -45,22 +45,22 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
|
|||||||
override func viewWillAppear(animated: Bool) {
|
override func viewWillAppear(animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
configureViews()
|
configureViews()
|
||||||
book?.addObserver(self, forKeyPath: "isLocal", options: .New, context: context)
|
// book?.addObserver(self, forKeyPath: "isLocal", options: .New, context: context)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear(animated: Bool) {
|
override func viewWillDisappear(animated: Bool) {
|
||||||
super.viewWillDisappear(animated)
|
super.viewWillDisappear(animated)
|
||||||
book?.removeObserver(self, forKeyPath: "isLocal", context: context)
|
// book?.removeObserver(self, forKeyPath: "isLocal", context: context)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
|
// override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
|
||||||
guard let book = object as? Book where context == self.context else {return}
|
// guard let book = object as? Book where context == self.context else {return}
|
||||||
NSOperationQueue.mainQueue().addOperationWithBlock {
|
// NSOperationQueue.mainQueue().addOperationWithBlock {
|
||||||
print(book.isLocal)
|
// print(book.isLocal)
|
||||||
self.configureActionSection(book)
|
// self.configureActionSection(book)
|
||||||
self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Fade)
|
// self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Fade)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// MARK: - Configure
|
// MARK: - Configure
|
||||||
|
|
||||||
@ -90,10 +90,10 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
|
|||||||
cellTitles.append([String]())
|
cellTitles.append([String]())
|
||||||
|
|
||||||
// Action Cells
|
// Action Cells
|
||||||
sectionHeaders.append(nil)
|
// sectionHeaders.append(nil)
|
||||||
sectionFooters.append(nil)
|
// sectionFooters.append(nil)
|
||||||
cellTitles.append([])
|
// cellTitles.append([])
|
||||||
configureActionSection(book)
|
// configureActionSection(book)
|
||||||
|
|
||||||
// Book Info
|
// Book Info
|
||||||
sectionHeaders.append(Strings.bookInfo)
|
sectionHeaders.append(Strings.bookInfo)
|
||||||
|
@ -39,17 +39,12 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel
|
|||||||
override func viewWillAppear(animated: Bool) {
|
override func viewWillAppear(animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
tabBarController?.navigationItem.rightBarButtonItem = UIBarButtonItem(imageNamed: "LanguageFilter", target: self, action: #selector(CloudBooksController.showLanguageFilter))
|
tabBarController?.navigationItem.rightBarButtonItem = UIBarButtonItem(imageNamed: "LanguageFilter", target: self, action: #selector(CloudBooksController.showLanguageFilter))
|
||||||
if fetchedResultController.delegate !== self {
|
|
||||||
fetchedResultController.delegate = self
|
|
||||||
tableView.reloadData()
|
|
||||||
}
|
|
||||||
refreshAutomatically()
|
refreshAutomatically()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear(animated: Bool) {
|
override func viewWillDisappear(animated: Bool) {
|
||||||
super.viewWillDisappear(animated)
|
super.viewWillDisappear(animated)
|
||||||
tabBarController?.navigationItem.rightBarButtonItem = nil
|
tabBarController?.navigationItem.rightBarButtonItem = nil
|
||||||
fetchedResultController.delegate = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
@ -262,6 +257,10 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel
|
|||||||
header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
|
header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||||
|
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -37,17 +37,12 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController
|
|||||||
override func viewWillAppear(animated: Bool) {
|
override func viewWillAppear(animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(DownloadTasksController.refreshProgress), userInfo: nil, repeats: true)
|
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(DownloadTasksController.refreshProgress), userInfo: nil, repeats: true)
|
||||||
if fetchedResultController.delegate !== self {
|
|
||||||
fetchedResultController.delegate = self
|
|
||||||
tableView.reloadData()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillDisappear(animated: Bool) {
|
override func viewWillDisappear(animated: Bool) {
|
||||||
super.viewWillDisappear(animated)
|
super.viewWillDisappear(animated)
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
timer = nil
|
timer = nil
|
||||||
fetchedResultController.delegate = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
@ -174,6 +169,10 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController
|
|||||||
// header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
|
// header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||||
|
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -200,19 +199,13 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController
|
|||||||
tableView.setEditing(false, animated: true)
|
tableView.setEditing(false, animated: true)
|
||||||
}
|
}
|
||||||
actions.insert(resume, atIndex: 0)
|
actions.insert(resume, atIndex: 0)
|
||||||
//
|
case .Error:
|
||||||
// if let book = downloadTask.book,
|
let retry = UITableViewRowAction(style: .Normal, title: "Restart") { (action, indexPath) in
|
||||||
// let resumeData = Preference.resumeData[book.id] {
|
let operation = ResumeBookDwonloadOperation(bookID: bookID)
|
||||||
//
|
GlobalQueue.shared.addOperation(operation)
|
||||||
// } else {
|
tableView.setEditing(false, animated: true)
|
||||||
// let restart = UITableViewRowAction(style: .Normal, title: "Restart") { (action, indexPath) in
|
}
|
||||||
// guard let bookID = downloadTask.book?.id,
|
actions.insert(retry, atIndex: 0)
|
||||||
// let operation = DownloadBookOperation(bookID: bookID) else {return}
|
|
||||||
// Network.shared.queue.addOperation(operation)
|
|
||||||
// tableView.setEditing(false, animated: true)
|
|
||||||
// }
|
|
||||||
// actions.insert(restart, atIndex: 0)
|
|
||||||
// }
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -294,7 +287,6 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController
|
|||||||
|
|
||||||
func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
func controllerDidChangeContent(controller: NSFetchedResultsController) {
|
||||||
tableView.endUpdates()
|
tableView.endUpdates()
|
||||||
refreshTabBarBadgeCount()
|
//refreshTabBarBadgeCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,6 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
|
|||||||
|
|
||||||
override func viewWillAppear(animated: Bool) {
|
override func viewWillAppear(animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
if fetchedResultController.delegate !== self {
|
|
||||||
fetchedResultController.delegate = self
|
|
||||||
tableView.reloadData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override func viewWillDisappear(animated: Bool) {
|
|
||||||
super.viewWillDisappear(animated)
|
|
||||||
fetchedResultController.delegate = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||||
@ -131,6 +122,10 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||||
|
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
|
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
|
||||||
|
|
||||||
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
|
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.761</string>
|
<string>1.8.777</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.764</string>
|
<string>1.8.780</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -54,14 +54,13 @@ class Network: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSe
|
|||||||
self.context.performBlockAndWait {
|
self.context.performBlockAndWait {
|
||||||
guard let book = Book.fetch(bookID, context: self.context),
|
guard let book = Book.fetch(bookID, context: self.context),
|
||||||
let downloadTask = book.downloadTask else {return}
|
let downloadTask = book.downloadTask else {return}
|
||||||
if error.code == NSURLErrorCancelled {
|
if let resumeData = error.userInfo[NSURLSessionDownloadTaskResumeData] as? NSData {
|
||||||
// If download task doesnt exist, it must mean download is cancelled by user
|
// If download task doesnt exist, it must mean download is cancelled by user
|
||||||
// DownloadTask object will have been deleted when user tap Cancel button / table row action
|
// DownloadTask object will have been deleted when user tap Cancel button / table row action
|
||||||
downloadTask.totalBytesWritten = task.countOfBytesReceived
|
downloadTask.totalBytesWritten = task.countOfBytesReceived
|
||||||
downloadTask.state = .Paused
|
downloadTask.state = .Paused
|
||||||
|
|
||||||
// Save resume data to disk
|
// Save resume data to disk
|
||||||
guard let resumeData = error.userInfo[NSURLSessionDownloadTaskResumeData] as? NSData else {return}
|
|
||||||
Preference.resumeData[bookID] = resumeData
|
Preference.resumeData[bookID] = resumeData
|
||||||
} else {
|
} else {
|
||||||
downloadTask.state = .Error
|
downloadTask.state = .Error
|
||||||
|
@ -20,6 +20,11 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
|
|||||||
super.init(downloadTask: downloadTask)
|
super.init(downloadTask: downloadTask)
|
||||||
name = downloadTask.taskDescription
|
name = downloadTask.taskDescription
|
||||||
|
|
||||||
|
if UIApplication.sharedApplication().applicationState == .Active,
|
||||||
|
let url = downloadTask.originalRequest?.URL {
|
||||||
|
addCondition(ReachabilityCondition(url: url, connectivity: .ViaWiFi))
|
||||||
|
}
|
||||||
|
|
||||||
// Update Coredata
|
// Update Coredata
|
||||||
let context = NSManagedObjectContext.mainQueueContext
|
let context = NSManagedObjectContext.mainQueueContext
|
||||||
context.performBlockAndWait {
|
context.performBlockAndWait {
|
||||||
@ -58,13 +63,7 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
|
|||||||
self.init(downloadTask: task)
|
self.init(downloadTask: task)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func operationWillCancel(errors: [ErrorType]) {
|
|
||||||
print("Download Task will cancel")
|
|
||||||
}
|
|
||||||
|
|
||||||
override func operationDidCancel() {
|
override func operationDidCancel() {
|
||||||
print("Download Task did cancel")
|
|
||||||
|
|
||||||
// Update CoreData
|
// Update CoreData
|
||||||
let context = NSManagedObjectContext.mainQueueContext
|
let context = NSManagedObjectContext.mainQueueContext
|
||||||
context.performBlockAndWait {
|
context.performBlockAndWait {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user