marinofaggiana 4 years ago
parent
commit
349cf8a08a

+ 2 - 2
iOSClient/CCGlobal.h

@@ -318,9 +318,9 @@
 #define k_notificationCenter_reloadDataSource           @"reloadDataSource"                 // userInfo: ocId?, serverUrl?
 #define k_notificationCenter_reloadMediaDataSource      @"reloadMediaDataSource"
 
-#define k_notificationCenter_uploadFileStart            @"uploadFileStart"                  // userInfo: ocId, task, serverUrl, account
+#define k_notificationCenter_uploadFileStart            @"uploadFileStart"                  // userInfo: metadata, task, serverUrl, account
 #define k_notificationCenter_uploadedFile               @"uploadedFile"                     // userInfo: metadata, errorCode, errorDescription
-#define k_notificationCenter_downloadFileStart          @"downloadFileStart"                // userInfo: ocId, serverUrl, account
+#define k_notificationCenter_downloadFileStart          @"downloadFileStart"                // userInfo: metadata, serverUrl, account
 #define k_notificationCenter_downloadedFile             @"downloadedFile"                   // userInfo: metadata, selector, errorCode, errorDescription
 #define k_notificationCenter_progressTask               @"progressTask"                     // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
 #define k_notificationCenter_createFolder               @"createFolder"                     // userInfo: fileName, serverUrl, errorCode, errorDescription

+ 28 - 0
iOSClient/Favorites/NCFavorite.swift

@@ -91,6 +91,8 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_deleteFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource), name: NSNotification.Name(rawValue: k_notificationCenter_reloadDataSource), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_downloadedFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_uploadedFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(uploadFileStart(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_uploadFileStart), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_progressTask), object:nil)
 
         changeTheming()
@@ -165,6 +167,32 @@ class NCFavorite: UIViewController, UIGestureRecognizerDelegate, NCListCellDeleg
         }
     }
     
+    @objc 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 errorCode = userInfo["errorCode"] as? Int {
+                if errorCode == 0 {
+                    self.dataSource?.reloadMetadata(ocId: metadata.ocId)
+                    collectionView.reloadData()
+                }
+            }
+        }
+    }
+    
+    @objc func uploadFileStart(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
+        
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let metadata = userInfo["metadata"] as? tableMetadata , let serverUrl = userInfo["serverUrl"] as? String{
+                if serverUrl == self.serverUrl {
+                    self.dataSource?.addMetadata(metadata)
+                    collectionView.reloadData()
+                }
+            }
+        }
+    }
+    
     @objc func triggerProgressTask(_ notification: NSNotification) {
         if self.view?.window == nil { return }
         

+ 6 - 1
iOSClient/Main/NCDataSource.swift

@@ -152,11 +152,16 @@ import Foundation
     
     @objc func addMetadata(_ metadata: tableMetadata) {
         
+        for metadataCount in metadatas {
+            if metadataCount.ocId == metadata.ocId {
+                return
+            }
+        }
+        
         self.metadatas.append(metadata)
         createMetadatas(metadatasSource: metadatas)
     }
     
-    
     func getIndexMetadata(ocId: String) -> Int? {
         
         var index: Int = 0

+ 2 - 2
iOSClient/Networking/NCNetworking.swift

@@ -248,7 +248,7 @@ import Queuer
             self.downloadRequest[fileNameLocalPath] = request
             
             NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, status: Int(k_metadataStatusDownloading))
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadFileStart, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl, "account":metadata.account])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadFileStart, userInfo: ["metadata":metadata, "serverUrl":metadata.serverUrl, "account":metadata.account])
             
         }, progressHandler: { (progress) in
             
@@ -409,7 +409,7 @@ import Queuer
             CCGraphics.createNewImage(from: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, typeFile: metadata.typeFile)
             #endif
             
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadFileStart, userInfo: ["ocId":metadata.ocId, "task":task, "serverUrl":metadata.serverUrl, "account":metadata.account])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadFileStart, userInfo: ["metadata":metadata, "task":task, "serverUrl":metadata.serverUrl, "account":metadata.account])
             NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
             
             completion(0, "")

+ 1 - 1
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -232,7 +232,7 @@ import Alamofire
                     NCNetworking.shared.uploadRequest[fileNameLocalPath] = request
                     NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: nil, sessionSelector: nil, sessionTaskIdentifier: nil, status: Int(k_metadataStatusUploading))
                     
-                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadFileStart, userInfo: ["ocId":metadata.ocId, "serverUrl":serverUrl, "account": metadata.account])
+                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadFileStart, userInfo: ["metadata":metadata, "serverUrl":serverUrl, "account": metadata.account])
                     
                 }, progressHandler: { (progress) in
                     

+ 0 - 8
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -42,10 +42,6 @@ import Foundation
     //MARK: - Download
 
     @objc func downloadFileStart(_ notification: NSNotification) {
-        
-//        if let userInfo = notification.userInfo as NSDictionary? {
-//            if let ocId = userInfo["ocId"] as? String, let serverUrl = userInfo["serverUrl"] as? String { }
-//        }
     }
     
     @objc func downloadedFile(_ notification: NSNotification) {
@@ -142,10 +138,6 @@ import Foundation
     //MARK: - Upload
 
     @objc func uploadFileStart(_ notification: NSNotification) {
-        
-//        if let userInfo = notification.userInfo as NSDictionary? {
-//            if let ocId = userInfo["ocId"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let _ = userInfo["task"] as? URLSessionUploadTask { }
-//        }
     }
     
     @objc func uploadedFile(_ notification: NSNotification) {