marinofaggiana 4 жил өмнө
parent
commit
b858e7da85

+ 8 - 7
iOSClient/Main/Collection/NCCollectionViewCommon.swift

@@ -514,6 +514,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     // MARK: TAP EVENT
     
     @objc func tapSelect(sender: Any) {
+        
         isEditMode = !isEditMode
         self.collectionView.reloadData()
     }
@@ -552,23 +553,23 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     }
     
     @objc func tapSelectMenu(sender: Any) {
-      
+        
+        guard let tabBarController = self.tabBarController else { return }
+        toggleMoreSelect(viewController: tabBarController, selectOcId: selectOcId)
     }
     
     func tapMoreHeader(sender: Any) {
-        
+
     }
     
     func tapMoreListItem(with objectId: String, namedButtonMore: String, sender: Any) {
+        
         tapMoreGridItem(with: objectId, namedButtonMore: namedButtonMore, sender: sender)
     }
     
     func tapShareListItem(with objectId: String, sender: Any) {
         
-        guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(objectId) else {
-            return
-        }
-        
+        guard let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(objectId) else { return }
         NCMainCommon.shared.openShare(ViewController: self, metadata: metadata, indexPage: 2)
     }
         
@@ -578,7 +579,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         guard let tabBarController = self.tabBarController else { return }
 
         if namedButtonMore == "more" {
-            toggleMoreMenu(viewController: tabBarController, metadata: metadata, selectOcId: selectOcId)
+            toggleMoreMenu(viewController: tabBarController, metadata: metadata)
         } else if namedButtonMore == "stop" {
             NCMainCommon.shared.cancelTransferMetadata(metadata, uploadStatusForcedStart: false)
         }

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

@@ -27,12 +27,12 @@ import FloatingPanel
 
 extension NCCollectionViewCommon {
 
-    func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata, selectOcId: [String]) {
+    func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata) {
         
         if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
             
             let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
-            mainMenuViewController.actions = self.initMenu(viewController: viewController, metadata: metadata, selectOcId: selectOcId)
+            mainMenuViewController.actions = self.initMenuMore(viewController: viewController, metadata: metadata)
 
             let menuPanelController = NCMenuPanelController()
             menuPanelController.parentPresenter = viewController
@@ -44,7 +44,7 @@ extension NCCollectionViewCommon {
         }
     }
     
-    private func initMenu(viewController: UIViewController, metadata: tableMetadata, selectOcId: [String]) -> [NCMenuAction] {
+    private func initMenuMore(viewController: UIViewController, metadata: tableMetadata) -> [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)        
@@ -80,7 +80,7 @@ extension NCCollectionViewCommon {
         )
 
         // Favorite
-        if (layoutKey == k_layout_view_favorite && serverUrl == "") || (layoutKey != k_layout_view_favorite) {
+        if (layoutKey == k_layout_view_favorite && serverUrl == nil) || (layoutKey != k_layout_view_favorite) {
             actions.append(
                 NCMenuAction(
                     title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
@@ -97,7 +97,7 @@ extension NCCollectionViewCommon {
         }
         
         // Offline
-        if !isFolderEncrypted && (layoutKey == k_layout_view_offline && self.serverUrl == "" || (layoutKey != k_layout_view_offline)) {
+        if !isFolderEncrypted && (layoutKey == k_layout_view_offline && serverUrl == nil || (layoutKey != k_layout_view_offline)) {
             actions.append(
                 NCMenuAction(
                     title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: ""),
@@ -182,7 +182,7 @@ extension NCCollectionViewCommon {
         )
         
 
-        if !isFolderEncrypted && serverUrl != "" {
+        if !isFolderEncrypted && serverUrl != nil {
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_move_or_copy_", comment: ""),
@@ -201,25 +201,78 @@ 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
-                        if selectOcId.count > 0 {
-                            for ocId in selectOcId {
-                                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                                    NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: false)
-                                }
+                        NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: false)
+                    })
+                    alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (action:UIAlertAction) in
+                        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)
+                }
+            )
+        )
+
+        return actions
+    }
+    
+    func toggleMoreSelect(viewController: UIViewController, selectOcId: [String]) {
+        
+        let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
+        mainMenuViewController.actions = self.initMenuSelect(viewController: viewController, selectOcId: selectOcId)
+
+        let menuPanelController = NCMenuPanelController()
+        menuPanelController.parentPresenter = viewController
+        menuPanelController.delegate = mainMenuViewController
+        menuPanelController.set(contentViewController: mainMenuViewController)
+        menuPanelController.track(scrollView: mainMenuViewController.tableView)
+
+        viewController.present(menuPanelController, animated: true, completion: nil)
+    }
+    
+    private func initMenuSelect(viewController: UIViewController, selectOcId: [String]) -> [NCMenuAction] {
+        var actions = [NCMenuAction]()
+       
+        actions.append(
+            NCMenuAction(
+                title: NSLocalizedString("_select_all_", comment: ""),
+                icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                action: { menuAction in
+                }
+            )
+        )
+        
+        actions.append(
+            NCMenuAction(
+                title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
+                icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+                action: { menuAction in
+                    for ocId in selectOcId {
+                        if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                            NCCollectionCommon.shared.openSelectView(viewController: viewController, array: [metadata])
+                        }
+                    }
+                }
+            )
+        )
+        
+        actions.append(
+            NCMenuAction(
+                title: NSLocalizedString("_delete_selected_files_", comment: ""),
+                icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
+                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
+                        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
-                        if selectOcId.count > 0 {
-                            for ocId in selectOcId {
-                                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                                    NCOperationQueue.shared.delete(metadata: metadata, onlyLocal: true)
-                                }
+                        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 })
@@ -227,7 +280,7 @@ extension NCCollectionViewCommon {
                 }
             )
         )
-
+        
         return actions
     }
 }