NCShareQuickStatusMenu.swift 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // NCShareQuickStatusMenu.swift
  3. // Nextcloud
  4. //
  5. // Created by TSI-mc on 30/06/21.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. import UIKit
  9. class NCShareQuickStatusMenu: NSObject {
  10. func toggleMenu(viewController: UIViewController, directory: Bool, tableShare: tableShare) {
  11. print(tableShare.permissions)
  12. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  13. var actions = [NCMenuAction]()
  14. // "_share_read_only_" = "Read only";
  15. // "_share_editing_" = "Editing";
  16. // "_share_allow_upload_" = "Allow upload and editing";
  17. // "_share_file_drop_" = "File drop (upload only)";
  18. actions.append(
  19. NCMenuAction(
  20. title: NSLocalizedString("_share_read_only_", comment: ""),
  21. icon: UIImage(),
  22. selected: tableShare.permissions == NCGlobal.shared.permissionReadShare + NCGlobal.shared.permissionShareShare,
  23. on: false,
  24. action: { menuAction in
  25. let permission = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: false, andIsFolder: directory)
  26. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermission, userInfo: ["idShare": tableShare.idShare, "permission": permission, "hideDownload": tableShare.hideDownload])
  27. }
  28. )
  29. )
  30. actions.append(
  31. NCMenuAction(
  32. title: directory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
  33. icon: UIImage(),
  34. selected: tableShare.permissions == NCGlobal.shared.permissionMaxFileShare || tableShare.permissions == NCGlobal.shared.permissionMaxFolderShare || tableShare.permissions == NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption,
  35. on: false,
  36. action: { menuAction in
  37. let permission = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: false, andIsFolder: directory)
  38. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermission, userInfo: ["idShare": tableShare.idShare, "permission": permission, "hideDownload": tableShare.hideDownload])
  39. }
  40. )
  41. )
  42. if directory {
  43. actions.append(
  44. NCMenuAction(
  45. title: NSLocalizedString("_share_file_drop_", comment: ""),
  46. icon: UIImage(),
  47. selected: tableShare.permissions == NCGlobal.shared.permissionCreateShare,
  48. on: false,
  49. action: { menuAction in
  50. let permission = NCGlobal.shared.permissionCreateShare
  51. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermission, userInfo: ["idShare": tableShare.idShare, "permission": permission, "hideDownload": tableShare.hideDownload])
  52. }
  53. )
  54. )
  55. }
  56. menuViewController.actions = actions
  57. let menuPanelController = NCMenuPanelController()
  58. menuPanelController.parentPresenter = viewController
  59. menuPanelController.delegate = menuViewController
  60. menuPanelController.set(contentViewController: menuViewController)
  61. menuPanelController.track(scrollView: menuViewController.tableView)
  62. viewController.present(menuPanelController, animated: true, completion: nil)
  63. }
  64. }