marinofaggiana 4 éve
szülő
commit
43bea8061b
1 módosított fájl, 65 hozzáadás és 46 törlés
  1. 65 46
      iOSClient/Transfers/NCTransfers.swift

+ 65 - 46
iOSClient/Transfers/NCTransfers.swift

@@ -85,15 +85,20 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-            
-                if let row = dataSource.addMetadata(metadata) {
-                    let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.performBatchUpdates({
-                        collectionView?.insertItems(at: [indexPath])
-                    }, completion: { (_) in
-                        self.reloadDataSource()
-                    })
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    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.reloadDataSource()
+                            })
+                        } else {
+                            reloadDataSource()
+                        }
+                    }
                 }
             }
         }
@@ -103,32 +108,41 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                
-                if errorCode == 0 {
-                    
-                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.deleteItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
-                    } else {
-                        reloadDataSource()
-                    }
-                    
-                } else if errorCode != NSURLErrorCancelled {
-                    
-                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.reloadItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
-                    } else {
-                        reloadDataSource()
+            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if  errorCode == 0 {
+                        
+                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                            let indexPath = IndexPath(row: row, section: 0)
+                            if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                                collectionView?.performBatchUpdates({
+                                    collectionView?.deleteItems(at: [indexPath])
+                                }, completion: { (_) in
+                                    self.collectionView?.reloadData()
+                                })
+                            } else {
+                                reloadDataSource()
+                            }
+                        } else {
+                            reloadDataSource()
+                        }
+                        
+                    } else if errorCode != NSURLErrorCancelled {
+                        
+                        if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
+                            let indexPath = IndexPath(row: row, section: 0)
+                            if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                                collectionView?.performBatchUpdates({
+                                    collectionView?.reloadItems(at: [indexPath])
+                                }, completion: { (_) in
+                                    self.collectionView?.reloadData()
+                                })
+                            } else {
+                                reloadDataSource()
+                            }
+                        } else {
+                            reloadDataSource()
+                        }
                     }
                 }
             }
@@ -139,17 +153,22 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-            
-                if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                    let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.performBatchUpdates({
-                        collectionView?.deleteItems(at: [indexPath])
-                    }, completion: { (_) in
-                        self.collectionView?.reloadData()
-                    })
-                } else {
-                    self.reloadDataSource()
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
+                            collectionView?.performBatchUpdates({
+                                collectionView?.deleteItems(at: [indexPath])
+                            }, completion: { (_) in
+                                self.collectionView?.reloadData()
+                            })
+                        } else {
+                            reloadDataSource()
+                        }
+                    } else {
+                        reloadDataSource()
+                    }
                 }
             }
         }