Prechádzať zdrojové kódy

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 rokov pred
rodič
commit
c045b10e88

+ 13 - 17
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -902,11 +902,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             NCNetworking.shared.unifiedSearchFilesProvider(urlBase: appDelegate, id: searchResult.id, term: term, limit: 5, cursor: cursor) { searchResult, metadatas, errorCode, ErrorDescription in
 
                 metadataForSection.unifiedSearchInProgress = false
-                self.collectionView?.reloadData()
-
-                guard let searchResult = searchResult, let metadatas = metadatas else {
-                    return
-                }
+                guard let searchResult = searchResult, let metadatas = metadatas else { return }
                 metadataForSection.searchResult = searchResult
                 var indexPaths: [IndexPath] = []
                 for metadata in metadatas {
@@ -916,11 +912,13 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                         indexPaths.append(indexPath)
                     }
                 }
-                self.collectionView?.performBatchUpdates({
-                    self.collectionView?.insertItems(at: indexPaths)
-                }, completion: { _ in
-                    self.collectionView?.reloadData()
-                })
+                DispatchQueue.main.async {
+                    self.collectionView?.performBatchUpdates({
+                        self.collectionView?.insertItems(at: indexPaths)
+                    }, completion: { _ in
+                        self.collectionView?.reloadData()
+                    })
+                }
             }
         }
     }
@@ -1062,19 +1060,19 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     @objc func networkSearch() {
         guard !appDelegate.account.isEmpty, let literalSearch = literalSearch, !literalSearch.isEmpty
         else {
-            DispatchQueue.main.async { self.refreshControl.endRefreshing() }
+            self.refreshControl.endRefreshing()
             return
         }
 
         isReloadDataSourceNetworkInProgress = true
         self.metadatasSource.removeAll()
         self.dataSource.clearDataSource()
-        collectionView?.reloadData()
-        
+        self.refreshControl.beginRefreshing()
+        self.collectionView.reloadData()
+
         let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
-        
         if serverVersionMajor >= NCGlobal.shared.nextcloudVersion20 {
-            self.refreshControl.beginRefreshing()
+
             NCNetworking.shared.unifiedSearchFiles(urlBase: appDelegate, literal: literalSearch) { allProviders in
                 self.providers = allProviders
             } update: { searchResults, metadatas in
@@ -1103,7 +1101,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     self.searchResults = searchResults
                     self.metadatasSource = metadatas
                 }
-                self.refreshControl.endRefreshing()
                 self.isReloadDataSourceNetworkInProgress = false
                 self.reloadDataSource()
             }
@@ -1117,7 +1114,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     self.searchResults = nil
                     self.metadatasSource = metadatas
                 }
-
                 self.isReloadDataSourceNetworkInProgress = false
                 self.reloadDataSource()
             }

+ 2 - 6
iOSClient/Networking/NCNetworking.swift

@@ -1023,9 +1023,7 @@ import Queuer
 
         let request = NCCommunication.shared.searchProvider(id, term: term, limit: limit, cursor: cursor, timeout: 60) { searchResult, errorCode, errorDescription in
             guard let searchResult = searchResult else {
-                DispatchQueue.main.async {
-                    completion(nil, metadatas, errorCode, errorDescription)
-                }
+                completion(nil, metadatas, errorCode, errorDescription)
                 return
             }
 
@@ -1062,9 +1060,7 @@ import Queuer
                 })
             }
 
-            DispatchQueue.main.async {
-                completion(searchResult, metadatas, errorCode, errorDescription)
-            }
+            completion(searchResult, metadatas, errorCode, errorDescription)
         }
         if let request = request {
             requestsUnifiedSearch.append(request)