NCShareQuickStatusMenu.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // @objc let permissionReadShare: Int = 1
  19. // @objc let permissionUpdateShare: Int = 2
  20. // @objc let permissionCreateShare: Int = 4
  21. // @objc let permissionDeleteShare: Int = 8
  22. // @objc let permissionShareShare: Int = 16
  23. // @objc let permissionMinFileShare: Int = 1
  24. // @objc let permissionMaxFileShare: Int = 19
  25. // @objc let permissionMinFolderShare: Int = 1
  26. // @objc let permissionMaxFolderShare: Int = 31
  27. // @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3
  28. // @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15
  29. actions.append(
  30. NCMenuAction(
  31. title: NSLocalizedString("_share_read_only_", comment: ""),
  32. icon: UIImage(),
  33. selected: tableShare.permissions == (NCGlobal.shared.permissionReadShare + NCGlobal.shared.permissionShareShare) || tableShare.permissions == NCGlobal.shared.permissionReadShare,
  34. on: false,
  35. action: { menuAction in
  36. let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
  37. let permissions = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: canShare, andIsFolder: directory)
  38. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
  39. }
  40. )
  41. )
  42. actions.append(
  43. NCMenuAction(
  44. title: directory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
  45. icon: UIImage(),
  46. selected: tableShare.permissions == NCGlobal.shared.permissionMaxFileShare || tableShare.permissions == NCGlobal.shared.permissionMaxFolderShare || tableShare.permissions == NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption,
  47. on: false,
  48. action: { menuAction in
  49. let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions)
  50. let permissions = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: canShare, andIsFolder: directory)
  51. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
  52. }
  53. )
  54. )
  55. /*
  56. if directory {
  57. actions.append(
  58. NCMenuAction(
  59. title: NSLocalizedString("_share_file_drop_", comment: ""),
  60. icon: UIImage(),
  61. selected: tableShare.permissions == NCGlobal.shared.permissionCreateShare,
  62. on: false,
  63. action: { menuAction in
  64. let permissions = NCGlobal.shared.permissionCreateShare
  65. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShareChangePermissions, userInfo: ["idShare": tableShare.idShare, "permissions": permissions, "hideDownload": tableShare.hideDownload])
  66. }
  67. )
  68. )
  69. }
  70. */
  71. menuViewController.actions = actions
  72. let menuPanelController = NCMenuPanelController()
  73. menuPanelController.parentPresenter = viewController
  74. menuPanelController.delegate = menuViewController
  75. menuPanelController.set(contentViewController: menuViewController)
  76. menuPanelController.track(scrollView: menuViewController.tableView)
  77. viewController.present(menuPanelController, animated: true, completion: nil)
  78. }
  79. }