mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-28 06:25:04 -04:00
ArticleLoadOperation
This commit is contained in:
parent
71e43c60e4
commit
99e5193a96
@ -125,8 +125,6 @@ class MainController: UIViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard let url = url else {return}
|
guard let url = url else {return}
|
||||||
webView.hidden = false
|
|
||||||
hideWelcome()
|
|
||||||
let request = NSURLRequest(URL: url)
|
let request = NSURLRequest(URL: url)
|
||||||
webView.loadRequest(request)
|
webView.loadRequest(request)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,13 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate,
|
|||||||
|
|
||||||
func webViewDidStartLoad(webView: UIWebView) {
|
func webViewDidStartLoad(webView: UIWebView) {
|
||||||
URLResponseCache.shared.start()
|
URLResponseCache.shared.start()
|
||||||
|
|
||||||
|
// UI Updates
|
||||||
|
if webView.hidden {
|
||||||
|
webView.hidden = false
|
||||||
|
hideWelcome()
|
||||||
|
}
|
||||||
|
hideSearch(animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func webViewDidFinishLoad(webView: UIWebView) {
|
func webViewDidFinishLoad(webView: UIWebView) {
|
||||||
|
@ -106,11 +106,10 @@ class SearchResultTBVC: UIViewController, UITableViewDataSource, UITableViewDele
|
|||||||
|
|
||||||
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||||
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||||
guard let mainVC = parentViewController?.parentViewController as? MainController else {return}
|
|
||||||
let result = searchResults[indexPath.row]
|
let result = searchResults[indexPath.row]
|
||||||
let url = NSURL.kiwixURLWithZimFileid(result.bookID, articleTitle: result.title)
|
let operation = ArticleLoadOperation(bookID: result.bookID, articleTitle: result.title)
|
||||||
mainVC.load(url)
|
GlobalQueue.shared.add(load: operation)
|
||||||
mainVC.hideSearch(animated: true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Search
|
// MARK: - Search
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.369</string>
|
<string>1.8.401</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.372</string>
|
<string>1.8.404</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -10,15 +10,71 @@ import UIKit
|
|||||||
import Operations
|
import Operations
|
||||||
|
|
||||||
class ArticleLoadOperation: Operation {
|
class ArticleLoadOperation: Operation {
|
||||||
let url: NSURL
|
let bookID: String?
|
||||||
|
let path: String?
|
||||||
|
let title: String?
|
||||||
|
let url: NSURL?
|
||||||
|
|
||||||
init?(url: NSURL) {
|
init(url: NSURL) {
|
||||||
|
self.bookID = nil
|
||||||
|
self.path = nil
|
||||||
|
self.title = nil
|
||||||
self.url = url
|
self.url = url
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func execute() {
|
init(bookID: String) {
|
||||||
|
self.bookID = bookID
|
||||||
|
self.path = nil
|
||||||
|
self.title = nil
|
||||||
|
self.url = nil
|
||||||
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init(bookID: String, articlePath: String) {
|
||||||
|
self.bookID = bookID
|
||||||
|
self.path = articlePath
|
||||||
|
self.title = nil
|
||||||
|
self.url = nil
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
init(bookID: String, articleTitle: String) {
|
||||||
|
self.bookID = bookID
|
||||||
|
self.path = nil
|
||||||
|
self.title = articleTitle
|
||||||
|
self.url = nil
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func execute() {
|
||||||
|
let controller = ((UIApplication.sharedApplication().delegate as! AppDelegate)
|
||||||
|
.window?.rootViewController as! UINavigationController)
|
||||||
|
.topViewController as! MainController
|
||||||
|
guard let url: NSURL = {
|
||||||
|
if let url = self.url { return url}
|
||||||
|
if let bookID = bookID, let path = path { return NSURL(bookID: bookID, contentPath: path) }
|
||||||
|
if let bookID = bookID, let title = title {
|
||||||
|
guard let path = ZimMultiReader.shared.readers[bookID]?.pageURLFromTitle(title) else {return nil}
|
||||||
|
return NSURL(bookID: bookID, contentPath: path)
|
||||||
|
}
|
||||||
|
if let bookID = bookID {
|
||||||
|
guard let reader = ZimMultiReader.shared.readers[bookID] else {return nil}
|
||||||
|
let path = reader.mainPageURL()
|
||||||
|
return NSURL(bookID: bookID, contentPath: path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}() else {
|
||||||
|
// TODO - should produce error
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let request = NSURLRequest(URL: url)
|
||||||
|
|
||||||
|
NSOperationQueue.mainQueue().addOperationWithBlock {
|
||||||
|
controller.webView.loadRequest(request)
|
||||||
|
self.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ class GlobalQueue: OperationQueue {
|
|||||||
|
|
||||||
private weak var scanOperation: ScanLocalBookOperation?
|
private weak var scanOperation: ScanLocalBookOperation?
|
||||||
private weak var searchOperation: SearchOperation?
|
private weak var searchOperation: SearchOperation?
|
||||||
|
private weak var articleLoadOperation: ArticleLoadOperation?
|
||||||
|
|
||||||
func add(scan operation: ScanLocalBookOperation) {
|
func add(scan operation: ScanLocalBookOperation) {
|
||||||
addOperation(operation)
|
addOperation(operation)
|
||||||
@ -20,13 +21,8 @@ class GlobalQueue: OperationQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func add(search operation: SearchOperation) {
|
func add(search operation: SearchOperation) {
|
||||||
if let _ = searchOperation {
|
|
||||||
print("search is not released")
|
|
||||||
}
|
|
||||||
|
|
||||||
if let scanOperation = scanOperation {
|
if let scanOperation = scanOperation {
|
||||||
operation.addDependency(scanOperation)
|
operation.addDependency(scanOperation)
|
||||||
print("scan not finished")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let searchOperation = self.searchOperation {
|
if let searchOperation = self.searchOperation {
|
||||||
@ -35,6 +31,19 @@ class GlobalQueue: OperationQueue {
|
|||||||
addOperation(operation)
|
addOperation(operation)
|
||||||
searchOperation = operation
|
searchOperation = operation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func add(load operation: ArticleLoadOperation) {
|
||||||
|
if let scanOperation = scanOperation {
|
||||||
|
operation.addDependency(scanOperation)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let articleLoadOperation = self.articleLoadOperation {
|
||||||
|
operation.addDependency(articleLoadOperation)
|
||||||
|
}
|
||||||
|
|
||||||
|
addOperation(operation)
|
||||||
|
articleLoadOperation = operation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum OperationErrorCode: Int {
|
public enum OperationErrorCode: Int {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user