Ver código fonte

VLCMediaCategoryViewController: Cosmetic: Put SearchDelegate into extension

Soomin Lee 6 anos atrás
pai
commit
e9613f96ea

+ 28 - 25
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -247,31 +247,6 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
         }
     }
 
-    // MARK: - Search
-    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
-        reloadData()
-        searchBar.setShowsCancelButton(true, animated: true)
-    }
-
-    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
-        searchBar.resignFirstResponder()
-        searchBar.text = ""
-        searchBar.setShowsCancelButton(false, animated: true)
-        reloadData()
-    }
-
-    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
-        searchBar.resignFirstResponder()
-    }
-
-    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
-        searchDataSource.shouldReloadFor(searchString: searchText)
-        reloadData()
-        if searchText.isEmpty {
-            self.searchBar.resignFirstResponder
-        }
-    }
-
     func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
         return IndicatorInfo(title:model.indicatorName)
     }
@@ -321,6 +296,34 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     }
 }
 
+// MARK: - UISearchBarDelegate
+
+extension VLCMediaCategoryViewController {
+    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
+        reloadData()
+        searchBar.setShowsCancelButton(true, animated: true)
+    }
+
+    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
+        searchBar.resignFirstResponder()
+        searchBar.text = ""
+        searchBar.setShowsCancelButton(false, animated: true)
+        reloadData()
+    }
+
+    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
+        searchBar.resignFirstResponder()
+    }
+
+    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
+        searchDataSource.shouldReloadFor(searchString: searchText)
+        reloadData()
+        if searchText.isEmpty {
+            self.searchBar.resignFirstResponder
+        }
+    }
+}
+
 // MARK: - UICollectionViewDelegateFlowLayout
 
 extension VLCMediaCategoryViewController {