NCCollectionViewCommon+Menu.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // NCCollectionViewCommon+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 NCCollectionViewCommon {
  27. func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata) {
  28. if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
  29. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  30. mainMenuViewController.actions = self.initMoreMenu(metadata: metadata, viewController: viewController)
  31. let menuPanelController = NCMenuPanelController()
  32. menuPanelController.parentPresenter = viewController
  33. menuPanelController.delegate = mainMenuViewController
  34. menuPanelController.set(contentViewController: mainMenuViewController)
  35. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  36. viewController.present(menuPanelController, animated: true, completion: nil)
  37. }
  38. }
  39. private func initMoreMenu(metadata: tableMetadata, viewController: UIViewController) -> [NCMenuAction] {
  40. var actions = [NCMenuAction]()
  41. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  42. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl+"/"+metadata.fileName, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
  43. var iconHeader: UIImage!
  44. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
  45. iconHeader = icon
  46. } else {
  47. if metadata.directory {
  48. iconHeader = CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  49. } else {
  50. iconHeader = UIImage(named: metadata.iconName)
  51. }
  52. }
  53. actions.append(
  54. NCMenuAction(
  55. title: metadata.fileNameView,
  56. icon: iconHeader,
  57. action: nil
  58. )
  59. )
  60. // Favorite
  61. if layoutKey == k_layout_view_favorite && serverUrl == "" {
  62. actions.append(
  63. NCMenuAction(
  64. title: NSLocalizedString("_remove_favorites_", comment: ""),
  65. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  66. action: { menuAction in
  67. NCNetworking.shared.favoriteMetadata(metadata, urlBase: appDelegate.urlBase) { (errorCode, errorDescription) in }
  68. }
  69. )
  70. )
  71. }
  72. // Offline
  73. if layoutKey == k_layout_view_offline && self.serverUrl == "" {
  74. actions.append(
  75. NCMenuAction(
  76. title: NSLocalizedString("_remove_available_offline_", comment: ""),
  77. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  78. action: { menuAction in
  79. if metadata.directory {
  80. NCManageDatabase.sharedInstance.setDirectory(serverUrl: CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!, offline: false, account: self.appDelegate.account)
  81. } else {
  82. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: false)
  83. }
  84. self.reloadDataSource()
  85. }
  86. )
  87. )
  88. }
  89. // All
  90. actions.append(
  91. NCMenuAction(
  92. title: NSLocalizedString("_details_", comment: ""),
  93. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  94. action: { menuAction in
  95. NCMainCommon.shared.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  96. }
  97. )
  98. )
  99. if !metadata.directory && !NCBrandOptions.sharedInstance.disable_openin_file {
  100. actions.append(
  101. NCMenuAction(
  102. title: NSLocalizedString("_open_in_", comment: ""),
  103. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  104. action: { menuAction in
  105. NCMainCommon.shared.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  106. }
  107. )
  108. )
  109. }
  110. /*
  111. if !isFolderEncrypted && serverUrl != "" {
  112. actions.append(
  113. NCMenuAction(
  114. title: NSLocalizedString("_move_or_copy_", comment: ""),
  115. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  116. action: { menuAction in
  117. NCCollectionCommon.shared.openSelectView(viewController: viewController, array: [metadata])
  118. }
  119. )
  120. )
  121. }
  122. */
  123. actions.append(
  124. NCMenuAction(
  125. title: NSLocalizedString("_delete_", comment: ""),
  126. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  127. action: { menuAction in
  128. let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  129. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  130. NCNetworking.shared.deleteMetadata(metadata, account: metadata.account, urlBase: metadata.urlBase, onlyLocal: false) { (errorCode, errorDescription) in }
  131. })
  132. alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (action:UIAlertAction) in
  133. NCNetworking.shared.deleteMetadata(metadata, account: metadata.account, urlBase: metadata.urlBase, onlyLocal: true) { (errorCode, errorDescription) in }
  134. })
  135. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
  136. self.present(alertController, animated: true, completion:nil)
  137. }
  138. )
  139. )
  140. return actions
  141. }
  142. }