mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Persist the Feeds Read filter across application launches. Issue #1349
This commit is contained in:
@@ -383,12 +383,12 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
||||
}
|
||||
|
||||
@IBAction func toggleFilter(_ sender: Any) {
|
||||
if coordinator.isUnreadFeedsFiltered {
|
||||
if coordinator.isReadFeedsFiltered {
|
||||
filterButton.image = AppAssets.filterInactiveImage
|
||||
coordinator.showAllFeeds()
|
||||
} else {
|
||||
filterButton.image = AppAssets.filterActiveImage
|
||||
coordinator.hideUnreadFeeds()
|
||||
coordinator.hideReadFeeds()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,14 +506,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
||||
}
|
||||
}
|
||||
|
||||
func reloadFeeds() {
|
||||
func reloadFeeds(initialLoad: Bool) {
|
||||
updateUI()
|
||||
|
||||
// We have to reload all the visible cells because if we got here by doing a table cell move,
|
||||
// then the table itself is in a weird state. This is because we do unusual things like allowing
|
||||
// drops on a "folder" that should cause the dropped cell to disappear.
|
||||
applyChanges(animated: true) { [weak self] in
|
||||
self?.reloadAllVisibleCells()
|
||||
applyChanges(animated: !initialLoad) { [weak self] in
|
||||
if !initialLoad {
|
||||
self?.reloadAllVisibleCells()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,6 +635,11 @@ private extension MasterFeedViewController {
|
||||
}
|
||||
|
||||
func updateUI() {
|
||||
if coordinator.isReadFeedsFiltered {
|
||||
filterButton.image = AppAssets.filterActiveImage
|
||||
} else {
|
||||
filterButton.image = AppAssets.filterInactiveImage
|
||||
}
|
||||
refreshProgressView?.updateRefreshLabel()
|
||||
addNewItemButton?.isEnabled = !AccountManager.shared.activeAccounts.isEmpty
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
return panelMode == .three
|
||||
}
|
||||
|
||||
var isUnreadFeedsFiltered: Bool {
|
||||
var isReadFeedsFiltered: Bool {
|
||||
return treeControllerDelegate.isReadFiltered
|
||||
}
|
||||
|
||||
@@ -279,8 +279,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
shadowTable.append([Node]())
|
||||
}
|
||||
|
||||
rebuildShadowTable()
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
|
||||
@@ -307,7 +306,6 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
masterFeedViewController = UIStoryboard.main.instantiateController(ofType: MasterFeedViewController.self)
|
||||
masterFeedViewController.coordinator = self
|
||||
masterNavigationController.pushViewController(masterFeedViewController, animated: false)
|
||||
masterFeedViewController.reloadFeeds()
|
||||
|
||||
let articleViewController = UIStoryboard.main.instantiateController(ofType: ArticleViewController.self)
|
||||
articleViewController.coordinator = self
|
||||
@@ -319,12 +317,11 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
return rootSplitViewController
|
||||
}
|
||||
|
||||
func restoreWindowState(_ activity: NSUserActivity) {
|
||||
if let windowState = activity.userInfo?[UserInfoKey.windowState] as? [AnyHashable: Any] {
|
||||
func restoreWindowState(_ activity: NSUserActivity?) {
|
||||
if let activity = activity, let windowState = activity.userInfo?[UserInfoKey.windowState] as? [AnyHashable: Any] {
|
||||
restoreWindowState(windowState)
|
||||
rebuildShadowTable()
|
||||
masterFeedViewController.reloadFeeds()
|
||||
}
|
||||
rebuildBackingStores(initialLoad: true)
|
||||
}
|
||||
|
||||
func handle(_ activity: NSUserActivity) {
|
||||
@@ -387,6 +384,15 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
@objc func unreadCountDidInitialize(_ notification: Notification) {
|
||||
guard notification.object is AccountManager else {
|
||||
return
|
||||
}
|
||||
if isReadFeedsFiltered {
|
||||
rebuildBackingStores()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func statusesDidChange(_ note: Notification) {
|
||||
updateUnreadCount()
|
||||
}
|
||||
@@ -525,7 +531,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
rebuildBackingStores()
|
||||
}
|
||||
|
||||
func hideUnreadFeeds() {
|
||||
func hideReadFeeds() {
|
||||
treeControllerDelegate.isReadFiltered = true
|
||||
rebuildBackingStores()
|
||||
}
|
||||
@@ -1150,12 +1156,12 @@ private extension SceneCoordinator {
|
||||
unreadCount = count
|
||||
}
|
||||
|
||||
func rebuildBackingStores(_ updateExpandedNodes: (() -> Void)? = nil) {
|
||||
func rebuildBackingStores(initialLoad: Bool = false, updateExpandedNodes: (() -> Void)? = nil) {
|
||||
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
||||
treeController.rebuild()
|
||||
updateExpandedNodes?()
|
||||
rebuildShadowTable()
|
||||
masterFeedViewController.reloadFeeds()
|
||||
masterFeedViewController.reloadFeeds(initialLoad: initialLoad)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1759,11 +1765,15 @@ private extension SceneCoordinator {
|
||||
func windowState() -> [AnyHashable: Any] {
|
||||
let containerIdentifierUserInfos = expandedTable.map( { $0.userInfo })
|
||||
return [
|
||||
UserInfoKey.readFeedsFilterState: isReadFeedsFiltered,
|
||||
UserInfoKey.containerExpandedWindowState: containerIdentifierUserInfos
|
||||
]
|
||||
}
|
||||
|
||||
func restoreWindowState(_ windowState: [AnyHashable: Any]) {
|
||||
if let readFeedsFilterState = windowState[UserInfoKey.readFeedsFilterState] as? Bool {
|
||||
treeControllerDelegate.isReadFiltered = readFeedsFilterState
|
||||
}
|
||||
if let containerIdentifierUserInfos = windowState[UserInfoKey.containerExpandedWindowState] as? [[AnyHashable: Any]] {
|
||||
let containerIdentifers = containerIdentifierUserInfos.compactMap( { ContainerIdentifier(userInfo: $0) })
|
||||
expandedTable = Set(containerIdentifers)
|
||||
|
||||
@@ -23,9 +23,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
window!.tintColor = AppAssets.primaryAccentColor
|
||||
window!.rootViewController = coordinator.start(for: window!.frame.size)
|
||||
|
||||
if let stateRestorationActivity = session.stateRestorationActivity {
|
||||
coordinator.restoreWindowState(stateRestorationActivity)
|
||||
}
|
||||
coordinator.restoreWindowState(session.stateRestorationActivity)
|
||||
|
||||
if let shortcutItem = connectionOptions.shortcutItem {
|
||||
window!.makeKeyAndVisible()
|
||||
|
||||
Reference in New Issue
Block a user