mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 13:59:04 -04:00
commit
This commit is contained in:
parent
0399f1b858
commit
29dfe133c9
@ -13,13 +13,16 @@ import DZNEmptyDataSet
|
|||||||
class SearchResultController: SearchBaseTableController, UITableViewDataSource, UITableViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
class SearchResultController: SearchBaseTableController, UITableViewDataSource, UITableViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||||
|
|
||||||
private var searchResults = [SearchResult]()
|
private var searchResults = [SearchResult]()
|
||||||
|
private var searchText = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Controls if empty table background should be displayed
|
Controls if empty table background should be displayed
|
||||||
- When search text is empty, shouldShowNoResults = false
|
- When search text is empty, shouldShowNoResults = false
|
||||||
- When search text is **not** empty, shouldShowNoResults = true
|
- When search text is **not** empty, shouldShowNoResults = true
|
||||||
*/
|
*/
|
||||||
private var shouldShowNoResults = false
|
private var shouldShowNoResults: Bool {
|
||||||
|
return searchText != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
@ -31,7 +34,7 @@ class SearchResultController: SearchBaseTableController, UITableViewDataSource,
|
|||||||
tableView.emptyDataSetDelegate = self
|
tableView.emptyDataSetDelegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectFirstResultIfPossible() {
|
func selectFirstResult() {
|
||||||
guard searchResults.count > 0 else {return}
|
guard searchResults.count > 0 else {return}
|
||||||
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: .top)
|
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: .top)
|
||||||
tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0))
|
tableView(tableView, didSelectRowAt: IndexPath(row: 0, section: 0))
|
||||||
@ -43,7 +46,7 @@ class SearchResultController: SearchBaseTableController, UITableViewDataSource,
|
|||||||
- Parameter results: An array of search result to be displayed
|
- Parameter results: An array of search result to be displayed
|
||||||
*/
|
*/
|
||||||
func reload(searchText: String, results: [SearchResult]) {
|
func reload(searchText: String, results: [SearchResult]) {
|
||||||
shouldShowNoResults = searchText != ""
|
self.searchText = searchText
|
||||||
searchResults = results
|
searchResults = results
|
||||||
|
|
||||||
tableView.tableFooterView = searchResults.count > 0 ? nil : UIView()
|
tableView.tableFooterView = searchResults.count > 0 ? nil : UIView()
|
||||||
@ -97,6 +100,7 @@ class SearchResultController: SearchBaseTableController, UITableViewDataSource,
|
|||||||
let result = searchResults[indexPath.row]
|
let result = searchResults[indexPath.row]
|
||||||
let operation = ArticleLoadOperation(bookID: result.bookID, articleTitle: result.title)
|
let operation = ArticleLoadOperation(bookID: result.bookID, articleTitle: result.title)
|
||||||
GlobalQueue.shared.add(articleLoadOperation: operation)
|
GlobalQueue.shared.add(articleLoadOperation: operation)
|
||||||
|
Preference.RecentSearch.add(term: searchText)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - DZNEmptyDataSet
|
// MARK: - DZNEmptyDataSet
|
||||||
|
Loading…
x
Reference in New Issue
Block a user