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 animatingChanges = false
|
||||||
private var expandedNodes = [Node]()
|
private var expandedNodes = [Node]()
|
||||||
private var shadowTable = [[Node]]()
|
private var shadowTable = [[Node]]()
|
||||||
|
private var lastSearchString = ""
|
||||||
|
|
||||||
private(set) var sortDirection = AppDefaults.timelineSortDirection {
|
private(set) var sortDirection = AppDefaults.timelineSortDirection {
|
||||||
didSet {
|
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() {
|
func selectPrevArticle() {
|
||||||
if let indexPath = prevArticleIndexPath {
|
if let indexPath = prevArticleIndexPath {
|
||||||
selectArticle(indexPath)
|
selectArticle(indexPath)
|
||||||
|
|
|
@ -19,9 +19,11 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||||
@IBOutlet weak var firstUnreadButton: UIBarButtonItem!
|
@IBOutlet weak var firstUnreadButton: UIBarButtonItem!
|
||||||
|
|
||||||
private lazy var dataSource = makeDataSource()
|
private lazy var dataSource = makeDataSource()
|
||||||
|
private let searchController = UISearchController(searchResultsController: nil)
|
||||||
|
|
||||||
weak var coordinator: AppCoordinator!
|
weak var coordinator: AppCoordinator!
|
||||||
var undoableCommands = [UndoableCommand]()
|
var undoableCommands = [UndoableCommand]()
|
||||||
|
|
||||||
override var canBecomeFirstResponder: Bool {
|
override var canBecomeFirstResponder: Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -29,7 +31,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
|
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
tableView.dataSource = dataSource
|
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, 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(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, 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 = UIRefreshControl()
|
||||||
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
||||||
|
|
||||||
|
// Configure the table
|
||||||
|
tableView.dataSource = dataSource
|
||||||
numberOfTextLines = AppDefaults.timelineNumberOfLines
|
numberOfTextLines = AppDefaults.timelineNumberOfLines
|
||||||
resetEstimatedRowHeight()
|
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
|
// MARK: Private
|
||||||
|
|
||||||
private extension MasterTimelineViewController {
|
private extension MasterTimelineViewController {
|
||||||
|
|
Loading…
Reference in New Issue