Browse Source

More menu in favorites as drawer

Signed-off-by: Philippe Weidmann <philippe.weidmann@infomaniak.com>
Philippe Weidmann 5 years ago
parent
commit
f5be1a542b

+ 3 - 0
iOSClient/Favorites/CCFavorites.h

@@ -50,4 +50,7 @@
 - (void)reloadDatasource:(NSString *)ocId action:(NSInteger)action;
 - (void)listingFavorites;
 
+- (void)actionDelete:(NSIndexPath *)indexPath;
+- (void)settingFavorite:(tableMetadata *)metadata favorite:(BOOL)favorite;
+
 @end

+ 3 - 0
iOSClient/Favorites/CCFavorites.m

@@ -431,6 +431,9 @@
     
     tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
     
+    [self toggleMoreMenuWithViewController:self.tabBarController indexPath:indexPath metadata:metadata];
+    return;
+    
     AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.tabBarController.view title:nil];
     
     actionSheet.animationDuration = 0.2;

+ 63 - 0
iOSClient/Main/MainMenu/MainMenuManager.swift

@@ -535,6 +535,69 @@ extension CCMain {
 
 }
 
+extension CCFavorites {
+
+    private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata) -> [MenuAction] {
+        var actions = [MenuAction]()
+        
+        var iconHeader: UIImage!
+        if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
+            iconHeader = icon
+        } else {
+            if(metadata.directory){
+                iconHeader = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
+            } else {
+                iconHeader = UIImage(named: metadata.iconName)
+            }
+        }
+
+        actions.append(MenuAction(title: metadata.fileNameView, icon: iconHeader, action: { menuAction in
+        }))
+
+        if(self.serverUrl == nil) {
+            actions.append(MenuAction(title: NSLocalizedString("_remove_favorites_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite), action: { menuAction in
+                self.settingFavorite(metadata, favorite: false)
+                }))
+        }
+
+        actions.append(MenuAction(title: NSLocalizedString("_details_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
+            }))
+
+        if(!metadata.directory && !NCBrandOptions.sharedInstance.disable_openin_file) {
+            actions.append(MenuAction(title: NSLocalizedString("_open_in_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                    self.tableView.setEditing(false, animated: true)
+                    NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
+                }))
+        }
+
+        actions.append(MenuAction(title: NSLocalizedString("_delete_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                self.actionDelete(indexPath)
+            }))
+
+        return actions
+    }
+
+    @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata) {
+        let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
+        mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata)
+
+        let fpc = FloatingPanelController()
+        fpc.surfaceView.grabberHandle.isHidden = true
+        fpc.delegate = mainMenuViewController
+        fpc.set(contentViewController: mainMenuViewController)
+        fpc.track(scrollView: mainMenuViewController.tableView)
+        fpc.isRemovalInteractionEnabled = true
+        if #available(iOS 11, *) {
+            fpc.surfaceView.cornerRadius = 16
+        } else {
+            fpc.surfaceView.cornerRadius = 0
+        }
+
+        viewController.present(fpc, animated: true, completion: nil)
+    }
+}
+
 //helper to find the current top view controller
 extension UIViewController {
     @objc class func topViewController(rootViewController: UIViewController?) -> UIViewController? {