Skip to content
Snippets Groups Projects
Commit 6f2dfcd8 authored by lazarog98's avatar lazarog98
Browse files

add delay duration variable and comments

parent 6c7af886
No related branches found
No related tags found
1 merge request!27Resolve "Improve searching"
...@@ -39,6 +39,10 @@ class InboxViewController: UITableViewController, InboxCellDelegator { ...@@ -39,6 +39,10 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
} }
} }
} }
// how many seconds should the app wait before processing search bar input
var searchDelay = 0.5
// holds the currently active search timer (if it exists) so it can be terminated if a new character is typed before the execution
var searchBarTimer: Timer? var searchBarTimer: Timer?
@IBOutlet weak var lastUpdateButton: UIBarButtonItem! @IBOutlet weak var lastUpdateButton: UIBarButtonItem!
...@@ -250,19 +254,20 @@ class InboxViewController: UITableViewController, InboxCellDelegator { ...@@ -250,19 +254,20 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
} }
/// searches a given string with a delay so that the entire client doesn't lag if the inbox is very big /// searches a given string with a delay so that the entire client doesn't lag if the inbox is very big
// TODO: Perhaps think of a better name
func startSearch(searchText: String, scope: Int = 0) { func startSearch(searchText: String, scope: Int = 0) {
if #available(iOS 10.0, *) { if #available(iOS 10.0, *) {
if let searchBarTimer: Timer = self.searchBarTimer { if let searchBarTimer: Timer = self.searchBarTimer {
searchBarTimer.invalidate() searchBarTimer.invalidate()
} }
self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { _ in self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: searchDelay, repeats: false, block: { _ in
self.filterContentForSearchText(searchText, scope: scope) self._filterContentForSearchText(searchText, scope: scope)
}) })
} }
} }
private func filterContentForSearchText(_ searchText: String, scope: Int = 0) { private func _filterContentForSearchText(_ searchText: String, scope: Int = 0) {
var records = [KeyRecord]() var records = [KeyRecord]()
if scope == 0 || scope == 3 { if scope == 0 || scope == 3 {
records += folder.records.filter({ (record: KeyRecord) -> Bool in records += folder.records.filter({ (record: KeyRecord) -> Bool in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment