Browse Source

Sort and select menu

Signed-off-by: Philippe Weidmann <philippe.weidmann@infomaniak.com>
Philippe Weidmann 5 years ago
parent
commit
8841bce7b5
3 changed files with 169 additions and 50 deletions
  1. 6 0
      iOSClient/Main/CCMain.h
  2. 24 49
      iOSClient/Main/CCMain.m
  3. 139 1
      iOSClient/Main/MainMenu/MainMenuManager.swift

+ 6 - 0
iOSClient/Main/CCMain.h

@@ -93,5 +93,11 @@
 
 - (void)setTableViewHeader;
 
+- (void)didSelectAll;
+- (void)deleteFile;
+- (void)saveSelectedFiles;
+- (void)downloadSelectedFilesFolders;
+- (void)moveOpenWindow:(NSArray *)indexPaths;
+
 @end
 

+ 24 - 49
iOSClient/Main/CCMain.m

@@ -615,12 +615,15 @@
 
 - (void)setUINavigationBarDefault
 {
-    UIBarButtonItem *buttonMore, *buttonNotification;
+    UIBarButtonItem *buttonMore, *buttonNotification, *buttonSelect;
     
     // =
     buttonMore = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationControllerMenu"] style:UIBarButtonItemStylePlain target:self action:@selector(toggleReMainMenu)];
     buttonMore.enabled = true;
     
+    buttonSelect = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"select"] width:50 height:50 color:NCBrandColor.sharedInstance.textView] style:UIBarButtonItemStylePlain target:self action:@selector(tableViewSelect)];
+    buttonSelect.enabled = true;
+    
     // <
     self.navigationController.navigationBar.hidden = NO;
     
@@ -633,10 +636,10 @@
     }
     
     if (buttonNotification)
-        self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonNotification, nil];
+        self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonSelect, buttonNotification, nil];
     else
-        self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, nil];
-
+        self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonMore, buttonSelect, nil];
+    
     self.navigationItem.leftBarButtonItem = nil;
 }
 
@@ -653,7 +656,7 @@
 
 - (void)cancelSelect
 {
-    [self tableViewSelect:NO];
+    [self tableViewSelect];
     [appDelegate.reSelectMenu close];
 }
 
@@ -892,7 +895,7 @@
         [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
     });
     
-    [self tableViewSelect:NO];
+    [self tableViewSelect];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -981,7 +984,7 @@
         [_hud hideHud];
     });
     
-    [self tableViewSelect:NO];
+    [self tableViewSelect];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -1451,7 +1454,7 @@
     }];
     
     // End Select Table View
-    [self tableViewSelect:NO];
+    [self tableViewSelect];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -1613,7 +1616,7 @@
             [self presentViewController:alert animated:YES completion:nil];
             
             // End Select Table View
-            [self tableViewSelect:NO];
+            [self tableViewSelect];
             
             // reload Datasource
             [self readFileReloadFolder];
@@ -1652,7 +1655,7 @@
                         } else {
                             
                             // End Select Table View
-                            [self tableViewSelect:NO];
+                            [self tableViewSelect];
                             
                             // reload Datasource
                             if (self.searchController.isActive)
@@ -1666,7 +1669,7 @@
                         [[NCContentPresenter shared] messageNotification:@"_move_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
                         
                         // End Select Table View
-                        [self tableViewSelect:NO];
+                        [self tableViewSelect];
                         
                         // reload Datasource
                         if (self.searchController.isActive)
@@ -2203,7 +2206,7 @@
     // ITEM SELECT ----------------------------------------------------------------------------------------------------
     
     appDelegate.selezionaItem = [[REMenuItem alloc] initWithTitle:NSLocalizedString(@"_select_", nil)subtitle:@"" image:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"selectLight"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] highlightedImage:nil action:^(REMenuItem *item) {
-        if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect:YES];
+        if ([sectionDataSource.allRecordsDataSource count] > 0) [self tableViewSelect];
     }];
     
     // ITEM ORDER ----------------------------------------------------------------------------------------------------
@@ -2378,21 +2381,7 @@
 
 - (void)toggleReMainMenu
 {
-    if (appDelegate.reMainMenu.isOpen) {
-        
-        [appDelegate.reMainMenu close];
-        
-    } else {
-        
-        [self createReMainMenu];
-        [appDelegate.reMainMenu showFromNavigationController:self.navigationController];
-        
-        // Backgroun reMenu & (Gesture)
-        [self createReMenuBackgroundView:appDelegate.reMainMenu];
-        
-        _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReMainMenu)];
-        [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
-    }
+    [self toggleMenuWithViewController:self.navigationController];
 }
 
 - (void)createReSelectMenu
@@ -2495,21 +2484,7 @@
 
 - (void)toggleReSelectMenu
 {
-    if (appDelegate.reSelectMenu.isOpen) {
-        
-        [appDelegate.reSelectMenu close];
-        
-    } else {
-        
-        [self createReSelectMenu];
-        [appDelegate.reSelectMenu showFromNavigationController:self.navigationController];
-        
-        // Backgroun reMenu & (Gesture)
-        [self createReMenuBackgroundView:appDelegate.reSelectMenu];
-        
-        _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleReSelectMenu)];
-        [_reMenuBackgroundView addGestureRecognizer:_singleFingerTap];
-    }
+    [self toggleSelectMenuWithViewController:self.navigationController];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -2709,7 +2684,7 @@
         }
     }
     
