NCMedia+Menu.swift 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // NCMedia+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/03/2021.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import FloatingPanel
  25. extension NCMedia {
  26. func toggleMenu() {
  27. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  28. var actions: [NCMenuAction] = []
  29. if !isEditMode {
  30. if metadatas.count > 0 {
  31. actions.append(
  32. NCMenuAction(
  33. title: NSLocalizedString("_select_", comment: ""),
  34. icon: NCUtility.shared.loadImage(named: "checkmark.circle.fill"),
  35. action: { menuAction in
  36. self.isEditMode = true
  37. }
  38. )
  39. )
  40. }
  41. actions.append(
  42. NCMenuAction(
  43. title: NSLocalizedString(filterTypeFileImage ? "_media_viewimage_show_" : "_media_viewimage_hide_", comment: ""),
  44. icon: NCUtility.shared.loadImage(named: "photo"),
  45. selected: filterTypeFileImage,
  46. on: true,
  47. action: { menuAction in
  48. self.filterTypeFileImage = !self.filterTypeFileImage
  49. self.filterTypeFileVideo = false
  50. self.reloadDataSource()
  51. }
  52. )
  53. )
  54. actions.append(
  55. NCMenuAction(
  56. title: NSLocalizedString(filterTypeFileVideo ? "_media_viewvideo_show_" : "_media_viewvideo_hide_", comment: ""),
  57. icon: NCUtility.shared.loadImage(named: "video"),
  58. selected: filterTypeFileVideo,
  59. on: true,
  60. action: { menuAction in
  61. self.filterTypeFileVideo = !self.filterTypeFileVideo
  62. self.filterTypeFileImage = false
  63. self.reloadDataSource()
  64. }
  65. )
  66. )
  67. actions.append(
  68. NCMenuAction(
  69. title: NSLocalizedString("_select_media_folder_", comment: ""),
  70. icon: NCUtility.shared.loadImage(named: "folder"),
  71. action: { menuAction in
  72. let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as! UINavigationController
  73. let viewController = navigationController.topViewController as! NCSelect
  74. viewController.delegate = self
  75. viewController.typeOfCommandView = .select
  76. viewController.type = "mediaFolder"
  77. self.present(navigationController, animated: true, completion: nil)
  78. }
  79. )
  80. )
  81. actions.append(
  82. NCMenuAction(
  83. title: NSLocalizedString("_media_by_modified_date_", comment: ""),
  84. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.up.fill"),
  85. selected: CCUtility.getMediaSortDate() == "date",
  86. on: true,
  87. action: { menuAction in
  88. CCUtility.setMediaSortDate("date")
  89. self.reloadDataSource()
  90. }
  91. )
  92. )
  93. actions.append(
  94. NCMenuAction(
  95. title: NSLocalizedString("_media_by_created_date_", comment: ""),
  96. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.down.fill"),
  97. selected: CCUtility.getMediaSortDate() == "creationDate",
  98. on: true,
  99. action: { menuAction in
  100. CCUtility.setMediaSortDate("creationDate")
  101. self.reloadDataSource()
  102. }
  103. )
  104. )
  105. actions.append(
  106. NCMenuAction(
  107. title: NSLocalizedString("_media_by_upload_date_", comment: ""),
  108. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.right.fill"),
  109. selected: CCUtility.getMediaSortDate() == "uploadDate",
  110. on: true,
  111. action: { menuAction in
  112. CCUtility.setMediaSortDate("uploadDate")
  113. self.reloadDataSource()
  114. }
  115. )
  116. )
  117. } else {
  118. //
  119. // CANCEL
  120. //
  121. actions.append(
  122. NCMenuAction(
  123. title: NSLocalizedString("_cancel_", comment: ""),
  124. icon: NCUtility.shared.loadImage(named: "xmark"),
  125. action: { menuAction in
  126. self.isEditMode = false
  127. self.selectOcId.removeAll()
  128. self.reloadDataThenPerform { }
  129. }
  130. )
  131. )
  132. //
  133. // COPY - MOVE
  134. //
  135. actions.append(
  136. NCMenuAction(
  137. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  138. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  139. action: { menuAction in
  140. self.isEditMode = false
  141. var meradatasSelect = [tableMetadata]()
  142. for ocId in self.selectOcId {
  143. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  144. meradatasSelect.append(metadata)
  145. }
  146. }
  147. if meradatasSelect.count > 0 {
  148. NCFunctionCenter.shared.openSelectView(items: meradatasSelect, viewController: self)
  149. }
  150. self.selectOcId.removeAll()
  151. }
  152. )
  153. )
  154. //
  155. // DELETE
  156. //
  157. actions.append(
  158. NCMenuAction(
  159. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  160. icon: NCUtility.shared.loadImage(named: "trash"),
  161. action: { menuAction in
  162. self.isEditMode = false
  163. for ocId in self.selectOcId {
  164. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  165. NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
  166. if errorCode != 0 {
  167. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  168. }
  169. }
  170. }
  171. }
  172. self.selectOcId.removeAll()
  173. }
  174. )
  175. )
  176. }
  177. menuViewController.actions = actions
  178. let menuPanelController = NCMenuPanelController()
  179. menuPanelController.parentPresenter = self
  180. menuPanelController.delegate = menuViewController
  181. menuPanelController.set(contentViewController: menuViewController)
  182. menuPanelController.track(scrollView: menuViewController.tableView)
  183. self.present(menuPanelController, animated: true, completion: nil)
  184. }
  185. }