Update search results.

This commit is contained in:
Matthew Chen 2018-06-13 11:37:01 -04:00
parent e7fc9438c5
commit 91cc902b1d
3 changed files with 39 additions and 5 deletions

View file

@ -7,6 +7,15 @@ import Foundation
@objc
class ConversationSearchViewController: UITableViewController {
@objc
public var searchText = "" {
didSet {
SwiftAssertIsOnMainThread(#function)
updateSearchResults(searchText: searchText)
}
}
var searchResultSet: SearchResultSet = SearchResultSet.empty
var uiDatabaseConnection: YapDatabaseConnection {
@ -31,7 +40,7 @@ class ConversationSearchViewController: UITableViewController {
var blockedPhoneNumberSet = Set<String>()
// MARK: View Lifecyle
// MARK: View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
@ -45,6 +54,32 @@ class ConversationSearchViewController: UITableViewController {
tableView.register(EmptySearchResultCell.self, forCellReuseIdentifier: EmptySearchResultCell.reuseIdentifier)
tableView.register(HomeViewCell.self, forCellReuseIdentifier: HomeViewCell.cellReuseIdentifier())
tableView.register(ContactTableViewCell.self, forCellReuseIdentifier: ContactTableViewCell.reuseIdentifier())
NotificationCenter.default.addObserver(self,
selector: #selector(yapDatabaseModified),
name: NSNotification.Name.YapDatabaseModified,
object: OWSPrimaryStorage.shared().dbNotificationObject)
}
var refreshTimer: Timer?
@objc internal func yapDatabaseModified(notification: NSNotification) {
SwiftAssertIsOnMainThread(#function)
if refreshTimer != nil {
// Don't start a new refresh timer if there's already one active.
return
}
refreshTimer?.invalidate()
refreshTimer = WeakTimer.scheduledTimer(timeInterval: 1, target: self, userInfo: nil, repeats: false) { [weak self] _ in
guard let strongSelf = self else {
return
}
strongSelf.updateSearchResults(searchText: strongSelf.searchText)
strongSelf.refreshTimer = nil
}
}
// MARK: UITableViewDelegate
@ -235,8 +270,7 @@ class ConversationSearchViewController: UITableViewController {
// MARK: UISearchBarDelegate
@objc
public func updateSearchResults(searchText: String) {
private func updateSearchResults(searchText: String) {
guard searchText.stripped.count > 0 else {
self.searchResultSet = SearchResultSet.empty
self.tableView.reloadData()

View file

@ -910,7 +910,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
OWSAssertIsOnMainThread();
NSString *searchText = self.searchBar.text.ows_stripped;
[self.searchResultsController updateSearchResultsWithSearchText:searchText];
self.searchResultsController.searchText = searchText;
BOOL isSearching = searchText.length > 0;
self.searchResultsController.view.hidden = !isSearching;
}

View file

@ -239,7 +239,7 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc
return super.resignFirstResponder()
}
// MARK: View Lifecyle
// MARK: View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()