marinofaggiana 4 жил өмнө
parent
commit
ada01f7309

+ 2 - 6
iOSClient/Media/NCMedia.swift

@@ -415,9 +415,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
                     collectionView?.reloadData()
                 } else if let row = indexes.first {
                     let indexPath = IndexPath(row: row, section: 0)
-                    if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
-                        collectionView?.deleteItems(at: [indexPath])
-                    }
+                    collectionView?.deleteItems(at: [indexPath])
                 }
                 
                 self.updateMediaControlVisibility()
@@ -441,9 +439,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
                         collectionView?.reloadData()
                     } else if let row = indexes.first {
                         let indexPath = IndexPath(row: row, section: 0)
-                        if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
-                            collectionView?.deleteItems(at: [indexPath])
-                        }
+                        collectionView?.deleteItems(at: [indexPath])
                     }
                     
                     self.updateMediaControlVisibility()

+ 46 - 65
iOSClient/Transfers/NCTransfers.swift

@@ -85,20 +85,15 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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()
-                        }
-                    }
+            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()
+                    })
                 }
             }
         }
@@ -108,41 +103,32 @@ 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 {
-                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()
-                        }
+            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()
                     }
                 }
             }
@@ -153,22 +139,17 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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()
-                    }
+            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()
                 }
             }
         }