Fix how the Article Unread Count is updated

This commit is contained in:
Maurice Parker
2022-10-04 20:19:47 -05:00
parent 7e238a0d07
commit f38ab1ab51
2 changed files with 12 additions and 14 deletions

View File

@@ -102,7 +102,6 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable {
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadDueToThemeChange(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(configureAppearanceMenu(_:)), name: .ArticleThemeNamesDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(updateUnreadCountIndicator(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
articleExtractorButton.addTarget(self, action: #selector(toggleArticleExtractor(_:)), for: .touchUpInside)
toolbarItems?.insert(UIBarButtonItem(customView: articleExtractorButton), at: 6)
@@ -349,9 +348,8 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable {
/// For iPad, this indicator is visible if it is in `portrait` or `unknown`
/// orientation, **and** the unread count is > 0.
/// - Parameter sender: `Any` (optional)
@objc
public func updateUnreadCountIndicator(_ sender: Any? = nil) {
if UIDevice.current.userInterfaceIdiom == .phone {
public func updateUnreadCountIndicator(forDisplayMode displayMode: UISplitViewController.DisplayMode? = nil) {
func changeUnreadCountIndicator() {
if currentUnreadCount > 0 {
let unreadCountView = MasterTimelineUnreadCountView(frame: .zero)
unreadCountView.unreadCount = currentUnreadCount
@@ -360,17 +358,13 @@ class ArticleViewController: UIViewController, MainControllerIdentifiable {
} else {
navigationItem.leftBarButtonItem = nil
}
}
if UIDevice.current.userInterfaceIdiom == .phone {
changeUnreadCountIndicator()
} else {
if UIDevice.current.orientation.isPortrait || !UIDevice.current.orientation.isValidInterfaceOrientation {
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 displayMode == nil || displayMode == .secondaryOnly {
changeUnreadCountIndicator()
} else {
navigationItem.leftBarButtonItem = nil
}

View File

@@ -1323,6 +1323,10 @@ extension SceneCoordinator: UISplitViewControllerDelegate {
}
}
func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) {
articleViewController?.updateUnreadCountIndicator(forDisplayMode: displayMode)
}
}
// MARK: UINavigationControllerDelegate