-    [self tableViewSelect:NO];
+    [self tableViewSelect];
 }
 
 - (void)copyFileToPasteboard:(tableMetadata *)metadata
@@ -3614,17 +3589,17 @@
 #pragma mark - ==== Table ==== 
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)tableViewSelect:(BOOL)edit
+- (void)tableViewSelect
 {
+    _isSelectedMode = !_isSelectedMode;
     // chiudiamo eventuali swipe aperti
-    if (edit)
+    if (_isSelectedMode)
         [self.tableView setEditing:NO animated:NO];
     
-    [self.tableView setAllowsMultipleSelectionDuringEditing:edit];
-    [self.tableView setEditing:edit animated:YES];
-    _isSelectedMode = edit;
+    [self.tableView setAllowsMultipleSelectionDuringEditing:_isSelectedMode];
+    [self.tableView setEditing:_isSelectedMode animated:YES];
     
-    if (edit)
+    if (_isSelectedMode)
         [self setUINavigationBarSelected];
     else
         [self setUINavigationBarDefault];

+ 139 - 1
iOSClient/Main/MainMenu/MainMenuManager.swift

@@ -71,7 +71,7 @@ extension AppDelegate {
                 NCMainCommon.sharedInstance.startAudioRecorder()
             }))
 
-        actions.append(MenuAction(title: NSLocalizedString("_create_folder_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement), action: { menuAction in
+        actions.append(MenuAction(title: NSLocalizedString("_create_folder_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
                 appDelegate.activeMain.createFolder()
             }))
 
@@ -144,3 +144,141 @@ extension AppDelegate {
         viewController.present(fpc, animated: true, completion: nil)
     }
 }
+
+extension CCMain {
+
+    private func initSortMenu() -> [MenuAction] {
+        var actions = [MenuAction]()
+
+        actions.append(MenuAction(
+            title: NSLocalizedString("_order_by_name_a_z_", comment: ""),
+            icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortFileNameAZ"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            onTitle: NSLocalizedString("_order_by_name_z_a_", comment: ""),
+            onIcon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortFileNameZA"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            selected: CCUtility.getOrderSettings() == "fileName",
+            on: CCUtility.getAscendingSettings(),
+            action: { menuAction in
+                if(CCUtility.getOrderSettings() == "fileName" && CCUtility.getAscendingSettings()) {
+                    CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
+                } else {
+                    CCUtility.setOrderSettings("fileName")
+                    CCUtility.setAscendingSettings(true)
+                }
+
+                NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
+            }))
+
+        actions.append(MenuAction(
+            title: NSLocalizedString("_order_by_date_more_recent_", comment: ""),
+            icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortDateMoreRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
+            onIcon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortDateLessRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            selected: CCUtility.getOrderSettings() == "date",
+            on: CCUtility.getAscendingSettings(),
+            action: { menuAction in
+                if(CCUtility.getOrderSettings() == "date" && CCUtility.getAscendingSettings()) {
+                    CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
+                } else {
+                    CCUtility.setOrderSettings("date")
+                    CCUtility.setAscendingSettings(true)
+                }
+
+                NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
+            }))
+
+        actions.append(MenuAction(
+            title: NSLocalizedString("_order_by_size_smallest_", comment: ""),
+            icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortSmallest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
+            onIcon: CCGraphics.changeThemingColorImage(UIImage.init(named: "sortLargest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            selected: CCUtility.getOrderSettings() == "size",
+            on: CCUtility.getAscendingSettings(),
+            action: { menuAction in
+                if(CCUtility.getOrderSettings() == "size" && CCUtility.getAscendingSettings()) {
+                    CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
+                } else {
+                    CCUtility.setOrderSettings("size")
+                    CCUtility.setAscendingSettings(true)
+                }
+
+                NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
+            }))
+
+        actions.append(MenuAction(
+            title: NSLocalizedString("_directory_on_top_no_", comment: ""),
+            icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "foldersOnTop"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
+            selected: CCUtility.getDirectoryOnTop(),
+            on: CCUtility.getDirectoryOnTop(),
+            action: { menuAction in
+                CCUtility.setDirectoryOnTop(!CCUtility.getDirectoryOnTop())
+                NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
+            }))
+
+        return actions
+    }
+
+    @objc public func toggleMenu(viewController: UIViewController) {
+        let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
+        mainMenuViewController.actions = self.initSortMenu()
+
+        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)
+    }
+
+    @objc public func toggleSelectMenu(viewController: UIViewController) {
+        let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
+        mainMenuViewController.actions = self.initSelectMenu()
+
+        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)
+    }
+
+
+    private func initSelectMenu() -> [MenuAction] {
+        var actions = [MenuAction]()
+
+        actions.append(MenuAction(title: NSLocalizedString("_select_all_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                self.didSelectAll()
+            }))
+
+        actions.append(MenuAction(title: NSLocalizedString("_move_selected_files_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                self.moveOpenWindow(self.tableView.indexPathsForSelectedRows)
+            }))
+
+        actions.append(MenuAction(title: NSLocalizedString("_download_selected_files_folders_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "downloadSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                self.downloadSelectedFilesFolders()
+            }))
+
+        actions.append(MenuAction(title: NSLocalizedString("_save_selected_files_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "saveSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                self.saveSelectedFiles()
+            }))
+
+        actions.append(MenuAction(title: NSLocalizedString("_delete_selected_files_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
+                self.deleteFile()
+            }))
+
+        return actions
+    }
+}