marinofaggiana 4 سال پیش
والد
کامیت
f0bfa21a4c
3فایلهای تغییر یافته به همراه29 افزوده شده و 7 حذف شده
  1. 9 2
      iOSClient/Favorites/NCFavorite.swift
  2. 16 5
      iOSClient/Main/NCCollectionCommon.swift
  3. 4 0
      iOSClient/Main/NCDataSource.swift

+ 9 - 2
iOSClient/Favorites/NCFavorite.swift

@@ -93,6 +93,7 @@ class NCFavorite: NCCollectionViewCommon  {
     // MARK: - NC API & Algorithm
     
     override func reloadDataSource() {
+        super.reloadDataSource()
         
         var sort: String
         var ascending: Bool
@@ -116,7 +117,8 @@ class NCFavorite: NCCollectionViewCommon  {
     }
     
     override func reloadDataSourceNetwork() {
-     
+        super.reloadDataSourceNetwork()
+        
         if serverUrl == "" {
             
             NCNetworking.shared.listingFavoritescompletion(selector: selectorListingFavorite) { (account, metadatas, errorCode, errorDescription) in
@@ -154,10 +156,15 @@ class NCFavorite: NCCollectionViewCommon  {
     }
     
     override func searchDataSourceNetwork() {
+        super.searchDataSourceNetwork()
+        
+        guard let literalSearch = literalSearch else { return }
         if literalSearch == "" { return }
         
         NCNetworking.shared.searchFiles(urlBase: appDelegate.urlBase, user: appDelegate.user, literal: literalSearch) { (account, metadatas, errorCode, errorDescription) in
-            
+            if self.isSearching {
+                
+            }
         }
     }
 }

+ 16 - 5
iOSClient/Main/NCCollectionCommon.swift

@@ -653,8 +653,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     private let footerHeight: CGFloat = 50
     
     private var timerInputSearch: Timer?
-    internal var literalSearch: String = ""
-        
+    internal var literalSearch: String?
+    internal var isSearching: Bool = false
+    internal var isSearchingInProgress: Bool = false
+    
     internal let refreshControl = UIRefreshControl()
     
     // DECLARE
@@ -943,12 +945,21 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
         timerInputSearch?.invalidate()
         timerInputSearch = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(searchDataSourceNetwork), userInfo: nil, repeats: false)
+        literalSearch = searchController.searchBar.text
+    }
+    
+    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
         
-        literalSearch = searchController.searchBar.text ?? ""
+        dataSource = NCDataSource.init()
+        isSearching = true
+        collectionView.reloadData()
     }
     
-    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
+    func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
         
+        literalSearch = ""
+        isSearching = false
+        reloadDataSource()
     }
     
     // MARK: TAP EVENT
@@ -1042,7 +1053,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     // MARK: - NC API & Algorithm
     
     @objc func reloadDataSource() { }
-    @objc func reloadDataSourceNetwork() { }
+    @objc func reloadDataSourceNetwork() {}
     @objc func searchDataSourceNetwork() { }
 }
 

+ 4 - 0
iOSClient/Main/NCDataSource.swift

@@ -32,6 +32,10 @@ import Foundation
     private var directoryOnTop: Bool = true
     private var filterLivePhoto: Bool = true
     
+    override init() {
+        super.init()
+    }
+    
     @objc init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, directoryOnTop: Bool, filterLivePhoto: Bool) {
         super.init()