marinofaggiana 4 жил өмнө
parent
commit
3186b39b93

+ 1 - 0
iOSClient/Data/NCDataSource.swift

@@ -198,6 +198,7 @@ class NCDataSource: NSObject {
         return index
     }
     
+    @discardableResult
     func addMetadata(_ metadata: tableMetadata) -> Int? {
         
         var index: Int = 0

+ 11 - 16
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -398,10 +398,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-               if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                   let indexPath = IndexPath(row: row, section: 0)
-                   collectionView?.reloadItems(at: [indexPath])
-               }
+                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                    let indexPath = IndexPath(row: row, section: 0)
+                    if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                        collectionView?.reloadItems(at: [indexPath])
+                    }
+                }
             }
         }
     }
@@ -413,7 +415,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
                 if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
                     let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.reloadItems(at: [indexPath])
+                    if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                        collectionView?.reloadItems(at: [indexPath])
+                    }
                 }
             }
         }
@@ -425,17 +429,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
                 if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                    
-                    if let row = dataSource.addMetadata(metadata) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
-                            collectionView?.performBatchUpdates({
-                                collectionView?.insertItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        }
-                    }
+                    dataSource.addMetadata(metadata)
+                    self.collectionView?.reloadData()
                 }
             }
         }

+ 5 - 2
iOSClient/Networking/NCNetworking.swift

@@ -293,8 +293,11 @@ import Queuer
             }
             
             self.downloadRequest[fileNameLocalPath] = nil
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["ocId":metadata.ocId, "selector":selector, "errorCode":errorCode, "errorDescription":errorDescription])
-            
+            if error?.isExplicitlyCancelledError ?? false {
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadCancelFile, userInfo: ["ocId":metadata.ocId])
+            } else {
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["ocId":metadata.ocId, "selector":selector, "errorCode":errorCode, "errorDescription":errorDescription])
+            }
             completion(errorCode)
         }
     }