Don't start the article extractor if we only want to store the article. Issue #1494

This commit is contained in:
Maurice Parker 2020-03-14 06:31:14 -05:00
parent aee37925da
commit 07dc4f1f10
2 changed files with 21 additions and 16 deletions

View File

@ -44,7 +44,7 @@ class ArticleViewController: UIViewController {
var article: Article? { var article: Article? {
didSet { didSet {
if let controller = currentWebViewController, controller.article != article { if let controller = currentWebViewController, controller.article != article {
controller.article = article controller.setArticle(article)
DispatchQueue.main.async { DispatchQueue.main.async {
// You have to set the view controller to clear out the UIPageViewController child controller cache. // You have to set the view controller to clear out the UIPageViewController child controller cache.
// You also have to do it in an async call or you will get a strange assertion error. // You also have to do it in an async call or you will get a strange assertion error.
@ -103,7 +103,7 @@ class ArticleViewController: UIViewController {
view.bottomAnchor.constraint(equalTo: pageViewController.view.bottomAnchor) view.bottomAnchor.constraint(equalTo: pageViewController.view.bottomAnchor)
]) ])
let controller = createWebViewController(article) let controller = createWebViewController(article, updateView: false)
if let state = restoreState { if let state = restoreState {
controller.extractedArticle = state.extractedArticle controller.extractedArticle = state.extractedArticle
controller.isShowingExtractedArticle = state.isShowingExtractedArticle controller.isShowingExtractedArticle = state.isShowingExtractedArticle
@ -329,11 +329,11 @@ extension ArticleViewController: UIPageViewControllerDelegate {
private extension ArticleViewController { private extension ArticleViewController {
func createWebViewController(_ article: Article?) -> WebViewController { func createWebViewController(_ article: Article?, updateView: Bool = true) -> WebViewController {
let controller = WebViewController() let controller = WebViewController()
controller.coordinator = coordinator controller.coordinator = coordinator
controller.delegate = self controller.delegate = self
controller.article = article controller.setArticle(article, updateView: updateView)
return controller return controller
} }

View File

@ -57,18 +57,7 @@ class WebViewController: UIViewController {
weak var coordinator: SceneCoordinator! weak var coordinator: SceneCoordinator!
weak var delegate: WebViewControllerDelegate? weak var delegate: WebViewControllerDelegate?
var article: Article? { private(set) var article: Article?
didSet {
stopArticleExtractor()
if article?.webFeed?.isArticleExtractorAlwaysOn ?? false {
startArticleExtractor()
}
if article != oldValue {
windowScrollY = 0
loadWebView()
}
}
}
let scrollPositionQueue = CoalescingQueue(name: "Article Scroll Position", interval: 0.3, maxInterval: 1.0) let scrollPositionQueue = CoalescingQueue(name: "Article Scroll Position", interval: 0.3, maxInterval: 1.0)
var windowScrollY = 0 var windowScrollY = 0
@ -114,6 +103,22 @@ class WebViewController: UIViewController {
// MARK: API // MARK: API
func setArticle(_ article: Article?, updateView: Bool = true) {
stopArticleExtractor()
if article != self.article {
self.article = article
if updateView {
if article?.webFeed?.isArticleExtractorAlwaysOn ?? false {
startArticleExtractor()
}
windowScrollY = 0
loadWebView()
}
}
}
func focus() { func focus() {
webView?.becomeFirstResponder() webView?.becomeFirstResponder()
} }