CCFavorites+Menu.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // CCFavorites+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.01.20.
  6. // Copyright © 2020 Philippe Weidmann. All rights reserved.
  7. // Copyright © 2020 Marino Faggiana All rights reserved.
  8. //
  9. // Author Philippe Weidmann
  10. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import FloatingPanel
  26. extension CCFavorites {
  27. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata) -> [NCMenuAction] {
  28. var actions = [NCMenuAction]()
  29. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  30. var iconHeader: UIImage!
  31. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  32. iconHeader = icon
  33. } else {
  34. if(metadata.directory) {
  35. iconHeader = CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  36. } else {
  37. iconHeader = UIImage(named: metadata.iconName)
  38. }
  39. }
  40. actions.append(
  41. NCMenuAction(
  42. title: metadata.fileNameView,
  43. icon: iconHeader,
  44. action: nil
  45. )
  46. )
  47. if(self.serverUrl == nil) {
  48. actions.append(
  49. NCMenuAction(
  50. title: NSLocalizedString("_remove_favorites_", comment: ""),
  51. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  52. action: { menuAction in
  53. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  54. }
  55. )
  56. )
  57. }
  58. actions.append(
  59. NCMenuAction(
  60. title: NSLocalizedString("_details_", comment: ""),
  61. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  62. action: { menuAction in
  63. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  64. }
  65. )
  66. )
  67. if(!metadata.directory && !NCBrandOptions.sharedInstance.disable_openin_file) {
  68. actions.append(
  69. NCMenuAction(
  70. title: NSLocalizedString("_open_in_", comment: ""),
  71. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  72. action: { menuAction in
  73. self.tableView.setEditing(false, animated: true)
  74. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  75. }
  76. )
  77. )
  78. }
  79. actions.append(
  80. NCMenuAction(
  81. title: NSLocalizedString("_delete_", comment: ""),
  82. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  83. action: { menuAction in
  84. self.actionDelete(indexPath)
  85. }
  86. )
  87. )
  88. return actions
  89. }
  90. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata) {
  91. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  92. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata)
  93. let menuPanelController = NCMenuPanelController()
  94. menuPanelController.parentPresenter = viewController
  95. menuPanelController.delegate = mainMenuViewController
  96. menuPanelController.set(contentViewController: mainMenuViewController)
  97. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  98. viewController.present(menuPanelController, animated: true, completion: nil)
  99. }
  100. }