marinofaggiana пре 4 година
родитељ
комит
8c71845a65

+ 1 - 72
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -223,7 +223,7 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc") ) { action in
             self.appDelegate.pasteboardOcIds = [metadata.ocId]
-            self.copyPasteboard()
+            NCNetworkingNotificationCenter.shared.copyPasteboard()
         }
         
         let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info") ) { action in
@@ -301,77 +301,6 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         
         return UIMenu(title: "", image: nil, identifier: nil, children: children)
     }
-    
-    // MARK: - Copy & Paste
-
-    func copyPasteboard() {
-        
-        var metadatas: [tableMetadata] = []
-        var items = [[String : Any]]()
-        
-        for ocId in appDelegate.pasteboardOcIds {
-            if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-                metadatas.append(metadata)
-            }
-        }
-        
-        for metadata in metadatas {
-            
-            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-                do {
-                    // Get Data
-                    let data = try Data.init(contentsOf: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
-                    // Pasteboard item
-                    if let unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (metadata.fileNameView as NSString).pathExtension as CFString, nil) {
-                        let fileUTI = unmanagedFileUTI.takeRetainedValue() as String
-                        items.append([fileUTI:data])
-                    }
-                } catch {
-                    print("error")
-                }
-            } else {
-                NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { (_) in }
-            }
-        }
-        
-        UIPasteboard.general.setItems(items, options: [:])
-    }
-
-    func pastePasteboard(serverUrl: String) {
-                
-        for (index, items) in UIPasteboard.general.items.enumerated() {
-            for item in items {
-                let pasteboardType = item.key
-                if let data = UIPasteboard.general.data(forPasteboardType: pasteboardType, inItemSet: IndexSet([index]))?.first {
-                    let results = NCCommunicationCommon.shared.getDescriptionFile(inUTI: pasteboardType as CFString)
-                    if results.resultTypeFile != NCCommunicationCommon.typeFile.unknow.rawValue {
-                        uploadPasteFile(fileName: results.resultFilename, ext: results.resultExtension, contentType: pasteboardType, serverUrl: serverUrl, data: data)
-                    }
-                }
-            }
-        }
-    }
-
-    private func uploadPasteFile(fileName: String, ext: String, contentType: String, serverUrl: String, data: Data) {
-        
-        do {
-            let fileNameView = fileName + "_" + CCUtility.getIncrementalNumber() + "." + ext
-            let ocId = UUID().uuidString
-            let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
-            
-            try data.write(to: URL(fileURLWithPath: filePath))
-           
-            let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, fileName: fileNameView, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: contentType, livePhoto: false)
-            
-            metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
-            metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
-            metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath)
-            metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
-            
-            NCManageDatabase.shared.addMetadata(metadataForUpload)
-            
-        } catch { }
-    }
 }
 
 

+ 1 - 1
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -775,7 +775,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     }
     
     @objc func pasteFilesMenu() {
-        NCCollectionCommon.shared.pastePasteboard(serverUrl: serverUrl)
+        NCNetworkingNotificationCenter.shared.pastePasteboard(serverUrl: serverUrl)
     }
     
     // MARK: - DataSource + NC Endpoint

+ 2 - 2
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -264,7 +264,7 @@ extension NCCollectionViewCommon {
                     icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                     action: { menuAction in
                         self.appDelegate.pasteboardOcIds = [metadata.ocId];
-                        NCCollectionCommon.shared.copyPasteboard()
+                        NCNetworkingNotificationCenter.shared.copyPasteboard()
                     }
                 )
             )
@@ -447,7 +447,7 @@ extension NCCollectionViewCommon {
                     for ocId in selectOcId {
                         self.appDelegate.pasteboardOcIds.append(ocId)
                     }
-                    NCCollectionCommon.shared.copyPasteboard()
+                    NCNetworkingNotificationCenter.shared.copyPasteboard()
                     self.tapSelect(sender: self)
                 }
             )

+ 1 - 1
iOSClient/Menu/NCViewer+Menu.swift

