Create ArticleIconSchemeHandlerDelegate, so ArticleIconSchemeHandler doesn’t have to know about SceneCoordinator.
This commit is contained in:
parent
28ff23ee7b
commit
ebddf37f47
@ -8,19 +8,23 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import WebKit
|
import WebKit
|
||||||
import Articles
|
|
||||||
|
|
||||||
class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
protocol ArticleIconSchemeHandlerDelegate: AnyObject {
|
||||||
|
|
||||||
weak var coordinator: SceneCoordinator?
|
func iconImage(for articleID: String) -> IconImage?
|
||||||
|
}
|
||||||
|
|
||||||
init(coordinator: SceneCoordinator) {
|
final class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||||
self.coordinator = coordinator
|
|
||||||
|
weak var delegate: ArticleIconSchemeHandlerDelegate?
|
||||||
|
|
||||||
|
init(delegate: ArticleIconSchemeHandlerDelegate) {
|
||||||
|
self.delegate = delegate
|
||||||
}
|
}
|
||||||
|
|
||||||
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
||||||
|
|
||||||
guard let url = urlSchemeTask.request.url, let coordinator = coordinator else {
|
guard let url = urlSchemeTask.request.url, let delegate else {
|
||||||
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -29,7 +33,7 @@ class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let articleID = components.path
|
let articleID = components.path
|
||||||
guard let iconImage = coordinator.articleFor(articleID)?.iconImage() else {
|
guard let iconImage = delegate.iconImage(for: articleID) else {
|
||||||
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
urlSchemeTask.didFailWithError(URLError(.fileDoesNotExist))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -49,12 +53,10 @@ class ArticleIconSchemeHandler: NSObject, WKURLSchemeHandler {
|
|||||||
urlSchemeTask.didReceive(data)
|
urlSchemeTask.didReceive(data)
|
||||||
urlSchemeTask.didFinish()
|
urlSchemeTask.didFinish()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
||||||
urlSchemeTask.didFailWithError(URLError(.unknown))
|
urlSchemeTask.didFailWithError(URLError(.unknown))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class WebViewController: UIViewController {
|
|||||||
private var isFullScreenAvailable: Bool {
|
private var isFullScreenAvailable: Bool {
|
||||||
return AppDefaults.shared.articleFullscreenAvailable && traitCollection.userInterfaceIdiom == .phone && coordinator.isRootSplitCollapsed
|
return AppDefaults.shared.articleFullscreenAvailable && traitCollection.userInterfaceIdiom == .phone && coordinator.isRootSplitCollapsed
|
||||||
}
|
}
|
||||||
private lazy var articleIconSchemeHandler = ArticleIconSchemeHandler(coordinator: coordinator);
|
private lazy var articleIconSchemeHandler = ArticleIconSchemeHandler(delegate: self);
|
||||||
private lazy var transition = ImageTransition(controller: self)
|
private lazy var transition = ImageTransition(controller: self)
|
||||||
private var clickedImageCompletion: (() -> Void)?
|
private var clickedImageCompletion: (() -> Void)?
|
||||||
|
|
||||||
@ -326,6 +326,16 @@ extension WebViewController: ArticleExtractorDelegate {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MARK: ArticleIconSchemeHandlerDelegate
|
||||||
|
|
||||||
|
extension WebViewController: ArticleIconSchemeHandlerDelegate {
|
||||||
|
|
||||||
|
func iconImage(for articleID: String) -> IconImage? {
|
||||||
|
coordinator.articleFor(articleID)?.iconImage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: UIContextMenuInteractionDelegate
|
// MARK: UIContextMenuInteractionDelegate
|
||||||
|
|
||||||
extension WebViewController: UIContextMenuInteractionDelegate {
|
extension WebViewController: UIContextMenuInteractionDelegate {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user