From 6a1c39d8a3c32283a1b9a1dd435e23af693895ea Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 7 Oct 2017 11:56:22 -0700 Subject: [PATCH] Remove Notifications.swift from Data.framework. Clean up UnreadCountProvider. --- Evergreen/BatchUpdate.swift | 4 +-- .../MainWindow/MainWindowController.swift | 2 +- .../Sidebar/SidebarViewController.swift | 4 +-- .../MainWindow/StatusBar/StatusBarView.swift | 12 +++---- .../Timeline/TimelineViewController.swift | 2 +- Frameworks/Account/AccountManager.swift | 4 ++- .../Data/Data.xcodeproj/project.pbxproj | 4 --- Frameworks/Data/Notifications.swift | 21 ----------- Frameworks/Data/UnreadCountProvider.swift | 36 ++++++++++++------- ToDo.opml | 14 +++----- 10 files changed, 43 insertions(+), 60 deletions(-) delete mode 100644 Frameworks/Data/Notifications.swift diff --git a/Evergreen/BatchUpdate.swift b/Evergreen/BatchUpdate.swift index db992fefe..e3f0eabf1 100644 --- a/Evergreen/BatchUpdate.swift +++ b/Evergreen/BatchUpdate.swift @@ -12,7 +12,7 @@ public typealias BatchUpdateBlock = () -> Void public extension Notification.Name { - public static let BatchUpdateDidPerform = Notification.Name(rawValue: "BatchUpdateDidPerform") + public static let BatchUpdateDidFinish = Notification.Name(rawValue: "BatchUpdateDidFinish") } final class BatchUpdate { @@ -60,6 +60,6 @@ private extension BatchUpdate { func postBatchUpdateDidPerform() { - NotificationCenter.default.post(name: .BatchUpdateDidPerform, object: nil, userInfo: nil) + NotificationCenter.default.post(name: .BatchUpdateDidFinish, object: nil, userInfo: nil) } } diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index 7cd7f7126..e9228289f 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -29,7 +29,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { NotificationCenter.default.addObserver(self, selector: #selector(appNavigationKeyPressed(_:)), name: .AppNavigationKeyPressed, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) } // MARK: Notifications diff --git a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift index bea0708bf..342ec7a37 100644 --- a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift +++ b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift @@ -23,7 +23,7 @@ import Account NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) // NotificationCenter.default.addObserver(self, selector: #selector(folderChildrenDidChange(_:)), name: NSNotification.Name(rawValue: FolderChildrenDidChangeNotification), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: UserDidAddFeedNotification, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(dataModelDidPerformBatchUpdates(_:)), name: .DataModelDidPerformBatchUpdates, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidFinish(_:)), name: .BatchUpdateDidFinish, object: nil) outlineView.reloadData() } @@ -43,7 +43,7 @@ import Account rebuildTreeAndReloadDataIfNeeded() } - @objc dynamic func dataModelDidPerformBatchUpdates(_ notification: Notification) { + @objc dynamic func batchUpdateDidFinish(_ notification: Notification) { rebuildTreeAndReloadDataIfNeeded() } diff --git a/Evergreen/MainWindow/StatusBar/StatusBarView.swift b/Evergreen/MainWindow/StatusBar/StatusBarView.swift index 696aab462..dba1991e7 100644 --- a/Evergreen/MainWindow/StatusBar/StatusBarView.swift +++ b/Evergreen/MainWindow/StatusBar/StatusBarView.swift @@ -36,7 +36,7 @@ final class StatusBarView: NSView { progressLabel.font = NSFont.monospacedDigitSystemFont(ofSize: progressLabelFontSize, weight: NSFont.Weight.regular) progressLabel.stringValue = "" - NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(timelineSelectionDidChange(_:)), name: .TimelineSelectionDidChange, object: nil) } @@ -45,11 +45,11 @@ final class StatusBarView: NSView { @objc dynamic func progressDidChange(_ notification: Notification) { - guard let progress = notification.userInfo?[progressKey] as? DownloadProgress else { - return - } - updateProgressIndicator(progress) - updateProgressLabel(progress) +// guard let progress = notification.userInfo?[progressKey] as? DownloadProgress else { +// return +// } +// updateProgressIndicator(progress) +// updateProgressLabel(progress) } // MARK: Notifications diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 39e892fc3..218bdd752 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -76,7 +76,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView if !didRegisterForNotifications { NotificationCenter.default.addObserver(self, selector: #selector(sidebarSelectionDidChange(_:)), name: .SidebarSelectionDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(articleStatusesDidChange(_:)), name: .ArticleStatusesDidChange, object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(articleStatusesDidChange(_:)), name: .ArticleStatusesDidChange, object: nil) NSUserDefaultsController.shared.addObserver(self, forKeyPath: timelineFontSizeKVOKey, options: NSKeyValueObservingOptions(rawValue: 0), context: nil) diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index 1cd0913f9..b12ab7a5b 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -24,7 +24,9 @@ public final class AccountManager: UnreadCountProvider { public var unreadCount = 0 { didSet { - postUnreadCountDidChangeNotification() + if unreadCount != oldValue { + postUnreadCountDidChangeNotification() + } } } diff --git a/Frameworks/Data/Data.xcodeproj/project.pbxproj b/Frameworks/Data/Data.xcodeproj/project.pbxproj index e0f08e543..8b56279d6 100644 --- a/Frameworks/Data/Data.xcodeproj/project.pbxproj +++ b/Frameworks/Data/Data.xcodeproj/project.pbxproj @@ -19,7 +19,6 @@ 844BEE811F0AB4D0004AB7CD /* Author.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE801F0AB4D0004AB7CD /* Author.swift */; }; 844BEE831F0AB4D6004AB7CD /* Attachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE821F0AB4D6004AB7CD /* Attachment.swift */; }; 844BEE851F0AB4DB004AB7CD /* ArticleStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */; }; - 844BEE891F0AB4E7004AB7CD /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE881F0AB4E7004AB7CD /* Notifications.swift */; }; 84C490F41F705D5F003131D2 /* RSWeb.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84C490F51F705D5F003131D2 /* RSWeb.framework */; }; /* End PBXBuildFile section */ @@ -69,7 +68,6 @@ 844BEE801F0AB4D0004AB7CD /* Author.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Author.swift; sourceTree = ""; }; 844BEE821F0AB4D6004AB7CD /* Attachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Attachment.swift; sourceTree = ""; }; 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArticleStatus.swift; sourceTree = ""; }; - 844BEE881F0AB4E7004AB7CD /* Notifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = ""; }; 844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = ""; }; 84C490F51F705D5F003131D2 /* RSWeb.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RSWeb.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -104,7 +102,6 @@ 844BEE821F0AB4D6004AB7CD /* Attachment.swift */, 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */, 840405C91F1A8E4300DF0296 /* DatabaseID.swift */, - 844BEE881F0AB4E7004AB7CD /* Notifications.swift */, 8419741B1F6DD613006346C4 /* UnreadCountProvider.swift */, 8419741F1F6DD672006346C4 /* DisplayNameProvider.swift */, 841974221F6DD804006346C4 /* OPMLRepresentable.swift */, @@ -297,7 +294,6 @@ 844BEE7F1F0AB4CA004AB7CD /* Article.swift in Sources */, 844BEE7D1F0AB4C4004AB7CD /* Feed.swift in Sources */, 841974231F6DD804006346C4 /* OPMLRepresentable.swift in Sources */, - 844BEE891F0AB4E7004AB7CD /* Notifications.swift in Sources */, 844BEE831F0AB4D6004AB7CD /* Attachment.swift in Sources */, 8419741C1F6DD613006346C4 /* UnreadCountProvider.swift in Sources */, 841974201F6DD672006346C4 /* DisplayNameProvider.swift in Sources */, diff --git a/Frameworks/Data/Notifications.swift b/Frameworks/Data/Notifications.swift deleted file mode 100644 index 53c20e503..000000000 --- a/Frameworks/Data/Notifications.swift +++ /dev/null @@ -1,21 +0,0 @@ -// -// Notifications.swift -// DataModel -// -// Created by Brent Simmons on 9/10/16. -// Copyright © 2016 Ranchero Software, LLC. All rights reserved. -// - -import Foundation - -public extension Notification.Name { - - public static let ArticleStatusesDidChange = Notification.Name(rawValue: "ArticleStatusesDidChange") - public static let UnreadCountDidChange = Notification.Name(rawValue: "UnreadCountDidChange") - public static let DataModelDidPerformBatchUpdates = Notification.Name(rawValue: "DataModelDidPerformBatchUpdates") - public static let AccountRefreshProgressDidChange = Notification.Name(rawValue: "AccountRefreshProgressDidChange") -} - -public let articlesKey = "articles" -public let unreadCountKey = "unreadCount" -public let progressKey = "progress" //RSProgress diff --git a/Frameworks/Data/UnreadCountProvider.swift b/Frameworks/Data/UnreadCountProvider.swift index 34d3d4070..8decf754e 100644 --- a/Frameworks/Data/UnreadCountProvider.swift +++ b/Frameworks/Data/UnreadCountProvider.swift @@ -8,28 +8,38 @@ import Foundation +public extension Notification.Name { + + public static let UnreadCountDidChange = Notification.Name(rawValue: "UnreadCountDidChange") +} + public protocol UnreadCountProvider { var unreadCount: Int { get } + + func postUnreadCountDidChangeNotification() + func calculateUnreadCount(_ children: T) -> Int } -public func calculateUnreadCount(_ children: T) -> Int { - - let updatedUnreadCount = children.reduce(0) { (result, oneChild) -> Int in - if let oneUnreadCountProvider = oneChild as? UnreadCountProvider { - return result + oneUnreadCountProvider.unreadCount - } - return result - } - - return updatedUnreadCount -} public extension UnreadCountProvider { public func postUnreadCountDidChangeNotification() { - NotificationCenter.default.post(name: .UnreadCountDidChange, object: self, userInfo: [unreadCountKey: unreadCount]) + NotificationCenter.default.post(name: .UnreadCountDidChange, object: self, userInfo: nil) + } + + public func calculateUnreadCount(_ children: T) -> Int { + + let updatedUnreadCount = children.reduce(0) { (result, oneChild) -> Int in + if let oneUnreadCountProvider = oneChild as? UnreadCountProvider { + return result + oneUnreadCountProvider.unreadCount + } + return result + } + + return updatedUnreadCount } - } + + diff --git a/ToDo.opml b/ToDo.opml index 45c774798..97a6e7637 100644 --- a/ToDo.opml +++ b/ToDo.opml @@ -6,12 +6,12 @@ --> ToDo Tue, 12 Sep 2017 20:15:17 GMT - 23,26,30,35,43,44,48,54,63 + 23,26,30,35,43,44,46,61,66 0 - 208 - 30 - 762 - 967 + 2634 + 558 + 1290 + 3393 @@ -70,8 +70,6 @@ - - @@ -101,8 +99,6 @@ - -