From 6f2dfcd80869abef4055853c7a78e70d86775dd4 Mon Sep 17 00:00:00 2001
From: lazarog98 <lazarog98@87-77-95-50.mna.fu-berlin.de>
Date: Tue, 25 Feb 2020 16:08:12 +0100
Subject: [PATCH] add delay duration variable and comments

---
 enzevalos_iphone/InboxViewController.swift | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/enzevalos_iphone/InboxViewController.swift b/enzevalos_iphone/InboxViewController.swift
index c9693df3..743d76b4 100644
--- a/enzevalos_iphone/InboxViewController.swift
+++ b/enzevalos_iphone/InboxViewController.swift
@@ -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?
 
     @IBOutlet weak var lastUpdateButton: UIBarButtonItem!
@@ -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
+    // TODO: Perhaps think of a better name
     func startSearch(searchText: String, scope: Int = 0) {
         if #available(iOS 10.0, *) {
             if let searchBarTimer: Timer = self.searchBarTimer {
                 searchBarTimer.invalidate()
             }
             
-            self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { _ in
-                self.filterContentForSearchText(searchText, scope: scope)
+            self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: searchDelay, repeats: false, block: { _ in
+                self._filterContentForSearchText(searchText, scope: scope)
             })
         }
     }
     
-    private func filterContentForSearchText(_ searchText: String, scope: Int = 0) {
+    private func _filterContentForSearchText(_ searchText: String, scope: Int = 0) {
         var records = [KeyRecord]()
         if scope == 0 || scope == 3 {
             records += folder.records.filter({ (record: KeyRecord) -> Bool in
-- 
GitLab