marinofaggiana 4 lat temu
rodzic
commit
cd6be6403f

+ 21 - 7
iOSClient/Main/Menu/NCCollectionViewCommon+Menu.swift

@@ -27,12 +27,12 @@ import FloatingPanel
 
 extension NCCollectionViewCommon {
 
-    func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata) {
+    func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata, selectOcId: [String]) {
         
         if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
             
             let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
-            mainMenuViewController.actions = self.initMoreMenu(metadata: metadata, viewController: viewController)
+            mainMenuViewController.actions = self.initMenu(viewController: viewController, metadata: metadata, selectOcId: selectOcId)
 
             let menuPanelController = NCMenuPanelController()
             menuPanelController.parentPresenter = viewController
@@ -44,7 +44,7 @@ extension NCCollectionViewCommon {
         }
     }
     
-    private func initMoreMenu(metadata: tableMetadata, viewController: UIViewController) -> [NCMenuAction] {
+    private func initMenu(viewController: UIViewController, metadata: tableMetadata, selectOcId: [String]) -> [NCMenuAction] {
         var actions = [NCMenuAction]()
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
         let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl+"/"+metadata.fileName, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
@@ -122,7 +122,6 @@ extension NCCollectionViewCommon {
             )
         }
 
-        /*
         if !isFolderEncrypted && serverUrl != "" {
             actions.append(
                 NCMenuAction(
@@ -134,7 +133,6 @@ extension NCCollectionViewCommon {
                 )
             )
         }
-        */
         
         actions.append(
             NCMenuAction(
@@ -143,10 +141,26 @@ extension NCCollectionViewCommon {
                 action: { menuAction in
                     let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
-                        NCNetworking.shared.deleteMetadata(metadata, account: metadata.account, urlBase: metadata.urlBase, onlyLocal: false) { (errorCode, errorDescription) in }
+                        if selectOcId.count > 0 {
+                            for ocId in selectOcId {
+                                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                                    NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: false)
+                                }
+                            }
+                        } else {
+                            NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: false)
+                        }
                     })
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (action:UIAlertAction) in
-                        NCNetworking.shared.deleteMetadata(metadata, account: metadata.account, urlBase: metadata.urlBase, onlyLocal: true) { (errorCode, errorDescription) in }
+                        if selectOcId.count > 0 {
+                            for ocId in selectOcId {
+                                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                                    NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: true)
+                                }
+                            }
+                        } else {
+                            NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: true)
+                        }
                     })
                     alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
                     self.present(alertController, animated: true, completion:nil)

+ 29 - 4
iOSClient/Main/NCCollectionCommon.swift

@@ -372,8 +372,19 @@ class NCCollectionCommon: NSObject {
                     })
                 }
             }
-        } else {
-            NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+        } 
+    }
+    
+    func notificationMoveFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata, errorCode: Int, errorDescription: String) {
+        if errorCode == 0 {
+            if let row = dataSource?.deleteMetadata(ocId: metadata.ocId) {
+                let indexPath = IndexPath(row: row, section: 0)
+                collectionView?.performBatchUpdates({
+                    collectionView?.deleteItems(at: [indexPath])
+                }, completion: { (_) in
+                    collectionView?.reloadData()
+                })
+            }
         }
     }
     
@@ -655,7 +666,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, NCL
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource), name: NSNotification.Name(rawValue: k_notificationCenter_reloadDataSource), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_deleteFile), object: nil)
-        
+        NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(copyFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_copyFile), object: nil)
+
         NotificationCenter.default.addObserver(self, selector: #selector(downloadStartFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_downloadStartFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_downloadedFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(downloadCancelFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_downloadCancelFile), object: nil)
@@ -719,7 +732,19 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, NCL
             }
         }
     }
+   
+    @objc func moveFile(_ notification: NSNotification) {
+        if self.view?.window == nil { return }
         
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let metadata = userInfo["metadata"] as? tableMetadata, let _ = userInfo["metadataNew"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
+                NCCollectionCommon.shared.notificationMoveFile(collectionView: collectionView, dataSource: dataSource, metadata: metadata, errorCode: errorCode, errorDescription: errorDescription)
+            }
+        }
+    }
+    
+    @objc func copyFile(_ notification: NSNotification) { }
+    
     @objc func downloadStartFile(_ notification: NSNotification) {
         if self.view?.window == nil { return }
         
@@ -880,7 +905,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, NCL
         guard let tabBarController = self.tabBarController else { return }
 
         if namedButtonMore == "more" {
-            toggleMoreMenu(viewController: tabBarController, metadata: metadata)
+            toggleMoreMenu(viewController: tabBarController, metadata: metadata, selectOcId: selectOcId)
         } else if namedButtonMore == "stop" {
             NCMainCommon.shared.cancelTransferMetadata(metadata, uploadStatusForcedStart: false)
         }