Remove Notifications.swift from Data.framework. Clean up UnreadCountProvider.

This commit is contained in:
Brent Simmons 2017-10-07 11:56:22 -07:00
parent 12ea6e6a9f
commit 6a1c39d8a3
10 changed files with 43 additions and 60 deletions

View File

@ -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)
}
}

View File

@ -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

View File

@ -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()
}

View File

@ -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

View File

@ -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)

View File

@ -24,7 +24,9 @@ public final class AccountManager: UnreadCountProvider {
public var unreadCount = 0 {
didSet {
postUnreadCountDidChangeNotification()
if unreadCount != oldValue {
postUnreadCountDidChangeNotification()
}
}
}

View File

@ -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 = "<group>"; };
844BEE821F0AB4D6004AB7CD /* Attachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Attachment.swift; sourceTree = "<group>"; };
844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArticleStatus.swift; sourceTree = "<group>"; };
844BEE881F0AB4E7004AB7CD /* Notifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
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 */,

View File

@ -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

View File

@ -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<T: Collection>(_ children: T) -> Int
}
public func calculateUnreadCount<T: Collection>(_ 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<T: Collection>(_ 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
}
}

View File

@ -6,12 +6,12 @@
</editor> -->
<title>ToDo</title>
<dateCreated>Tue, 12 Sep 2017 20:15:17 GMT</dateCreated>
<expansionState>23,26,30,35,43,44,48,54,63</expansionState>
<expansionState>23,26,30,35,43,44,46,61,66</expansionState>
<vertScrollState>0</vertScrollState>
<windowTop>208</windowTop>
<windowLeft>30</windowLeft>
<windowRight>762</windowRight>
<windowBottom>967</windowBottom>
<windowTop>2634</windowTop>
<windowLeft>558</windowLeft>
<windowRight>1290</windowRight>
<windowBottom>3393</windowBottom>
</head>
<body>
<outline text="App">
@ -70,8 +70,6 @@
</outline>
<outline text="Frameworks">
<outline text="Account">
<outline text="Save account settings and feeds to disk"/>
<outline text="Read account settings and feeds from disk"/>
<outline text="Update feed unread counts at startup"/>
</outline>
<outline text="Database">
@ -101,8 +99,6 @@
</outline>
<outline text="Data">
<outline text="Make model classes quicklookable"/>
<outline text="Move BatchUpdates.swift somewhere"/>
<outline text="Move Notifications.swift somewhere"/>
</outline>
<outline text="RSParser">
<outline text="ParsedItem == should compare all properties"/>