mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 14:33:04 +01:00
Implement full article search
This commit is contained in:
parent
061dfe931b
commit
d9ce01591f
@ -48,6 +48,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
private var animatingChanges = false
|
||||
private var expandedNodes = [Node]()
|
||||
private var shadowTable = [[Node]]()
|
||||
private var lastSearchString = ""
|
||||
|
||||
private(set) var sortDirection = AppDefaults.timelineSortDirection {
|
||||
didSet {
|
||||
@ -503,6 +504,21 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||
}
|
||||
}
|
||||
|
||||
func searchArticles(_ searchString: String) {
|
||||
guard !searchString.isEmpty else {
|
||||
if let ip = currentMasterIndexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher {
|
||||
timelineFetcher = fetcher
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if searchString != lastSearchString {
|
||||
timelineFetcher = SmartFeed(delegate: SearchFeedDelegate(searchString: searchString))
|
||||
lastSearchString = searchString
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func selectPrevArticle() {
|
||||
if let indexPath = prevArticleIndexPath {
|
||||
selectArticle(indexPath)
|
||||
|
@ -19,9 +19,11 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
@IBOutlet weak var firstUnreadButton: UIBarButtonItem!
|
||||
|
||||
private lazy var dataSource = makeDataSource()
|
||||
private let searchController = UISearchController(searchResultsController: nil)
|
||||
|
||||
weak var coordinator: AppCoordinator!
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
|
||||
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
return true
|
||||
}
|
||||
@ -29,7 +31,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
override func viewDidLoad() {
|
||||
|
||||
super.viewDidLoad()
|
||||
tableView.dataSource = dataSource
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||
@ -40,9 +41,19 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
||||
|
||||
// Setup the Search Controller
|
||||
searchController.searchResultsUpdater = self
|
||||
searchController.obscuresBackgroundDuringPresentation = false
|
||||
searchController.searchBar.placeholder = NSLocalizedString("Search Articles", comment: "Search Articles")
|
||||
navigationItem.searchController = searchController
|
||||
definesPresentationContext = true
|
||||
|
||||
// Setup the Refresh Control
|
||||
refreshControl = UIRefreshControl()
|
||||
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
||||
|
||||
// Configure the table
|
||||
tableView.dataSource = dataSource
|
||||
numberOfTextLines = AppDefaults.timelineNumberOfLines
|
||||
resetEstimatedRowHeight()
|
||||
|
||||
@ -392,6 +403,14 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||
|
||||
}
|
||||
|
||||
// MARK: UISearchResultsUpdating
|
||||
|
||||
extension MasterTimelineViewController: UISearchResultsUpdating {
|
||||
func updateSearchResults(for searchController: UISearchController) {
|
||||
coordinator.searchArticles(searchController.searchBar.text!)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private extension MasterTimelineViewController {
|
||||
|
Loading…
Reference in New Issue
Block a user