ソースを参照

Fix conflict dismiss + don't allow share extension modifications while uploading

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 年 前
コミット
c00f2e28ff

+ 2 - 1
Share/NCShareCell.swift

@@ -25,6 +25,7 @@ import UIKit
 import NCCommunication
 
 protocol NCShareCellDelegate: AnyObject {
+    var uploadStated: Bool { get }
     func removeFile(named fileName: String)
     func renameFile(named fileName: String)
 }
@@ -64,7 +65,7 @@ class NCShareCell: UITableViewCell {
     }
 
     @IBAction func buttonTapped(_ sender: Any) {
-        guard !fileName.isEmpty else { return }
+        guard !fileName.isEmpty, delegate?.uploadStated != true else { return }
         let alertController = UIAlertController(title: "", message: fileName, preferredStyle: .alert)
 
         alertController.addAction(UIAlertAction(title: NSLocalizedString("_rename_file_", comment: ""), style: .default) { _ in

+ 1 - 0
Share/NCShareExtension+DataSource.swift

@@ -158,6 +158,7 @@ extension NCShareExtension: UITableViewDelegate {
     }
 
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        guard !uploadStarted else { return }
         let fileName = filesName[indexPath.row]
         renameFile(named: fileName)
     }

+ 3 - 0
Share/NCShareExtension+NCDelegate.swift

@@ -102,6 +102,9 @@ extension NCShareExtension: NCEmptyDataSetDelegate, NCAccountRequestDelegate {
 }
 
 extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCellDelegate {
+    // Bug in Swift?
+    var uploadStated: Bool { uploadStarted }
+
     func removeFile(named fileName: String) {
         guard let index = self.filesName.firstIndex(of: fileName) else {
             return showAlert(title: "_file_not_found_", description: fileName)

+ 5 - 9
Share/NCShareExtension.swift

@@ -73,11 +73,10 @@ class NCShareExtension: UIViewController {
     var activeAccount: tableAccount!
     private let chunckSize = CCUtility.getChunkSize() * 1000000
 
-    private var numberFilesName: Int = 0
     private var counterUpload: Int = 0
     var uploadDispatchGroup: DispatchGroup?
     private var uploadErrors: [tableMetadata] = []
-    private var uploadStarted = false
+    private(set) var uploadStarted = false
 
     // MARK: - View Life Cycle
 
@@ -190,11 +189,9 @@ class NCShareExtension: UIViewController {
     }
 
     @objc func triggerProgressTask(_ notification: NSNotification) {
-        if let userInfo = notification.userInfo as NSDictionary?, let progressNumber = userInfo["progress"] as? NSNumber {
-            let progress = CGFloat(progressNumber.floatValue)
-            let status = NSLocalizedString("_upload_file_", comment: "") + " \(self.counterUpload) " + NSLocalizedString("_of_", comment: "") + " \(self.numberFilesName)"
-            IHProgressHUD.show(progress: progress, status: status)
-        }
+        guard let progress = notification.userInfo?["progress"] as? CGFloat else { return }
+        let status = NSLocalizedString("_upload_file_", comment: "") + " \(counterUpload) " + NSLocalizedString("_of_", comment: "") + " \(filesName.count)"
+        IHProgressHUD.show(progress: progress, status: status)
     }
 
     func setNavigationBar(navigationTitle: String) {
@@ -271,8 +268,7 @@ class NCShareExtension: UIViewController {
             self.tableView.isScrollEnabled = false
         }
         // Label upload button
-        numberFilesName = filesName.count
-        uploadLabel.text = NSLocalizedString("_upload_", comment: "") + " \(numberFilesName) " + NSLocalizedString("_files_", comment: "")
+        uploadLabel.text = NSLocalizedString("_upload_", comment: "") + " \(filesName.count) " + NSLocalizedString("_files_", comment: "")
         // Empty
         emptyDataSet = NCEmptyDataSet(view: collectionView, offset: -50 * counter, delegate: self)
         self.tableView.reloadData()

+ 9 - 6
iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift

@@ -178,7 +178,9 @@ extension NCCreateFormUploadConflictDelegate {
         }))
 
         conflictAlert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_keep_existing_action_title_", comment: ""), style: .cancel, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
+            self.dismiss(animated: true) {
+                self.delegate?.dismissCreateFormUploadConflict(metadatas: nil)
+            }
         }))
 
         conflictAlert.addAction(UIAlertAction(title: NSLocalizedString("_more_action_title_", comment: ""), style: .default, handler: { _ in
@@ -236,9 +238,9 @@ extension NCCreateFormUploadConflictDelegate {
     }
 
     @IBAction func buttonCancelTouch(_ sender: Any) {
-
-        delegate?.dismissCreateFormUploadConflict(metadatas: nil)
-        dismiss(animated: true)
+        dismiss(animated: true) {
+            self.delegate?.dismissCreateFormUploadConflict(metadatas: nil)
+        }
     }
 
     @IBAction func buttonContinueTouch(_ sender: Any) {
@@ -309,9 +311,10 @@ extension NCCreateFormUploadConflictDelegate {
         }
 
         metadatasNOConflict.append(contentsOf: metadatasMOV)
-        delegate?.dismissCreateFormUploadConflict(metadatas: metadatasNOConflict)
 
-        dismiss(animated: true)
+        dismiss(animated: true) {
+            self.delegate?.dismissCreateFormUploadConflict(metadatas: self.metadatasNOConflict)
+        }
     }
 }