NCMedia+Menu.swift 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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-search-outline"),
  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.hideButtonCreateFolder = true
  75. viewController.includeDirectoryE2EEncryption = false
  76. viewController.includeImages = false
  77. viewController.selectFile = false
  78. viewController.titleButtonDone = NSLocalizedString("_select_", comment: "")
  79. viewController.type = "mediaFolder"
  80. navigationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
  81. self.present(navigationController, animated: true, completion: nil)
  82. }
  83. )
  84. )
  85. actions.append(
  86. NCMenuAction(
  87. title: NSLocalizedString("_media_by_modified_date_", comment: ""),
  88. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.up.fill"),
  89. selected: CCUtility.getMediaSortDate() == "date",
  90. on: true,
  91. action: { menuAction in
  92. CCUtility.setMediaSortDate("date")
  93. self.reloadDataSource()
  94. }
  95. )
  96. )
  97. actions.append(
  98. NCMenuAction(
  99. title: NSLocalizedString("_media_by_created_date_", comment: ""),
  100. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.down.fill"),
  101. selected: CCUtility.getMediaSortDate() == "creationDate",
  102. on: true,
  103. action: { menuAction in
  104. CCUtility.setMediaSortDate("creationDate")
  105. self.reloadDataSource()
  106. }
  107. )
  108. )
  109. actions.append(
  110. NCMenuAction(
  111. title: NSLocalizedString("_media_by_upload_date_", comment: ""),
  112. icon: NCUtility.shared.loadImage(named: "circle.grid.cross.right.fill"),
  113. selected: CCUtility.getMediaSortDate() == "uploadDate",
  114. on: true,
  115. action: { menuAction in
  116. CCUtility.setMediaSortDate("uploadDate")
  117. self.reloadDataSource()
  118. }
  119. )
  120. )
  121. } else {
  122. //
  123. // CANCEL
  124. //
  125. actions.append(
  126. NCMenuAction(
  127. title: NSLocalizedString("_cancel_", comment: ""),
  128. icon: NCUtility.shared.loadImage(named: "xmark"),
  129. action: { menuAction in
  130. self.isEditMode = false
  131. self.selectOcId.removeAll()
  132. self.reloadDataThenPerform { }
  133. }
  134. )
  135. )
  136. //
  137. // COPY - MOVE
  138. //
  139. actions.append(
  140. NCMenuAction(
  141. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  142. icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
  143. action: { menuAction in
  144. self.isEditMode = false
  145. var meradatasSelect = [tableMetadata]()
  146. for ocId in self.selectOcId {
  147. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  148. meradatasSelect.append(metadata)
  149. }
  150. }
  151. if meradatasSelect.count > 0 {
  152. NCFunctionCenter.shared.openSelectView(items: meradatasSelect, viewController: self)
  153. }
  154. self.selectOcId.removeAll()
  155. }
  156. )
  157. )
  158. //
  159. // DELETE
  160. //
  161. actions.append(
  162. NCMenuAction(
  163. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  164. icon: NCUtility.shared.loadImage(named: "trash"),
  165. action: { menuAction in
  166. self.isEditMode = false
  167. for ocId in self.selectOcId {
  168. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  169. NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
  170. if errorCode != 0 {
  171. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  172. }
  173. }
  174. }
  175. }
  176. self.selectOcId.removeAll()
  177. }
  178. )
  179. )
  180. }
  181. menuViewController.actions = actions
  182. let menuPanelController = NCMenuPanelController()
  183. menuPanelController.parentPresenter = self
  184. menuPanelController.delegate = menuViewController
  185. menuPanelController.set(contentViewController: menuViewController)
  186. menuPanelController.track(scrollView: menuViewController.tableView)
  187. self.present(menuPanelController, animated: true, completion: nil)
  188. }
  189. }