Add timeline filter button

This commit is contained in:
Maurice Parker 2019-11-21 18:22:43 -06:00
parent 64c1a615b0
commit e8826130a4
8 changed files with 67 additions and 3 deletions

View File

@ -9,6 +9,14 @@
import Foundation
import RSCore
public enum ReadFilter {
case read
case all
case none
}
public protocol Feed: FeedIdentifiable, ArticleFetcher, DisplayNameProvider, UnreadCountProvider {
var defaultReadFilter: ReadFilter { get }
}

View File

@ -12,6 +12,10 @@ import RSCore
public final class Folder: Feed, Renamable, Container, Hashable {
public var defaultReadFilter: ReadFilter {
return .read
}
public var feedID: FeedIdentifier? {
guard let accountID = account?.accountID else {
assertionFailure("Expected feed.account, but got nil.")

View File

@ -13,6 +13,10 @@ import Articles
public final class WebFeed: Feed, Renamable, Hashable {
public var defaultReadFilter: ReadFilter {
return .all
}
public var feedID: FeedIdentifier? {
guard let accountID = account?.accountID else {
assertionFailure("Expected feed.account, but got nil.")

View File

@ -13,6 +13,10 @@ import Account
final class SmartFeed: PseudoFeed {
public var defaultReadFilter: ReadFilter {
return .all
}
var feedID: FeedIdentifier? {
delegate.feedID
}

View File

@ -19,6 +19,10 @@ import Articles
final class UnreadFeed: PseudoFeed {
public var defaultReadFilter: ReadFilter {
return .none
}
var feedID: FeedIdentifier? {
return FeedIdentifier.smartFeed(String(describing: UnreadFeed.self))
}

View File

@ -167,10 +167,17 @@
</connections>
</barButtonItem>
</toolbarItems>
<navigationItem key="navigationItem" title="Timeline" largeTitleDisplayMode="never" id="wcC-1L-ug4"/>
<navigationItem key="navigationItem" title="Timeline" largeTitleDisplayMode="never" id="wcC-1L-ug4">
<barButtonItem key="rightBarButtonItem" image="line.horizontal.3.decrease.circle" catalog="system" id="af2-lj-EcA">
<connections>
<action selector="toggleFilter:" destination="Kyk-vK-QRX" id="jxP-b2-V1n"/>
</connections>
</barButtonItem>
</navigationItem>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" translucent="NO" prompted="NO"/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics" translucent="NO"/>
<connections>
<outlet property="filterButton" destination="af2-lj-EcA" id="uGR-n0-YKf"/>
<outlet property="firstUnreadButton" destination="2v2-jD-C9k" id="8NP-Uc-3Fn"/>
<outlet property="markAllAsReadButton" destination="fTv-eX-72r" id="12S-lN-Sxa"/>
</connections>

View File

@ -17,6 +17,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
private var numberOfTextLines = 0
private var iconSize = IconSize.medium
@IBOutlet weak var filterButton: UIBarButtonItem!
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem!
@IBOutlet weak var firstUnreadButton: UIBarButtonItem!
@ -87,7 +88,19 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
}
// MARK: Actions
@IBAction func toggleFilter(_ sender: Any) {
switch coordinator.articleReadFilter {
case .all:
filterButton.image = AppAssets.filterActiveImage
coordinator.hideUnreadArticles()
case .read:
filterButton.image = AppAssets.filterInactiveImage
coordinator.showAllArticles()
default:
break
}
}
@IBAction func markAllAsRead(_ sender: Any) {
if coordinator.displayUndoAvailableTip {
let alertController = UndoAvailableAlertController.alert { [weak self] _ in
@ -466,7 +479,6 @@ extension MasterTimelineViewController: UISearchBarDelegate {
private extension MasterTimelineViewController {
func resetUI() {
title = coordinator.timelineFeed?.nameForDisplay
if let titleView = Bundle.main.loadNibNamed("MasterTimelineTitleView", owner: self, options: nil)?[0] as? MasterTimelineTitleView {
self.titleView = titleView
@ -484,6 +496,16 @@ private extension MasterTimelineViewController {
navigationItem.titleView = titleView
}
switch coordinator.articleReadFilter {
case .all:
filterButton.isHidden = false
filterButton.image = AppAssets.filterInactiveImage
case .read:
filterButton.isHidden = false
filterButton.image = AppAssets.filterActiveImage
default:
filterButton.isHidden = true
}
tableView.selectRow(at: nil, animated: false, scrollPosition: .top)
if dataSource.snapshot().itemIdentifiers(inSection: 0).count > 0 {

View File

@ -116,6 +116,8 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
return treeControllerDelegate.isUnreadFiltered
}
var articleReadFilter: ReadFilter = .all
var rootNode: Node {
return treeController.rootNode
}
@ -469,6 +471,14 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
treeControllerDelegate.isUnreadFiltered = true
rebuildBackingStores()
}
func showAllArticles() {
articleReadFilter = .all
}
func hideUnreadArticles() {
articleReadFilter = .read
}
func expand(_ node: Node) {
node.isExpanded = true
@ -1129,6 +1139,7 @@ private extension SceneCoordinator {
func setTimelineFeed(_ feed: Feed?, completion: (() -> Void)? = nil) {
timelineFeed = feed
timelineMiddleIndexPath = nil
articleReadFilter = feed?.defaultReadFilter ?? .all
fetchAndReplaceArticlesAsync {
self.masterTimelineViewController?.reinitializeArticles()