Browse Source

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
f28ec63c65

+ 7 - 1
iOSClient/Data/NCDataSource.swift

@@ -49,7 +49,7 @@ class NCDataSource: NSObject {
     init(metadatasSource: [tableMetadata], account: String, sort: String? = "none", ascending: Bool? = false, directoryOnTop: Bool? = true, favoriteOnTop: Bool? = true, filterLivePhoto: Bool? = true, groupByField: String = "name", providers: [NCCSearchProvider]? = nil, searchResults: [NCCSearchResult]? = nil) {
         super.init()
 
-        self.metadatasSource = Array(metadatasSource.map { tableMetadata.init(value: $0) })
+        self.metadatasSource = metadatasSource
         self.shares = NCManageDatabase.shared.getTableShares(account: account)
         self.localFiles = NCManageDatabase.shared.getTableLocalFile(account: account)
         self.sort = sort ?? "none"
@@ -302,7 +302,13 @@ class NCDataSource: NSObject {
 
     func cellForItemAt(indexPath: IndexPath) -> tableMetadata? {
 
+        if metadatasForSection.count == 0 || indexPath.section >= metadatasForSection.count {
+            return nil
+        }
         let metadatasForSection = self.metadatasForSection[indexPath.section]
+        if indexPath.row >= metadatasForSection.metadatas.count {
+            return nil
+        }
         return metadatasForSection.metadatas[indexPath.row]
     }
 

+ 6 - 8
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1113,14 +1113,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 }
             } completion: { searchResults, metadatas, errorCode, errorDescription in
 
-                DispatchQueue.global().async {
-                    if self.isSearching, errorCode == 0, let metadatas = metadatas {
-                        self.searchResults = searchResults
-                        self.metadatasSource = metadatas
-                    }
-                    self.isReloadDataSourceNetworkInProgress = false
-                    self.reloadDataSource()
+                if self.isSearching, errorCode == 0, let metadatas = metadatas {
+                    self.searchResults = searchResults
+                    self.metadatasSource = metadatas
                 }
+                self.isReloadDataSourceNetworkInProgress = false
+                self.reloadDataSource()
             }
 
         } else {
@@ -1546,7 +1544,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             cell = gridCell
         }
 
-        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return UICollectionViewCell() }
+        guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return cell }
 
         let tableShare = dataSource.metadatasForSection[indexPath.section].metadataShare[metadata.ocId]
         var isShare = false