marinofaggiana %!s(int64=4) %!d(string=hai) anos
pai
achega
53db655baa

+ 112 - 0
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -207,8 +207,120 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         
         appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
     }
+    
+    // MARK: - Copy & Paste
+
+    func copyFile(ocIds: [String]) {
+        var metadatas: [tableMetadata] = []
+        var items = [[String : Any]]()
+
+        
+        for ocId in ocIds {
+            if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+                metadatas.append(metadata)
+            }
+        }
+        
+        for metadata in metadatas {
+            
+            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                do {
+                    let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
+                    items.append([NCBrandGlobal.shared.metadataKeyedUnarchiver:etagPasteboard])
+                } catch {
+                    print("error")
+                }
+            } else {
+                NCNetworking.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorLoadCopy, setFavorite: false) { (_) in }
+            }
+        }
+        
+        UIPasteboard.general.setItems(items, options: [:])
+    }
+
+    func pasteFiles(serverUrl: String) {
+        
+        var listData: [String] = []
+        
+        for item in UIPasteboard.general.items {
+            for object in item {
+                let contentType = object.key
+                let data = object.value
+                if contentType == NCBrandGlobal.shared.metadataKeyedUnarchiver {
+                    do {
+                        if let ocId = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data as! Data) as? String{
+                            uploadPasteOcId(ocId, serverUrl: serverUrl)
+                        }
+                    } catch {
+                        print("error")
+                    }
+                    continue
+                }
+                if data is String {
+                    if listData.contains(data as! String) {
+                        continue
+                    } else {
+                        listData.append(data as! String)
+                    }
+                }
+                let type = NCCommunicationCommon.shared.convertUTItoResultType(fileUTI: contentType as CFString)
+                if type.resultTypeFile != NCCommunicationCommon.typeFile.unknow.rawValue && type.resultExtension != "" {
+                    uploadPasteFile(fileName: type.resultFilename, ext: type.resultExtension, contentType: contentType, serverUrl: serverUrl, data: data)
+                }
+            }
+        }
+    }
+
+    private func uploadPasteFile(fileName: String, ext: String, contentType: String, serverUrl: String, data: Any) {
+        do {
+            let fileNameView = fileName + "_" + CCUtility.getIncrementalNumber() + "." + ext
+            let ocId = UUID().uuidString
+            let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
+            
+            if data is UIImage {
+                try (data as? UIImage)?.jpegData(compressionQuality: 1)?.write(to: URL(fileURLWithPath: filePath))
+            } else if data is Data {
+                try (data as? Data)?.write(to: URL(fileURLWithPath: filePath))
+            } else if data is String {
+                try (data as? String)?.write(to: URL(fileURLWithPath: filePath), atomically: true, encoding: .utf8)
+            } else {
+                return
+            }
+            
+            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 = NCBrandGlobal.shared.selectorUploadFile
+            metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath)
+            metadataForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload
+            
+            NCManageDatabase.shared.addMetadata(metadataForUpload)
+            
+        } catch { }
+    }
+
+    private func uploadPasteOcId(_ ocId: String, serverUrl: String) {
+        if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                let fileNameView = NCUtilityFileSystem.shared.createFileName(metadata.fileNameView, serverUrl: serverUrl, account: appDelegate.account)
+                let ocId = NSUUID().uuidString
+                
+                CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView))
+                let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, fileName: fileNameView, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "", livePhoto: false)
+                
+                metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
+                metadataForUpload.sessionSelector = NCBrandGlobal.shared.selectorUploadFile
+                metadataForUpload.size = metadata.size
+                metadataForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload
+                
+                NCManageDatabase.shared.addMetadata(metadataForUpload)
+            }
+        }
+    }
+
 }
 
+
 // MARK: - List Layout
 
 class NCListLayout: UICollectionViewFlowLayout {

+ 2 - 134
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -746,140 +746,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         return false
     }
     
