Pārlūkot izejas kodu

Remove copy to pasteboard completion

- easier to just cancel and dismiss all details before starting the copy process
- fixes glitch where selected rows wouldn't reload when they were downloaded in a selected state

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 gadi atpakaļ
vecāks
revīzija
ee4cb962b5

+ 11 - 15
iOSClient/Main/NCFunctionCenter.swift

@@ -417,8 +417,7 @@ import JGProgressHUD
 
 
     // MARK: - Copy & Paste
     // MARK: - Copy & Paste
 
 
-    func copyPasteboard(pasteboardOcIds: [String], hudView: UIView, completion: @escaping () -> Void) {
-        var metadatas: [tableMetadata] = pasteboardOcIds.compactMap(NCManageDatabase.shared.getMetadataFromOcId)
+    func copyPasteboard(pasteboardOcIds: [String], hudView: UIView) {
         var items = [[String: Any]]()
         var items = [[String: Any]]()
         var isCancelled = false
         var isCancelled = false
         let hud = JGProgressHUD()
         let hud = JGProgressHUD()
@@ -429,15 +428,14 @@ import JGProgressHUD
 
 
         // getting file data can take some time and block the main queue
         // getting file data can take some time and block the main queue
         DispatchQueue.global(qos: .userInitiated).async {
         DispatchQueue.global(qos: .userInitiated).async {
-            metadatas = metadatas.compactMap({ metadata in
-                if let pasteboardItem = metadata.toPasteBoardItem() {
-                    items.append(pasteboardItem)
-                    return nil
-                }
-                return metadata
-            })
+            var downloadMetadatas: [tableMetadata] = []
+            for ocid in pasteboardOcIds {
+                guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocid) else { continue }
+                if let pasteboardItem = metadata.toPasteBoardItem() { items.append(pasteboardItem) }
+                else { downloadMetadatas.append(metadata) }
+            }
 
 
-            if !metadatas.isEmpty {
+            if !downloadMetadatas.isEmpty {
                 DispatchQueue.main.async {
                 DispatchQueue.main.async {
                     hud.textLabel.text = NSLocalizedString("_status_downloading_", comment: "")
                     hud.textLabel.text = NSLocalizedString("_status_downloading_", comment: "")
                     hud.detailTextLabel.text = NSLocalizedString("_tap_to_cancel_", comment: "")
                     hud.detailTextLabel.text = NSLocalizedString("_tap_to_cancel_", comment: "")
@@ -445,12 +443,11 @@ import JGProgressHUD
                         isCancelled = true
                         isCancelled = true
                         hud.dismiss()
                         hud.dismiss()
                     }
                     }
-                    hud.show(in: hudView)
                 }
                 }
             }
             }
 
 
             // do 5 downloads in paralell to optimize efficiancy
             // do 5 downloads in paralell to optimize efficiancy
-            for metadata in metadatas {
+            for metadata in downloadMetadatas {
                 guard !isCancelled else { return }
                 guard !isCancelled else { return }
                 copyDispatchGroup.enter()
                 copyDispatchGroup.enter()
                 NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { _ in
                 NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { _ in
@@ -466,9 +463,8 @@ import JGProgressHUD
                 hud.textLabel.text = NSLocalizedString("_success_", comment: "")
                 hud.textLabel.text = NSLocalizedString("_success_", comment: "")
                 hud.detailTextLabel.text = ""
                 hud.detailTextLabel.text = ""
                 hud.dismiss(afterDelay: 1)
                 hud.dismiss(afterDelay: 1)
-                items.append(contentsOf: metadatas.compactMap({ $0.toPasteBoardItem() }))
+                items.append(contentsOf: downloadMetadatas.compactMap({ $0.toPasteBoardItem() }))
                 UIPasteboard.general.setItems(items, options: [:])
                 UIPasteboard.general.setItems(items, options: [:])
-                completion()
             })
             })
         }
         }
     }
     }
@@ -680,7 +676,7 @@ import JGProgressHUD
         let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: "")
         let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: "")
 
 
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { _ in
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { _ in
-            self.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view, completion: { })
+            self.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view)
         }
         }
 
 
         let copyPath = UIAction(title: NSLocalizedString("_copy_path_", comment: ""), image: UIImage(systemName: "doc.on.clipboard")) { _ in
         let copyPath = UIAction(title: NSLocalizedString("_copy_path_", comment: ""), image: UIImage(systemName: "doc.on.clipboard")) { _ in

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

@@ -320,7 +320,7 @@ extension NCCollectionViewCommon {
                     title: NSLocalizedString("_copy_file_", comment: ""),
                     title: NSLocalizedString("_copy_file_", comment: ""),
                     icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                     icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                     action: { _ in
                     action: { _ in
-                        NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: self.view, completion: { })
+                        NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: self.view)
                     }
                     }
                 )
                 )
             )
             )
@@ -535,7 +535,8 @@ extension NCCollectionViewCommon {
                 title: NSLocalizedString("_copy_file_", comment: ""),
                 title: NSLocalizedString("_copy_file_", comment: ""),
                 icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                 icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                 action: { _ in
                 action: { _ in
-                    NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: self.selectOcId, hudView: self.view, completion: { self.tapSelect(sender: self) })
+                    NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: self.selectOcId, hudView: self.view)
+                    self.tapSelect(sender: self)
                 }
                 }
             )
             )
         )
         )

+ 3 - 4
iOSClient/Menu/NCMedia+Menu.swift

@@ -224,10 +224,9 @@ extension NCMedia {
                     icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                     icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                     action: { _ in
                     action: { _ in
                         self.isEditMode = false
                         self.isEditMode = false
-                        NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: self.selectOcId, hudView: self.view) {
-                            self.selectOcId.removeAll()
-                            self.reloadDataThenPerform { }
-                        }
+                        NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: self.selectOcId, hudView: self.view)
+                        self.selectOcId.removeAll()
+                        self.reloadDataThenPerform { }
                     }
                     }
                 )
                 )
             )
             )

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

@@ -257,7 +257,7 @@ extension NCViewer {
                 title: NSLocalizedString("_copy_file_", comment: ""),
                 title: NSLocalizedString("_copy_file_", comment: ""),
                 icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                 icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
                 action: { _ in
                 action: { _ in
-                    NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view, completion: { })
+                    NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view)
                 }
                 }
             )
             )
         )
         )