Browse Source

Fix error when Share upload fails

Also make sure upload button is disabled once upload is in progress

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
a4be71a898

+ 22 - 13
Share/NCShareExtension.swift

@@ -42,6 +42,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     @IBOutlet weak var createFolderLabel: UILabel!
 
     @IBOutlet weak var uploadView: UIView!
+    //is this still needed?
     @IBOutlet weak var uploadImage: UIImageView!
     @IBOutlet weak var uploadLabel: UILabel!
 
@@ -71,6 +72,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     private var numberFilesName: Int = 0
     private var counterUpload: Int = 0
     private var uploadDispatchGroup: DispatchGroup?
+    private var uploadErrors: [tableMetadata] = []
+    private var uploadStarted = false
 
     // MARK: - View Life Cycle
 
@@ -414,7 +417,11 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     }
 
     @objc func actionUpload() {
-        guard !filesName.isEmpty else { fatalError("No files") }
+        guard !uploadStarted else { return }
+        guard !filesName.isEmpty else { return showAlert(description: "_files_no_files_") }
+
+        uploadStarted = true
+        uploadErrors = []
         uploadDispatchGroup = DispatchGroup()
         uploadDispatchGroup?.enter()
         uploadDispatchGroup?.notify(queue: .main, execute: finishedUploading)
@@ -468,27 +475,29 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         NCNetworking.shared.upload(metadata: metadata) {
 
         } completion: { errorCode, errorDescription in
+            defer { self.uploadDispatchGroup?.leave() }
             if errorCode != 0 {
                 self.counterUpload += 1
-                self.uploadDispatchGroup?.leave()
             } else {
-
-                IHProgressHUD.dismiss()
-
                 NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                 NCManageDatabase.shared.deleteChunks(account: self.activeAccount.account, ocId: metadata.ocId)
-
-                self.showAlert(description: errorDescription) {
-                    self.uploadDispatchGroup?.leave()
-                }
+                self.uploadErrors.append(metadata)
             }
         }
     }
 
     func finishedUploading() {
-        IHProgressHUD.showSuccesswithStatus(NSLocalizedString("_success_", comment: ""))
-        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-            self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
+        uploadStarted = false
+        if !uploadErrors.isEmpty {
+            let fileList = "- " + uploadErrors.map({ $0.fileName }).joined(separator: "\n  - ")
+            showAlert(title: "_error_files_upload_", description: fileList) {
+                self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
+            }
+        } else {
+            IHProgressHUD.showSuccesswithStatus(NSLocalizedString("_success_", comment: ""))
+            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+                self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
+            }
         }
     }
 
@@ -726,7 +735,7 @@ extension NCShareExtension {
                     self.setNavigationBar(navigationTitle: fileName)
 
                 } else {
-                    self.showAlert(description: errorDescription)
+                    self.showAlert(title: "_error_createsubfolders_upload_", description: errorDescription)
                 }
             }
         }

+ 3 - 2
iOSClient/Rename file/NCRenameFile.swift

@@ -219,8 +219,9 @@ class NCRenameFile: UIViewController, UITextFieldDelegate {
             }
 
             fileNameNew = (fileNameWithoutExt.text ?? "") + "." + (ext.text ?? "")
-            self.delegate?.rename(fileName: fileName, fileNameNew: fileNameNew)
-            self.dismiss(animated: true)
+            self.dismiss(animated: true) {
+                self.delegate?.rename(fileName: fileName, fileNameNew: fileNameNew)
+            }
         }
     }
 

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -763,6 +763,7 @@
 "_request_entity_too_large_"            = "The file is too large";
 "_not_possible_download_"               = "It is not possible to download the file";
 "_not_possible_upload_"                 = "It is not possible to upload the file";
+"_error_files_upload_"                  = "Error uploading files";
 "_method_not_allowed_"                  = "The requested method is not supported";
 "_invalid_url_"                         = "Invalid server URL";
 "_invalid_literal_"                     = "Invalid search string";