-    @objc func copyFileMenu() {
-        var metadatas: [tableMetadata] = []
-        var items = [[String : Any]]()
-
-        if isEditMode {
-            for ocId in selectOcId {
-                if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-                    metadatas.append(metadata)
-                }
-            }
-        } else {
-            guard let metadata = metadataTouch else { return }
-            metadatas.append(metadata)
-        }
-                
-        for metadata in metadatas {
-            
-            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-                do {
-                    let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
-                    items.append([NCBrandGlobal.shared.metadataKeyedUnarchiver:etagPasteboard])
-                } catch {
-                    print("error")
-                }
-            } else {
-                NCNetworking.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorLoadCopy, setFavorite: false) { (_) in }
-            }
-        }
-        
-        UIPasteboard.general.setItems(items, options: [:])
-        
-        if isEditMode {
-            tapSelect(sender: self)
-        }
-    }
-    
     @objc func pasteFilesMenu() {
-        
-        var listData: [String] = []
-        
-        for item in UIPasteboard.general.items {
-            for object in item {
-                let contentType = object.key
-                let data = object.value
-                if contentType == NCBrandGlobal.shared.metadataKeyedUnarchiver {
-                    do {
-                        if let ocId = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data as! Data) as? String{
-                            uploadPasteOcId(ocId)
-                        }
-                    } catch {
-                        print("error")
-                    }
-                    continue
-                }
-                if data is String {
-                    if listData.contains(data as! String) {
-                        continue
-                    } else {
-                        listData.append(data as! String)
-                    }
-                }
-                let type = NCCommunicationCommon.shared.convertUTItoResultType(fileUTI: contentType as CFString)
-                if type.resultTypeFile != NCCommunicationCommon.typeFile.unknow.rawValue && type.resultExtension != "" {
-                    uploadPasteFile(fileName: type.resultFilename, ext: type.resultExtension, contentType: contentType, data: data)
-                }
-            }
-        }
-    }
-    
-    private func uploadPasteFile(fileName: String, ext: String, contentType: String, data: Any) {
-        do {
-            let fileNameView = fileName + "_" + CCUtility.getIncrementalNumber() + "." + ext
-            let ocId = UUID().uuidString
-            let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
-            
-            if data is UIImage {
-                try (data as? UIImage)?.jpegData(compressionQuality: 1)?.write(to: URL(fileURLWithPath: filePath))
-            } else if data is Data {
-                try (data as? Data)?.write(to: URL(fileURLWithPath: filePath))
-            } else if data is String {
-                try (data as? String)?.write(to: URL(fileURLWithPath: filePath), atomically: true, encoding: .utf8)
-            } else {
-                return
-            }
-            
-            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 = NCBrandGlobal.shared.selectorUploadFile
-            metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath)
-            metadataForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload
-            
-            NCManageDatabase.shared.addMetadata(metadataForUpload)
-            
-        } catch { }
-    }
-    
-    private func uploadPasteOcId(_ ocId: String) {
-        if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-                let fileNameView = NCUtilityFileSystem.shared.createFileName(metadata.fileNameView, serverUrl: serverUrl, account: appDelegate.account)
-                let ocId = NSUUID().uuidString
-                
-                CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView))
-                let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, fileName: fileNameView, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "", livePhoto: false)
-                
-                metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
-                metadataForUpload.sessionSelector = NCBrandGlobal.shared.selectorUploadFile
-                metadataForUpload.size = metadata.size
-                metadataForUpload.status = NCBrandGlobal.shared.metadataStatusWaitUpload
-                
-                NCManageDatabase.shared.addMetadata(metadataForUpload)
-            }
-        }
-    }
-    
-    @objc func openQuickLookMenu(_ notification: Any) {
-        guard let metadata = metadataTouch else { return }
-                
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "selector": NCBrandGlobal.shared.selectorLoadFileQuickLook, "errorCode": 0, "errorDescription": "" ])
-        } else {
-            NCNetworking.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorLoadFileQuickLook) { (_) in }
-        }
-    }
-    
-    @objc func openInMenu(_ notification: Any) {
-        guard let metadata = metadataTouch else { return }
-                
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "selector": NCBrandGlobal.shared.selectorOpenIn, "errorCode": 0, "errorDescription": "" ])
-        } else {
-            NCNetworking.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorOpenIn) { (_) in }
-        }
+        NCCollectionCommon.shared.pasteFiles(serverUrl: serverUrl)
     }
     
     // MARK: - DataSource + NC Endpoint
@@ -1188,7 +1056,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
         }, actionProvider: { suggestedActions in
             
             let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc") ) { action in
-                self.copyFileMenu()
+                NCCollectionCommon.shared.copyFile(ocIds: [metadata.ocId])
             }
             
             let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info") ) { action in

+ 19 - 0
iOSClient/Main/Menu/NCCollectionViewCommon+Menu.swift

@@ -340,6 +340,9 @@ extension NCCollectionViewCommon {
     private func initMenuSelect(viewController: UIViewController, selectOcId: [String]) -> [NCMenuAction] {
         var actions = [NCMenuAction]()
        
+        //
+        // SELECT ALL
+        //
         actions.append(
             NCMenuAction(
                 title: NSLocalizedString("_select_all_", comment: ""),
@@ -350,6 +353,22 @@ extension NCCollectionViewCommon {
             )
         )
         
+        //
+        // COPY
+        //
+        if #available(iOS 13.0, *) {
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_copy_file_", comment: ""),
+                    icon: UIImage(systemName: "doc.on.doc")!.image(color: NCBrandColor.shared.icon, size: 50),
+                    action: { menuAction in
+                        NCCollectionCommon.shared.copyFile(ocIds: selectOcId)
+                        self.tapSelect(sender: self)
+                    }
+                )
+            )
+        }
+        
         //
         // COPY - MOVE
         //

+ 2 - 2
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -492,8 +492,8 @@
 
 "_file_del_only_local_"         = "File not present on server";
 
-"_copy_file_"                   = "Copy file";
-"_paste_file_"                  = "Paste file";
+"_copy_file_"                   = "Copy";
+"_paste_file_"                  = "Paste";
 "_open_quicklook_"              = "Open with Quick Look";
 
 "_search_this_folder_"          = "Search in this folder";