NCMedia+Menu.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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: UIImage(named: "selectFull")!.image(color: NCBrandColor.shared.icon, size: 50),
  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: UIImage(named: filterTypeFileImage ? "imageno" : "imageyes")!.image(color: NCBrandColor.shared.icon, size: 50),
  44. action: { menuAction in
  45. self.filterTypeFileImage = !self.filterTypeFileImage
  46. self.filterTypeFileVideo = false
  47. self.reloadDataSource()
  48. }
  49. )
  50. )
  51. actions.append(
  52. NCMenuAction(
  53. title: NSLocalizedString(filterTypeFileVideo ? "_media_viewvideo_show_" : "_media_viewvideo_hide_", comment: ""),
  54. icon: UIImage(named: filterTypeFileVideo ? "videono" : "videoyes")!.image(color: NCBrandColor.shared.icon, size: 50),
  55. action: { menuAction in
  56. self.filterTypeFileVideo = !self.filterTypeFileVideo
  57. self.filterTypeFileImage = false
  58. self.reloadDataSource()
  59. }
  60. )
  61. )
  62. actions.append(
  63. NCMenuAction(
  64. title: NSLocalizedString("_select_media_folder_", comment: ""),
  65. icon: UIImage(named: "folderAutomaticUpload")!.image(color: NCBrandColor.shared.icon, size: 50),
  66. action: { menuAction in
  67. let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as! UINavigationController
  68. let viewController = navigationController.topViewController as! NCSelect
  69. viewController.delegate = self
  70. viewController.hideButtonCreateFolder = true
  71. viewController.includeDirectoryE2EEncryption = false
  72. viewController.includeImages = false
  73. viewController.selectFile = false
  74. viewController.titleButtonDone = NSLocalizedString("_select_", comment: "")
  75. viewController.type = "mediaFolder"
  76. navigationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
  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: UIImage(named: "sortModifiedDate")!.image(color: NCBrandColor.shared.icon, size: 50),
  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: UIImage(named: "sortCreatedDate")!.image(color: NCBrandColor.shared.icon, size: 50),
  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: UIImage(named: "sortUploadDate")!.image(color: NCBrandColor.shared.icon, size: 50),
  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. actions.append(
  119. NCMenuAction(
  120. title: NSLocalizedString("_cancel_", comment: ""),
  121. icon: UIImage(named: "cancel")!.image(color: NCBrandColor.shared.icon, size: 50),
  122. action: { menuAction in
  123. self.isEditMode = false
  124. self.selectOcId.removeAll()
  125. self.reloadDataThenPerform { }
  126. }
  127. )
  128. )
  129. //
  130. // COPY - MOVE
  131. //
  132. actions.append(
  133. NCMenuAction(
  134. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  135. icon: UIImage(named: "move")!.image(color: NCBrandColor.shared.icon, size: 50),
  136. action: { menuAction in
  137. self.isEditMode = false
  138. var meradatasSelect = [tableMetadata]()
  139. for ocId in self.selectOcId {
  140. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  141. meradatasSelect.append(metadata)
  142. }
  143. }
  144. if meradatasSelect.count > 0 {
  145. NCCollectionCommon.shared.openSelectView(items: meradatasSelect, viewController: self)
  146. }
  147. self.selectOcId.removeAll()
  148. }
  149. )
  150. )
  151. //
  152. // DELETE
  153. //
  154. actions.append(
  155. NCMenuAction(
  156. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  157. icon: UIImage(named: "trash")!.image(color: NCBrandColor.shared.icon, size: 50),
  158. action: { menuAction in
  159. self.isEditMode = false
  160. for ocId in self.selectOcId {
  161. if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  162. NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
  163. if errorCode != 0 {
  164. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  165. }
  166. }
  167. }
  168. }
  169. self.selectOcId.removeAll()
  170. }
  171. )
  172. )
  173. }
  174. menuViewController.actions = actions
  175. let menuPanelController = NCMenuPanelController()
  176. menuPanelController.parentPresenter = self
  177. menuPanelController.delegate = menuViewController
  178. menuPanelController.set(contentViewController: menuViewController)
  179. menuPanelController.track(scrollView: menuViewController.tableView)
  180. self.present(menuPanelController, animated: true, completion: nil)
  181. }
  182. }