@@ -231,7 +231,7 @@ extension NCViewer {
                 icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                 action: { menuAction in
                     self.appDelegate.pasteboardOcIds = [metadata.ocId];
-                    NCCollectionCommon.shared.copyPasteboard()
+                    NCNetworkingNotificationCenter.shared.copyPasteboard()
                 }
             )
         )

+ 82 - 11
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -22,6 +22,7 @@
 //
 
 import Foundation
+import NCCommunication
 
 @objc class NCNetworkingNotificationCenter: NSObject, UIDocumentInteractionControllerDelegate {
     @objc public static let shared: NCNetworkingNotificationCenter = {
@@ -102,7 +103,7 @@ import Foundation
                         
                     case NCGlobal.shared.selectorLoadCopy:
                         
-                        NCCollectionCommon.shared.copyPasteboard()
+                        copyPasteboard()
                         
                     case NCGlobal.shared.selectorLoadOffline:
                         
@@ -160,6 +161,24 @@ import Foundation
         }
     }
     
+    //MARK: - Upload
+
+    @objc func uploadedFile(_ notification: NSNotification) {
+    
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+                
+                if metadata.account == appDelegate.account {
+                    if errorCode != 0 {
+                        if errorCode != -999 && errorCode != 401 && errorDescription != "" {
+                            NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
     // MARK: -
 
     func openShare(ViewController: UIViewController, metadata: tableMetadata, indexPage: Int) {
@@ -280,22 +299,74 @@ import Foundation
             }
         })
     }
-    //MARK: - Upload
-
-    @objc func uploadedFile(_ notification: NSNotification) {
     
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+    func copyPasteboard() {
+        
+        var metadatas: [tableMetadata] = []
+        var items = [[String : Any]]()
+        
+        for ocId in appDelegate.pasteboardOcIds {
+            if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+                metadatas.append(metadata)
+            }
+        }
+        
+        for metadata in metadatas {
+            
+            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                do {
+                    // Get Data
+                    let data = try Data.init(contentsOf: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
+                    // Pasteboard item
+                    if let unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (metadata.fileNameView as NSString).pathExtension as CFString, nil) {
+                        let fileUTI = unmanagedFileUTI.takeRetainedValue() as String
+                        items.append([fileUTI:data])
+                    }
+                } catch {
+                    print("error")
+                }
+            } else {
+                NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { (_) in }
+            }
+        }
+        
+        UIPasteboard.general.setItems(items, options: [:])
+    }
+
+    func pastePasteboard(serverUrl: String) {
                 
-                if metadata.account == appDelegate.account {
-                    if errorCode != 0 {
-                        if errorCode != -999 && errorCode != 401 && errorDescription != "" {
-                            NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                        }
+        for (index, items) in UIPasteboard.general.items.enumerated() {
+            for item in items {
+                let pasteboardType = item.key
+                if let data = UIPasteboard.general.data(forPasteboardType: pasteboardType, inItemSet: IndexSet([index]))?.first {
+                    let results = NCCommunicationCommon.shared.getDescriptionFile(inUTI: pasteboardType as CFString)
+                    if results.resultTypeFile != NCCommunicationCommon.typeFile.unknow.rawValue {
+                        uploadPasteFile(fileName: results.resultFilename, ext: results.resultExtension, contentType: pasteboardType, serverUrl: serverUrl, data: data)
                     }
                 }
             }
         }
     }
+
+    private func uploadPasteFile(fileName: String, ext: String, contentType: String, serverUrl: String, data: Data) {
+        
+        do {
+            let fileNameView = fileName + "_" + CCUtility.getIncrementalNumber() + "." + ext
+            let ocId = UUID().uuidString
+            let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
+            
+            try data.write(to: URL(fileURLWithPath: filePath))
+           
+            let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, fileName: fileNameView, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: contentType, livePhoto: false)
+            
+            metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
+            metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
+            metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath)
+            metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
+            
+            NCManageDatabase.shared.addMetadata(metadataForUpload)
+            
+        } catch { }
+    }
 }