Explorar el Código

fix copy/paste

marinofaggiana hace 4 años
padre
commit
222cfc8083

+ 2 - 3
iOSClient/AppDelegate.h

@@ -50,9 +50,6 @@
 @property (nonatomic, strong) UIWindow *window;
 @property (nonatomic, copy) void (^backgroundSessionCompletionHandler)(void);
 
-// Timer Process
-
-
 // Parameter account
 @property (nonatomic, strong) NSString *account;
 @property (nonatomic, strong) NSString *urlBase;
@@ -93,6 +90,8 @@
 @property (nonatomic, strong) NCNetworkingAutoUpload *networkingAutoUpload;
 @property (nonatomic, retain) TOPasscodeViewController *passcodeViewController;
 
+@property (nonatomic, strong) NSMutableArray *pasteboardOcIds;
+
 // Login
 - (void)startTimerErrorNetworking;
 - (void)openLoginView:(UIViewController *)viewController selector:(NSInteger)selector openLoginWeb:(BOOL)openLoginWeb;

+ 2 - 0
iOSClient/AppDelegate.m

@@ -99,6 +99,8 @@
     self.listFilesVC = [NSMutableDictionary new];
     self.listFavoriteVC = [NSMutableDictionary new];
     self.listOfflineVC = [NSMutableDictionary new];
+    
+    self.pasteboardOcIds = [NSMutableArray new];
 
     // Push Notification
     [application registerForRemoteNotifications];

+ 19 - 43
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -301,11 +301,8 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         }
         
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc") ) { action in
-            if metadataMOV != nil {
-                NCCollectionCommon.shared.copyFile(ocIds: [metadata.ocId, metadataMOV!.ocId])
-            } else {
-                NCCollectionCommon.shared.copyFile(ocIds: [metadata.ocId])
-            }
+            self.appDelegate.pasteboardOcIds = [metadata.ocId]
+            self.copyPasteboard()
         }
         
         let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info") ) { action in
@@ -384,14 +381,17 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
     
     // MARK: - Copy & Paste
 
-    func copyFile(ocIds: [String]) {
+    func copyPasteboard() {
+        
         var metadatas: [tableMetadata] = []
         var items = [[String : Any]]()
-
         
-        for ocId in ocIds {
-            if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
+        for ocId in appDelegate.pasteboardOcIds {
+            if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId as? String) {
                 metadatas.append(metadata)
+                if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
+                    metadatas.append(metadataMOV)
+                }
             }
         }
         
@@ -399,9 +399,6 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
             
             if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
                 do {
-                    // etag
-                    let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
-                    items.append([NCBrandGlobal.shared.metadataKeyedUnarchiver:etagPasteboard])
                     // Get Data
                     let data = try Data.init(contentsOf: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
                     // Pasteboard item
@@ -420,46 +417,25 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         UIPasteboard.general.setItems(items, options: [:])
     }
 
-    func pasteFiles(serverUrl: String) {
+    func pastePasteboard(serverUrl: String) {
         
         var listData: [String] = []
         
-        // Detect metadataKeyedUnarchiver
-        var foundMetadataKeyedUnarchiver: Bool = false
-        for item in UIPasteboard.general.items {
-            for object in item {
-                if object.key == NCBrandGlobal.shared.metadataKeyedUnarchiver {
-                    foundMetadataKeyedUnarchiver = true
-                }
-            }
-        }
-        
         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")
+               
+                if data is String {
+                    if listData.contains(data as! String) {
+                        continue
+                    } else {
+                        listData.append(data as! String)
                     }
-                    continue
                 }
-                if !foundMetadataKeyedUnarchiver {
-                    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)
-                    }
+                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)
                 }
             }
         }

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

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

+ 3 - 8
iOSClient/Main/Menu/NCCollectionViewCommon+Menu.swift

@@ -393,16 +393,11 @@ extension NCCollectionViewCommon {
                     title: NSLocalizedString("_copy_file_", comment: ""),
                     icon: UIImage(systemName: "doc.on.doc")!.image(color: NCBrandColor.shared.icon, size: 50),
                     action: { menuAction in
-                        var copyOcIds = [String]()
+                        self.appDelegate.pasteboardOcIds.removeAllObjects()
                         for ocId in selectOcId {
-                            copyOcIds.append(ocId)
-                            if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-                                if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
-                                    copyOcIds.append(metadataMOV.ocId)
-                                }
-                            }
+                            self.appDelegate.pasteboardOcIds.add(ocId)
                         }
-                        NCCollectionCommon.shared.copyFile(ocIds: copyOcIds)
+                        NCCollectionCommon.shared.copyPasteboard()
                         self.tapSelect(sender: self)
                     }
                 )

+ 1 - 10
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -100,16 +100,7 @@ import Foundation
                         
                     case NCBrandGlobal.shared.selectorLoadCopy:
                         
-                        var items = UIPasteboard.general.items
-                        
-                        do {
-                            let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
-                            items.append([NCBrandGlobal.shared.metadataKeyedUnarchiver:etagPasteboard])
-                        } catch {
-                            print("error")
-                        }
-                        
-                        UIPasteboard.general.setItems(items, options: [:])
+                        NCCollectionCommon.shared.copyPasteboard()
                         
                     case NCBrandGlobal.shared.selectorLoadOffline: