Эх сурвалжийг харах

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 жил өмнө
parent
commit
d55cd8cc44

+ 2 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1090,13 +1090,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                     searchResults: self.searchResults)
             } update: { id, searchResult, metadatas in
                 guard let metadatas = metadatas, metadatas.count > 0, self.isSearching , let searchResult = searchResult else { return }
-
-                NCOperationQueue.shared.dataSourceAddSection(dataSource: self.dataSource, metadatas: metadatas, searchResult: searchResult, collectionView: self.collectionView)
+                NCOperationQueue.shared.dataSourceAddSection(collectionViewCommon: self, metadatas: metadatas, searchResult: searchResult)
             } completion: {searchResults, errorCode, errorDescription in
-
                 self.searchResults = searchResults
                 self.refreshControl.endRefreshing()
                 self.isReloadDataSourceNetworkInProgress = false
+                self.collectionView.reloadData()
             }
 
         } else {

+ 14 - 14
iOSClient/Networking/NCOperationQueue.swift

@@ -199,8 +199,8 @@ import NCCommunication
     }
 
     // Datasource
-    func dataSourceAddSection(dataSource: NCDataSource, metadatas: [tableMetadata], searchResult: NCCSearchResult, collectionView: UICollectionView) {
-        dataSourceQueue.addOperation(NCOperationDataSource.init(dataSource: dataSource, metadatas: metadatas, searchResult: searchResult, collectionView: collectionView))
+    func dataSourceAddSection(collectionViewCommon: NCCollectionViewCommon, metadatas: [tableMetadata], searchResult: NCCSearchResult) {
+        dataSourceQueue.addOperation(NCOperationDataSource.init(collectionViewCommon: collectionViewCommon, metadatas: metadatas, searchResult: searchResult))
     }
 }
 
@@ -534,25 +534,21 @@ class NCOperationDownloadAvatar: ConcurrentOperation {
 
 class NCOperationDataSource: ConcurrentOperation {
 
-    var dataSource: NCDataSource
+    var collectionViewCommon: NCCollectionViewCommon
     var metadatas: [tableMetadata]
     var searchResult: NCCSearchResult
-    var collectionView: UICollectionView
 
-    init(dataSource:NCDataSource, metadatas: [tableMetadata], searchResult: NCCSearchResult, collectionView: UICollectionView) {
-        self.dataSource = dataSource
+    init(collectionViewCommon: NCCollectionViewCommon, metadatas: [tableMetadata], searchResult: NCCSearchResult) {
+        self.collectionViewCommon = collectionViewCommon
         self.metadatas = metadatas
         self.searchResult = searchResult
-        self.collectionView = collectionView
     }
 
     func reloadDataThenPerform(_ closure: @escaping (() -> Void)) {
-        DispatchQueue.main.async {
-            CATransaction.begin()
-            CATransaction.setCompletionBlock(closure)
-            self.collectionView.reloadData()
-            CATransaction.commit()
-        }
+        CATransaction.begin()
+        CATransaction.setCompletionBlock(closure)
+        self.collectionViewCommon.collectionView.reloadData()
+        CATransaction.commit()
     }
 
     override func start() {
@@ -560,7 +556,11 @@ class NCOperationDataSource: ConcurrentOperation {
         if isCancelled {
             self.finish()
         } else {
-            self.dataSource.addSection(metadatas: metadatas, searchResult: searchResult)
+            self.collectionViewCommon.dataSource.addSection(metadatas: metadatas, searchResult: searchResult)
+            for metadata in self.metadatas {
+                self.collectionViewCommon.metadatasSource.append(metadata)
+            }
+            self.collectionViewCommon.searchResults?.append(self.searchResult)
             reloadDataThenPerform {
                 self.finish()
             }