Explorar o código

https://github.com/nextcloud/ios/issues/2588 (#2589)

* fix

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* fix test

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

---------

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana hai 1 ano
pai
achega
f5d83e8815

+ 1 - 1
Tests/NextcloudUITests/LoginUITests.swift

@@ -47,7 +47,7 @@ final class LoginUITests: BaseUIXCTestCase {
         usernameTextField.typeText(user)
         let passwordTextField = element.children(matching: .other).element(boundBy: 4).children(matching: .secureTextField).element
         passwordTextField.tap()
-        passwordTextField.typeText(user)
+        passwordTextField.typeText(password)
         let loginButton3 = webViewsQuery/*@START_MENU_TOKEN@*/.buttons["Log in"]/*[[".otherElements[\"Login – Nextcloud\"]",".otherElements[\"main\"].buttons[\"Log in\"]",".buttons[\"Log in\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
         XCTAssert(loginButton3.waitForExistence(timeout: timeoutSeconds))
         loginButton3.tap()

+ 1 - 1
iOSClient/Main/Collection Common/NCSelectableNavigationView.swift

@@ -159,7 +159,7 @@ extension NCSelectableNavigationView where Self: UIViewController {
         }))
 
         actions.append(.moveOrCopyAction(selectedMetadatas: selectedMetadatas, indexPath: selectIndexPath, completion: tapSelect))
-        actions.append(.copyAction(selectOcId: selectOcId, hudView: self.view, completion: tapSelect))
+        actions.append(.copyAction(selectOcId: selectOcId, completion: tapSelect))
         actions.append(.deleteAction(selectedMetadatas: selectedMetadatas, indexPath: selectIndexPath, viewController: self, completion: tapSelect))
         return actions
     }

+ 21 - 8
iOSClient/Main/NCActionCenter.swift

@@ -516,11 +516,11 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
 
     // MARK: - Copy & Paste
 
-    func copyPasteboard(pasteboardOcIds: [String], hudView: UIView) {
+    func copyPasteboard(pasteboardOcIds: [String]) {
         var items = [[String: Any]]()
-        let hud = JGProgressHUD()
-        hud.textLabel.text = NSLocalizedString("_wait_", comment: "")
-        hud.show(in: hudView)
+        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
+        let hudView = appDelegate.window?.rootViewController?.view
+        var fractionCompleted: Float = 0
 
         // getting file data can take some time and block the main queue
         DispatchQueue.global(qos: .userInitiated).async {
@@ -534,14 +534,21 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
                 }
             }
 
-            DispatchQueue.main.async(execute: hud.dismiss)
-
             // do 5 downloads in parallel to optimize efficiency
             let processor = ParallelWorker(n: 5, titleKey: "_downloading_", totalTasks: downloadMetadatas.count, hudView: hudView)
 
             for metadata in downloadMetadatas {
                 processor.execute { completion in
-                    NCNetworking.shared.download(metadata: metadata, selector: "", notificationCenterProgressTask: false) { _, _ in completion() }
+                    NCNetworking.shared.download(metadata: metadata, selector: "", notificationCenterProgressTask: false) { _ in
+                    } progressHandler: { progress in
+                        if Float(progress.fractionCompleted) > fractionCompleted || fractionCompleted == 0 {
+                            processor.hud?.progress = Float(progress.fractionCompleted)
+                            fractionCompleted = Float(progress.fractionCompleted)
+                        }
+                    } completion: { _, _ in
+                        fractionCompleted = 0
+                        completion()
+                    }
                 }
             }
             processor.completeWork {
@@ -553,13 +560,18 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
 
     func pastePasteboard(serverUrl: String) {
         guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
+        var fractionCompleted: Float = 0
 
         let processor = ParallelWorker(n: 5, titleKey: "_uploading_", totalTasks: nil, hudView: appDelegate.window?.rootViewController?.view)
 
         func uploadPastePasteboard(fileName: String, serverUrlFileName: String, fileNameLocalPath: String, serverUrl: String, completion: @escaping () -> Void) {
             NextcloudKit.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath) { request in
                 NCNetworking.shared.uploadRequest[fileNameLocalPath] = request
-            } progressHandler: { _ in
+            } progressHandler: { progress in
+                if Float(progress.fractionCompleted) > fractionCompleted || fractionCompleted == 0 {
+                    processor.hud?.progress = Float(progress.fractionCompleted)
+                    fractionCompleted = Float(progress.fractionCompleted)
+                }
             } completionHandler: { account, ocId, etag, _, _, _, afError, error in
                 NCNetworking.shared.uploadRequest.removeValue(forKey: fileNameLocalPath)
                 if error == .success && etag != nil && ocId != nil {
@@ -572,6 +584,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
                 } else {
                     NCContentPresenter.shared.showError(error: error)
                 }
+                fractionCompleted = 0
                 completion()
             }
         }

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

@@ -334,7 +334,7 @@ extension NCCollectionViewCommon {
         // COPY IN PASTEBOARD
         //
         if metadata.isCopyableInPasteboard {
-            actions.append(.copyAction(selectOcId: [metadata.ocId], hudView: self.view, order: 140))
+            actions.append(.copyAction(selectOcId: [metadata.ocId], order: 140))
         }
 
         //

+ 0 - 7
iOSClient/Menu/NCContextMenu.swift

@@ -121,13 +121,6 @@ class NCContextMenu: NSObject {
             }
         }
 
-        /*
-        let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""),
-                            image: UIImage(systemName: "doc.on.doc")) { _ in
-            NCActionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view)
-        }
-        */
-
         let modify = UIAction(title: NSLocalizedString("_modify_", comment: ""),
                               image: UIImage(systemName: "pencil.tip.crop.circle")) { _ in
             if CCUtility.fileProviderStorageExists(metadata) {

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

@@ -214,7 +214,7 @@ extension NCMedia {
             //
             // COPY
             //
-            actions.append(.copyAction(selectOcId: selectOcId, hudView: self.view, completion: tapSelect))
+            actions.append(.copyAction(selectOcId: selectOcId, completion: tapSelect))
 
             //
             // DELETE

+ 2 - 2
iOSClient/Menu/NCMenuAction.swift

@@ -93,13 +93,13 @@ extension NCMenuAction {
     }
 
     /// Copy files to pasteboard
-    static func copyAction(selectOcId: [String], hudView: UIView, order: Int = 0, completion: (() -> Void)? = nil) -> NCMenuAction {
+    static func copyAction(selectOcId: [String], order: Int = 0, completion: (() -> Void)? = nil) -> NCMenuAction {
         NCMenuAction(
             title: NSLocalizedString("_copy_file_", comment: ""),
             icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
             order: order,
             action: { _ in
-                NCActionCenter.shared.copyPasteboard(pasteboardOcIds: selectOcId, hudView: hudView)
+                NCActionCenter.shared.copyPasteboard(pasteboardOcIds: selectOcId)
                 completion?()
             }
         )

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

@@ -204,7 +204,7 @@ extension NCViewer {
         // COPY IN PASTEBOARD
         //
         if !webView, metadata.isCopyableInPasteboard {
-            actions.append(.copyAction(selectOcId: [metadata.ocId], hudView: viewController.view))
+            actions.append(.copyAction(selectOcId: [metadata.ocId]))
         }
 
         //

+ 1 - 4
iOSClient/Utility/ParallelWorker.swift

@@ -96,10 +96,7 @@ class ParallelWorker {
     func completeWork(completion: (() -> Void)? = nil) {
         completionGroup.notify(queue: .main) {
             guard !self.isCancelled else { return }
-            self.hud?.indicatorView = JGProgressHUDSuccessIndicatorView()
-            self.hud?.textLabel.text = NSLocalizedString("_done_", comment: "")
-            self.hud?.detailTextLabel.text = ""
-            self.hud?.dismiss(afterDelay: 1)
+            self.hud?.dismiss()
             completion?()
         }
     }