Эх сурвалжийг харах

Update NCPlayerToolBar.swift

Marino Faggiana 1 жил өмнө
parent
commit
573aedc40f

+ 12 - 2
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -30,6 +30,7 @@ import MediaPlayer
 import MobileVLCKit
 import MobileVLCKit
 import FloatingPanel
 import FloatingPanel
 import JGProgressHUD
 import JGProgressHUD
+import Alamofire
 
 
 class NCPlayerToolBar: UIView {
 class NCPlayerToolBar: UIView {
 
 
@@ -441,12 +442,21 @@ extension NCPlayerToolBar: NCSelectDelegate {
             if CCUtility.fileProviderStorageExists(metadata) {
             if CCUtility.fileProviderStorageExists(metadata) {
                 addPlaybackSlave(type: type, metadata: metadata)
                 addPlaybackSlave(type: type, metadata: metadata)
             } else {
             } else {
+                var downloadRequest: DownloadRequest?
                 hud.indicatorView = JGProgressHUDRingIndicatorView()
                 hud.indicatorView = JGProgressHUDRingIndicatorView()
+                hud.detailTextLabel.text = NSLocalizedString("_tap_to_cancel_", comment: "")
                 if let indicatorView = hud.indicatorView as? JGProgressHUDRingIndicatorView {
                 if let indicatorView = hud.indicatorView as? JGProgressHUDRingIndicatorView {
                     indicatorView.ringWidth = 1.5
                     indicatorView.ringWidth = 1.5
                 }
                 }
+                hud.tapOnHUDViewBlock = { _ in
+                    if let request = downloadRequest {
+                        request.cancel()
+                    }
+                }
                 hud.show(in: viewerMediaPage.view)
                 hud.show(in: viewerMediaPage.view)
-                NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { _ in
+
+                NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { request in
+                    downloadRequest = request
                 }, taskHandler: { _ in
                 }, taskHandler: { _ in
                 }, progressHandler: { progress in
                 }, progressHandler: { progress in
                     self.hud.progress = Float(progress.fractionCompleted)
                     self.hud.progress = Float(progress.fractionCompleted)
@@ -454,7 +464,7 @@ extension NCPlayerToolBar: NCSelectDelegate {
                     self.hud.dismiss()
                     self.hud.dismiss()
                     if error == .success {
                     if error == .success {
                         self.addPlaybackSlave(type: type, metadata: metadata)
                         self.addPlaybackSlave(type: type, metadata: metadata)
-                    } else {
+                    } else if error.errorCode != 200 {
                         NCContentPresenter.shared.showError(error: error)
                         NCContentPresenter.shared.showError(error: error)
                     }
                     }
                 }
                 }