NCShareQuickStatusMenu.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, status: Int) {
  11. print(status)
  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: status == NCGlobal.shared.permissionReadShare + NCGlobal.shared.permissionShareShare,
  23. on: false,
  24. action: { menuAction in
  25. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterSharePermissionReadOnly)
  26. }
  27. )
  28. )
  29. actions.append(
  30. NCMenuAction(
  31. title: directory ? NSLocalizedString("_share_allow_upload_", comment: "") : NSLocalizedString("_share_editing_", comment: ""),
  32. icon: UIImage(),
  33. selected: status == NCGlobal.shared.permissionMaxFileShare || status == NCGlobal.shared.permissionMaxFolderShare || status == NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption,
  34. on: false,
  35. action: { menuAction in
  36. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterSharePermissionEditing)
  37. }
  38. )
  39. )
  40. if directory {
  41. actions.append(
  42. NCMenuAction(
  43. title: NSLocalizedString("_share_file_drop_", comment: ""),
  44. icon: UIImage(),
  45. selected: status == NCGlobal.shared.permissionCreateShare,
  46. on: false,
  47. action: { menuAction in
  48. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterSharePermissionFileDrop)
  49. }
  50. )
  51. )
  52. }
  53. menuViewController.actions = actions
  54. let menuPanelController = NCMenuPanelController()
  55. menuPanelController.parentPresenter = viewController
  56. menuPanelController.delegate = menuViewController
  57. menuPanelController.set(contentViewController: menuViewController)
  58. menuPanelController.track(scrollView: menuViewController.tableView)
  59. viewController.present(menuPanelController, animated: true, completion: nil)
  60. }
  61. }