marinofaggiana 4 years ago
parent
commit
6cceef3112

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

@@ -358,7 +358,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
-                if (metadata.serverUrl == serverUrl && metadata.account == appDelegate.account) || (layoutKey == k_layout_view_transfers) {
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
                     
                     if let row = dataSource?.addMetadata(metadata) {
                         let indexPath = IndexPath(row: row, section: 0)
@@ -378,7 +378,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int {
-                if (metadata.serverUrl == serverUrl && metadata.account == appDelegate.account) || (layoutKey == k_layout_view_transfers) {
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
                    
                     dataSource?.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
                     collectionView?.reloadData()
@@ -392,7 +392,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
-                if (metadata.serverUrl == serverUrl && metadata.account == appDelegate.account) || (layoutKey == k_layout_view_transfers) {
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
                     
                     if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
                         let indexPath = IndexPath(row: row, section: 0)

+ 85 - 0
iOSClient/Transfers/NCTransfers.swift

@@ -42,6 +42,91 @@ class NCTransfers: NCCollectionViewCommon  {
         super.viewWillAppear(animated)
     }
     
+    // MARK: - NotificationCenter
+    
+    override func downloadStartFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        reloadDataSource()
+    }
+    
+    override func downloadedFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        reloadDataSource()
+    }
+    
+    override func downloadCancelFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        reloadDataSource()
+    }
+    
+    override func uploadStartFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let metadata = userInfo["metadata"] as? tableMetadata {
+
+                if let row = dataSource?.addMetadata(metadata) {
+                    let indexPath = IndexPath(row: row, section: 0)
+                    collectionView?.performBatchUpdates({
+                        collectionView?.insertItems(at: [indexPath])
+                    }, completion: { (_) in
+                        self.collectionView?.reloadData()
+                    })
+                }
+            }
+        }
+    }
+    
+    override func uploadedFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let metadata = userInfo["metadata"] as? tableMetadata, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int {
+                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 {
+                    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()
+                        })
+                    }
+                }
+            }
+        }
+    }
+    
+    override func uploadCancelFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let metadata = userInfo["metadata"] as? tableMetadata {
+                    
+                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()
+                }
+            }
+        }
+    }
+    
     // MARK: - Collection View
     
     override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {