Browse Source

Refactor `NCShareQuickStatusMenu`

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
768bc0ffcc

+ 0 - 2
iOSClient/NCGlobal.swift

@@ -351,8 +351,6 @@ class NCGlobal: NSObject {
     let notificationCenterChangedLocation                       = "changedLocation"
     let notificationStatusAuthorizationChangedLocation          = "statusAuthorizationChangedLocation"
 
-    let notificationCenterShareChangePermissions                = "shareChangePermissions"          // userInfo: idShare, permissions, hideDownload
-
     let notificationCenterDownloadedThumbnail                   = "DownloadedThumbnail"             // userInfo: ocId
 
     let notificationCenterHidePlayerToolBar                     = "hidePlayerToolBar"               // userInfo: ocId

+ 1 - 4
iOSClient/Share/NCShare+NCCellDelegate.swift

@@ -33,7 +33,6 @@ extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate {
     }
 
     func tapMenu(with tableShare: tableShare?, sender: Any) {
-        guard let metadata = self.metadata else { return }
         if let tableShare = tableShare {
             self.toggleShareMenu(for: tableShare)
         } else {
@@ -50,8 +49,6 @@ extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate {
         guard let tableShare = tableShare,
               let metadata = metadata,
               tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption else { return }
-
-        let quickStatusMenu = NCShareQuickStatusMenu()
-        quickStatusMenu.toggleMenu(viewController: self, directory: metadata.directory, tableShare: tableShare)
+        self.toggleMenu(isDirectory: metadata.directory, tableShare: tableShare)
     }
 }

+ 0 - 9
iOSClient/Share/NCShare.swift

@@ -89,7 +89,6 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
 
         // changeTheming
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(changePermissions(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShareChangePermissions), object: nil)
 
         changeTheming()
     }
@@ -169,14 +168,6 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         tableView.reloadData()
     }
 
-    @objc func changePermissions(_ notification: NSNotification) {
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let idShare = userInfo["idShare"] as? Int, let permissions = userInfo["permissions"] as? Int, let hideDownload = userInfo["hideDownload"] as? Bool {
-                networking?.updateShare(idShare: idShare, password: nil, permissions: permissions, note: nil, label: nil, expirationDate: nil, hideDownload: hideDownload)
-            }
-        }
-    }
-
     // MARK: -
 
     @objc func reloadData() {

+ 14 - 20
iOSClient/Share/NCShareQuickStatusMenu.swift

@@ -8,12 +8,8 @@
 
 import UIKit
 
-class NCShareQuickStatusMenu: NSObject {
-
-    func toggleMenu(viewController: UIViewController, directory: Bool, tableShare: tableShare) {
-
-        print(tableShare.permissions)
-        let menuViewController = UIStoryboard(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
+extension NCShare {
+    func toggleMenu(isDirectory: Bool, tableShare: tableShare) {
         var actions = [NCMenuAction]()
 
         actions.append(
@@ -24,35 +20,27 @@ class NCShareQuickStatusMenu: NSObject {
                 on: false,
                 action: { _ in
                     let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
-                    let permissions = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: canShare, andIsFolder: directory)
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
+                    let permissions = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: canShare, andIsFolder: isDirectory)
+                    self.updateSharePermissions(share: tableShare, permissions: permissions)
                 }
             )
         )
 
         actions.append(
             NCMenuAction(
-                title: directory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
+                title: isDirectory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
                 icon: UIImage(),
                 selected: hasUploadPermission(tableShare: tableShare),
                 on: false,
                 action: { _ in
                     let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
-                    let permissions = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: canShare, andIsFolder: directory)
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
+                    let permissions = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: canShare, andIsFolder: isDirectory)
+                    self.updateSharePermissions(share: tableShare, permissions: permissions)
                 }
             )
         )
 
-        menuViewController.actions = actions
-
-        let menuPanelController = NCMenuPanelController()
-        menuPanelController.parentPresenter = viewController
-        menuPanelController.delegate = menuViewController
-        menuPanelController.set(contentViewController: menuViewController)
-        menuPanelController.track(scrollView: menuViewController.tableView)
-
-        viewController.present(menuPanelController, animated: true, completion: nil)
+        self.presentMenu(with: actions)
     }
 
     fileprivate func hasUploadPermission(tableShare: tableShare) -> Bool {
@@ -63,4 +51,10 @@ class NCShareQuickStatusMenu: NSObject {
             NCGlobal.shared.permissionDefaultFolderRemoteShareNoSupportShareOption]
         return uploadPermissions.contains(tableShare.permissions)
     }
+    
+    func updateSharePermissions(share: tableShare, permissions: Int) {
+        let updatedShare = tableShare(value: share)
+        updatedShare.permissions = permissions
+        networking?.updateShare(option: updatedShare)
+    }
 }