NCMedia+Menu.swift 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 FloatingPanel
  24. extension NCMedia {
  25. func toggleMenu() {
  26. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  27. var actions: [NCMenuAction] = []
  28. if !isEditMode {
  29. if metadatas.count > 0 {
  30. actions.append(
  31. NCMenuAction(
  32. title: NSLocalizedString("_select_", comment: ""),
  33. icon: NCUtility.shared.loadImage(named: "checkmark.circle.fill"),
  34. action: { menuAction in
  35. self.isEditMode = true
  36. }
  37. )
  38. )
  39. }
  40. actions.append(
  41. NCMenuAction(
  42. title: NSLocalizedString(filterTypeFileImage ? "_media_viewimage_show_" : "_media_viewimage_hide_", comment: ""),
  43. icon: NCUtility.shared.loadImage(named: "photo"),
  44. selected: filterTypeFileImage,
  45. on: true,
  46. action: { menuAction in
  47. self.filterTypeFileImage = !self.filterTypeFileImage
  48. self.filterTypeFileVideo = false
  49. self.reloadDataSource()
  50. }
  51. )
  52. )
  53. actions.append(
  54. NCMenuAction(
  55. title: NSLocalizedString(filterTypeFileVideo ? "_media_viewvideo_show_" : "_media_viewvideo_hide_", comment: ""),
  56. icon: NCUtility.shared.loadImage(named: "video"),
  57. selected: filterTypeFileVideo,
  58. on: true,
  59. action: { menuAction in
  60. self.filterTypeFileVideo = !self.filterTypeFileVideo
  61. self.filterTypeFileImage = false
  62. self.reloadDataSource()
  63. }
  64. )
  65. )
  66. actions.append(
  67. NCMenuAction(
  68. title: NSLocalizedString("_select_media_folder_", comment: ""),
  69. icon: NCUtility.shared.loadImage(named: "folder"),
  70. action: { menuAction in
  71. let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as! UINavigationController
  72. let viewController = navigationController.topViewController as! NCSelect
  73. viewController.delegate = self
  74. viewController.typeOfCommandView = .select
  75. viewController.type = "mediaFolder"
  76. self.present(navigationController, animated: true, completion: nil)
  77. }
  78. )
  79. )
  80. actions.append(
  81. NCMenuAction(
  82. title: NSLocalizedString("_media_by_modified_date_", comment: ""),
  83. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.up.fill"),
  84. selected: CCUtility.getMediaSortDate() == "date",
  85. on: true,
  86. action: { menuAction in
  87. CCUtility.setMediaSortDate("date")
  88. self.reloadDataSource()
  89. }
  90. )
  91. )
  92. actions.append(
  93. NCMenuAction(
  94. title: NSLocalizedString("_media_by_created_date_", comment: ""),
  95. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.down.fill"),
  96. selected: CCUtility.getMediaSortDate() == "creationDate",
  97. on: true,
  98. action: { menuAction in
  99. CCUtility.setMediaSortDate("creationDate")
  100. self.reloadDataSource()
  101. }
  102. )
  103. )
  104. actions.append(
  105. NCMenuAction(
  106. title: NSLocalizedString("_media_by_upload_date_", comment: ""),
  107. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.right.fill"),
  108. selected: CCUtility.getMediaSortDate() == "uploadDate",
  109. on: true,
  110. action: { menuAction in
  111. CCUtility.setMediaSortDate("uploadDate")
  112. self.reloadDataSource()
  113. }
  114. )
  115. )
  116. } else {
  117. //
  118. // CANCEL
  119. //
  120. actions.append(
  121. NCMenuAction(
  122. title: NSLocalizedString("_cancel_", comment: ""),
  123. icon: NCUtility.shared.loadImage(named: "xmark"),
  124. action: { menuAction in
  125. self.isEditMode = false
  126. self.selectOcId.removeAll()
  127. self.reloadDataThenPerform { }
  128. }
  129. )
  130. )
  131. //
  132. // COPY - MOVE
  133. //
  134. actions.append(
  135. NCMenuAction(
  136. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  137. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  138. action: { menuAction in
  139. self.isEditMode = false
  140. var meradatasSelect = [tableMetadata]()
  141. for ocId in self.selectOcId {
  142. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  143. meradatasSelect.append(metadata)
  144. }
  145. }
  146. if meradatasSelect.count > 0 {
  147. NCFunctionCenter.shared.openSelectView(items: meradatasSelect, viewController: self)
  148. }
  149. self.selectOcId.removeAll()
  150. }
  151. )
  152. )
  153. //
  154. // DELETE
  155. //
  156. actions.append(
  157. NCMenuAction(
  158. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  159. icon: NCUtility.shared.loadImage(named: "trash"),
  160. action: { menuAction in
  161. self.isEditMode = false
  162. for ocId in self.selectOcId {
  163. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  164. NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
  165. if errorCode != 0 {
  166. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  167. }
  168. }
  169. }
  170. }
  171. self.selectOcId.removeAll()
  172. }
  173. )
  174. )
  175. }
  176. menuViewController.actions = actions
  177. let menuPanelController = NCMenuPanelController()
  178. menuPanelController.parentPresenter = self
  179. menuPanelController.delegate = menuViewController
  180. menuPanelController.set(contentViewController: menuViewController)
  181. menuPanelController.track(scrollView: menuViewController.tableView)
  182. self.present(menuPanelController, animated: true, completion: nil)
  183. }
  184. }