From a72e0f047fc29e945e9a356265bcc5d111345b7f Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 12 Feb 2022 11:35:13 +0800 Subject: [PATCH 1/3] Adds unread count indicator to Article view Fixes #3134 --- iOS/Article/ArticleViewController.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 26d22aa01..4640bf4d0 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -105,6 +105,8 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { parentNavController.interactivePopGestureRecognizer?.delegate = poppableDelegate } + navigationItem.leftItemsSupplementBackButton = true + pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: [:]) pageViewController.delegate = self pageViewController.dataSource = self @@ -225,6 +227,25 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { starBarButtonItem.accLabelText = NSLocalizedString("Star Article", comment: "Star Article") } + configureUnreadCountView() + + } + + func configureUnreadCountView() { + guard let controllers = poppableDelegate.navigationController?.viewControllers, + controllers.count >= 2 else { return } + for controller in controllers { + if let feedController = controller as? MasterFeedViewController { + if feedController.coordinator.timelineUnreadCount > 0 { + let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) + unreadCountView.unreadCount = feedController.coordinator.timelineUnreadCount + unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) + navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) + } else { + navigationItem.leftBarButtonItem = nil + } + } + } } override func contentScrollView(for edge: NSDirectionalRectEdge) -> UIScrollView? { @@ -287,6 +308,7 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { } + // MARK: Notifications @objc dynamic func unreadCountDidChange(_ notification: Notification) { From 6eb18ce183b2a91e5d61f34473b486b33bd2ade9 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 13 Feb 2022 08:06:10 +0800 Subject: [PATCH 2/3] Article unread count updated via scenecoordinator --- iOS/Article/ArticleViewController.swift | 36 ++++++++++++------------- iOS/SceneCoordinator.swift | 2 +- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 4640bf4d0..c925fcaae 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -87,6 +87,12 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { return keyboardManager.keyCommands } + var currentUnreadCount: Int = 0 { + didSet { + updateUnreadCountIndicator() + } + } + override func viewDidLoad() { super.viewDidLoad() @@ -227,25 +233,6 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { starBarButtonItem.accLabelText = NSLocalizedString("Star Article", comment: "Star Article") } - configureUnreadCountView() - - } - - func configureUnreadCountView() { - guard let controllers = poppableDelegate.navigationController?.viewControllers, - controllers.count >= 2 else { return } - for controller in controllers { - if let feedController = controller as? MasterFeedViewController { - if feedController.coordinator.timelineUnreadCount > 0 { - let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) - unreadCountView.unreadCount = feedController.coordinator.timelineUnreadCount - unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) - navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) - } else { - navigationItem.leftBarButtonItem = nil - } - } - } } override func contentScrollView(for edge: NSDirectionalRectEdge) -> UIScrollView? { @@ -307,6 +294,17 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { configureAppearanceMenu() } + public func updateUnreadCountIndicator() { + if currentUnreadCount > 0 { + let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) + unreadCountView.unreadCount = currentUnreadCount + unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) + navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) + } else { + navigationItem.leftBarButtonItem = nil + } + } + // MARK: Notifications diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 73d9c58b6..d884975d7 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -822,7 +822,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner { // Mark article as read before navigating to it, so the read status does not flash unread/read on display markArticles(Set([article!]), statusKey: .read, flag: true) - masterTimelineViewController?.updateArticleSelection(animations: animations) articleViewController?.article = article if let isShowingExtractedArticle = isShowingExtractedArticle, let articleWindowScrollY = articleWindowScrollY { @@ -1404,6 +1403,7 @@ private extension SceneCoordinator { } } timelineUnreadCount = count + articleViewController?.currentUnreadCount = timelineUnreadCount } func rebuildArticleDictionaries() { From 3fd92fd63e7b88af64f8d1185468a922ef0a77cf Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 13 Feb 2022 08:08:51 +0800 Subject: [PATCH 3/3] suppress unread count on iPad --- iOS/Article/ArticleViewController.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index c925fcaae..05310ab86 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -295,13 +295,15 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable { } public func updateUnreadCountIndicator() { - if currentUnreadCount > 0 { - let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) - unreadCountView.unreadCount = currentUnreadCount - unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) - navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) - } else { - navigationItem.leftBarButtonItem = nil + if UIDevice.current.userInterfaceIdiom == .phone { + if currentUnreadCount > 0 { + let unreadCountView = MasterTimelineUnreadCountView(frame: .zero) + unreadCountView.unreadCount = currentUnreadCount + unreadCountView.setFrameIfNotEqual(CGRect(x: 0, y: 0, width: unreadCountView.intrinsicContentSize.width, height: unreadCountView.intrinsicContentSize.height)) + navigationItem.leftBarButtonItem = UIBarButtonItem(customView: unreadCountView) + } else { + navigationItem.leftBarButtonItem = nil + } } }