From f22415e3c99be37f60f687afcac91816f55745b6 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Mon, 19 Sep 2016 10:03:21 -0400 Subject: [PATCH] commit --- .../Library/BookDetailController.swift | 28 ++++++++-------- .../Library/CloudBooksController.swift | 9 +++--- .../Library/DownloadTasksController.swift | 32 +++++++------------ .../Library/LocalBooksController.swift | 13 +++----- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOSWidgets/Bookmarks/Info.plist | 2 +- Kiwix/Network/Network.swift | 3 +- Kiwix/Operations/BookOperation.swift | 11 +++---- 8 files changed, 42 insertions(+), 58 deletions(-) diff --git a/Kiwix-iOS/Controller/Library/BookDetailController.swift b/Kiwix-iOS/Controller/Library/BookDetailController.swift index 08da0b98..e337b788 100644 --- a/Kiwix-iOS/Controller/Library/BookDetailController.swift +++ b/Kiwix-iOS/Controller/Library/BookDetailController.swift @@ -45,22 +45,22 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) configureViews() - book?.addObserver(self, forKeyPath: "isLocal", options: .New, context: context) +// book?.addObserver(self, forKeyPath: "isLocal", options: .New, context: context) } override func viewWillDisappear(animated: Bool) { 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) { - guard let book = object as? Book where context == self.context else {return} - NSOperationQueue.mainQueue().addOperationWithBlock { - print(book.isLocal) - self.configureActionSection(book) - self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Fade) - } - } +// override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) { +// guard let book = object as? Book where context == self.context else {return} +// NSOperationQueue.mainQueue().addOperationWithBlock { +// print(book.isLocal) +// self.configureActionSection(book) +// self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Fade) +// } +// } // MARK: - Configure @@ -90,10 +90,10 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp cellTitles.append([String]()) // Action Cells - sectionHeaders.append(nil) - sectionFooters.append(nil) - cellTitles.append([]) - configureActionSection(book) +// sectionHeaders.append(nil) +// sectionFooters.append(nil) +// cellTitles.append([]) +// configureActionSection(book) // Book Info sectionHeaders.append(Strings.bookInfo) diff --git a/Kiwix-iOS/Controller/Library/CloudBooksController.swift b/Kiwix-iOS/Controller/Library/CloudBooksController.swift index efc37580..a4604a07 100644 --- a/Kiwix-iOS/Controller/Library/CloudBooksController.swift +++ b/Kiwix-iOS/Controller/Library/CloudBooksController.swift @@ -39,17 +39,12 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) tabBarController?.navigationItem.rightBarButtonItem = UIBarButtonItem(imageNamed: "LanguageFilter", target: self, action: #selector(CloudBooksController.showLanguageFilter)) - if fetchedResultController.delegate !== self { - fetchedResultController.delegate = self - tableView.reloadData() - } refreshAutomatically() } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) tabBarController?.navigationItem.rightBarButtonItem = nil - fetchedResultController.delegate = nil } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { @@ -262,6 +257,10 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel 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 { return true } diff --git a/Kiwix-iOS/Controller/Library/DownloadTasksController.swift b/Kiwix-iOS/Controller/Library/DownloadTasksController.swift index be7a233a..d421c695 100644 --- a/Kiwix-iOS/Controller/Library/DownloadTasksController.swift +++ b/Kiwix-iOS/Controller/Library/DownloadTasksController.swift @@ -37,17 +37,12 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) 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) { super.viewWillDisappear(animated) timer?.invalidate() timer = nil - fetchedResultController.delegate = nil } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { @@ -174,6 +169,10 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController // 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 { return true } @@ -200,19 +199,13 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController tableView.setEditing(false, animated: true) } actions.insert(resume, atIndex: 0) -// -// if let book = downloadTask.book, -// let resumeData = Preference.resumeData[book.id] { -// -// } else { -// let restart = UITableViewRowAction(style: .Normal, title: "Restart") { (action, indexPath) in -// guard let bookID = downloadTask.book?.id, -// let operation = DownloadBookOperation(bookID: bookID) else {return} -// Network.shared.queue.addOperation(operation) -// tableView.setEditing(false, animated: true) -// } -// actions.insert(restart, atIndex: 0) -// } + case .Error: + let retry = UITableViewRowAction(style: .Normal, title: "Restart") { (action, indexPath) in + let operation = ResumeBookDwonloadOperation(bookID: bookID) + GlobalQueue.shared.addOperation(operation) + tableView.setEditing(false, animated: true) + } + actions.insert(retry, atIndex: 0) default: break } @@ -294,7 +287,6 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController func controllerDidChangeContent(controller: NSFetchedResultsController) { tableView.endUpdates() - refreshTabBarBadgeCount() + //refreshTabBarBadgeCount() } - } diff --git a/Kiwix-iOS/Controller/Library/LocalBooksController.swift b/Kiwix-iOS/Controller/Library/LocalBooksController.swift index 82db1e29..e5bcce44 100644 --- a/Kiwix-iOS/Controller/Library/LocalBooksController.swift +++ b/Kiwix-iOS/Controller/Library/LocalBooksController.swift @@ -32,15 +32,6 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel override func viewWillAppear(animated: Bool) { 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?) { @@ -131,6 +122,10 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel 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, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 2d404c19..9f83679e 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.761 + 1.8.777 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index 46c834db..40a7eed8 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.764 + 1.8.780 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix/Network/Network.swift b/Kiwix/Network/Network.swift index 5d38d47b..5f1fb260 100644 --- a/Kiwix/Network/Network.swift +++ b/Kiwix/Network/Network.swift @@ -54,14 +54,13 @@ class Network: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSe self.context.performBlockAndWait { guard let book = Book.fetch(bookID, context: self.context), 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 // DownloadTask object will have been deleted when user tap Cancel button / table row action downloadTask.totalBytesWritten = task.countOfBytesReceived downloadTask.state = .Paused // Save resume data to disk - guard let resumeData = error.userInfo[NSURLSessionDownloadTaskResumeData] as? NSData else {return} Preference.resumeData[bookID] = resumeData } else { downloadTask.state = .Error diff --git a/Kiwix/Operations/BookOperation.swift b/Kiwix/Operations/BookOperation.swift index 1af00037..5056650c 100644 --- a/Kiwix/Operations/BookOperation.swift +++ b/Kiwix/Operations/BookOperation.swift @@ -20,6 +20,11 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation { super.init(downloadTask: downloadTask) name = downloadTask.taskDescription + if UIApplication.sharedApplication().applicationState == .Active, + let url = downloadTask.originalRequest?.URL { + addCondition(ReachabilityCondition(url: url, connectivity: .ViaWiFi)) + } + // Update Coredata let context = NSManagedObjectContext.mainQueueContext context.performBlockAndWait { @@ -58,13 +63,7 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation { self.init(downloadTask: task) } - override func operationWillCancel(errors: [ErrorType]) { - print("Download Task will cancel") - } - override func operationDidCancel() { - print("Download Task did cancel") - // Update CoreData let context = NSManagedObjectContext.mainQueueContext context.performBlockAndWait {