NCDetailNavigationController+Menu.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. //
  2. // NCDetailNavigationController+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/02/2020.
  6. // Copyright © 2020 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. import NCCommunication
  25. /*
  26. extension NCDetailNavigationController {
  27. @objc func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata) {
  28. if appDelegate.activeDetail.backgroundView.subviews.first == nil && appDelegate.activeDetail.viewerImageViewController == nil {
  29. return
  30. }
  31. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  32. if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
  33. mainMenuViewController.actions = self.initMoreMenu(viewController: viewController, metadata: metadata)
  34. } else {
  35. mainMenuViewController.actions = self.initMoreMenuClose(viewController: viewController)
  36. }
  37. let menuPanelController = NCMenuPanelController()
  38. menuPanelController.parentPresenter = viewController
  39. menuPanelController.delegate = mainMenuViewController
  40. menuPanelController.set(contentViewController: mainMenuViewController)
  41. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  42. viewController.present(menuPanelController, animated: true, completion: nil)
  43. }
  44. private func initMoreMenuClose(viewController: UIViewController) -> [NCMenuAction] {
  45. var actions = [NCMenuAction]()
  46. actions.append(
  47. NCMenuAction(title: NSLocalizedString("_close_", comment: ""),
  48. icon: CCGraphics.changeThemingColorImage(UIImage(named: "exit"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  49. action: { menuAction in
  50. NotificationCenter.default.postOnMainThread(name: k_notificationCenter_menuDetailClose)
  51. }
  52. )
  53. )
  54. return actions
  55. }
  56. private func initMoreMenu(viewController: UIViewController, metadata: tableMetadata) -> [NCMenuAction] {
  57. var actions = [NCMenuAction]()
  58. var titleFavorite = NSLocalizedString("_add_favorites_", comment: "")
  59. if metadata.favorite { titleFavorite = NSLocalizedString("_remove_favorites_", comment: "") }
  60. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  61. var titleOffline = ""
  62. if (localFile == nil || localFile!.offline == false) {
  63. titleOffline = NSLocalizedString("_set_available_offline_", comment: "")
  64. } else {
  65. titleOffline = NSLocalizedString("_remove_available_offline_", comment: "")
  66. }
  67. var titleDelete = NSLocalizedString("_delete_", comment: "")
  68. if NCManageDatabase.sharedInstance.isMetadataShareOrMounted(metadata: metadata, metadataFolder: nil) {
  69. titleDelete = NSLocalizedString("_leave_share_", comment: "")
  70. } else if metadata.directory {
  71. titleDelete = NSLocalizedString("_delete_folder_", comment: "")
  72. } else {
  73. titleDelete = NSLocalizedString("_delete_file_", comment: "")
  74. }
  75. //
  76. // FAVORITE
  77. //
  78. actions.append(
  79. NCMenuAction(
  80. title: titleFavorite,
  81. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  82. action: { menuAction in
  83. NCNetworking.shared.favoriteMetadata(metadata, urlBase: self.appDelegate.urlBase) { (errorCode, errorDescription) in
  84. if errorCode != 0 {
  85. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  86. }
  87. }
  88. }
  89. )
  90. )
  91. //
  92. // DETAIL
  93. //
  94. actions.append(
  95. NCMenuAction(
  96. title: NSLocalizedString("_details_", comment: ""),
  97. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  98. action: { menuAction in
  99. NCNetworkingNotificationCenter.shared.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  100. }
  101. )
  102. )
  103. //
  104. // OPEN IN
  105. //
  106. if metadata.session == "" {
  107. actions.append(
  108. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  109. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  110. action: { menuAction in
  111. NCNetworkingNotificationCenter.shared.downloadOpen(metadata: metadata, selector: selectorOpenInDetail)
  112. }
  113. )
  114. )
  115. }
  116. //
  117. // RENAME
  118. //
  119. actions.append(
  120. NCMenuAction(
  121. title: NSLocalizedString("_rename_", comment: ""),
  122. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  123. action: { menuAction in
  124. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  125. alertController.addTextField { (textField) in textField.text = metadata.fileNameView }
  126. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  127. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  128. let fileNameNew = alertController.textFields![0].text
  129. NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew!, urlBase: self.appDelegate.urlBase, viewController: self) { (errorCode, errorDescription) in
  130. if errorCode != 0 {
  131. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  132. }
  133. }
  134. })
  135. alertController.addAction(cancelAction)
  136. alertController.addAction(okAction)
  137. self.present(alertController, animated: true, completion: nil)
  138. }
  139. )
  140. )
  141. //
  142. // COPY - MOVE
  143. //
  144. actions.append(
  145. NCMenuAction(
  146. title: NSLocalizedString("_move_or_copy_", comment: ""),
  147. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  148. action: { menuAction in
  149. let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
  150. let navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
  151. let viewController = navigationController.topViewController as! NCSelect
  152. viewController.delegate = self.appDelegate.activeDetail
  153. viewController.hideButtonCreateFolder = false
  154. viewController.selectFile = false
  155. viewController.includeDirectoryE2EEncryption = false
  156. viewController.includeImages = false
  157. viewController.type = ""
  158. viewController.titleButtonDone = NSLocalizedString("_move_", comment: "")
  159. viewController.titleButtonDone1 = NSLocalizedString("_copy_", comment: "")
  160. viewController.isButtonDone1Hide = false
  161. viewController.isOverwriteHide = false
  162. navigationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
  163. self.present(navigationController, animated: true, completion: nil)
  164. }
  165. )
  166. )
  167. //
  168. // OFFLINE
  169. //
  170. if metadata.session == "" {
  171. actions.append(
  172. NCMenuAction(
  173. title: titleOffline,
  174. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  175. action: { menuAction in
  176. if ((localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) && metadata.session == "") {
  177. NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline) { (_) in }
  178. } else {
  179. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  180. }
  181. }
  182. )
  183. )
  184. }
  185. //
  186. // VIEW IN FOLDER
  187. //
  188. if appDelegate.activeFileViewInFolder == nil {
  189. actions.append(
  190. NCMenuAction(
  191. title: NSLocalizedString("_view_in_folder_", comment: ""),
  192. icon: CCGraphics.changeThemingColorImage(UIImage(named: "viewInFolder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  193. action: { menuAction in
  194. NCCollectionCommon.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileName: metadata.fileName)
  195. }
  196. )
  197. )
  198. }
  199. //
  200. // DELETE
  201. //
  202. actions.append(
  203. NCMenuAction(title: titleDelete,
  204. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  205. action: { menuAction in
  206. let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  207. alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  208. NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
  209. if errorCode != 0 {
  210. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  211. }
  212. }
  213. })
  214. alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
  215. self.present(alertController, animated: true, completion:nil)
  216. }
  217. )
  218. )
  219. //
  220. // PDF
  221. //
  222. if (metadata.typeFile == k_metadataTypeFile_document && metadata.contentType == "application/pdf" ) {
  223. actions.append(
  224. NCMenuAction(title: NSLocalizedString("_search_", comment: ""),
  225. icon: CCGraphics.changeThemingColorImage(UIImage(named: "search"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  226. action: { menuAction in
  227. NotificationCenter.default.postOnMainThread(name: k_notificationCenter_menuSearchTextPDF)
  228. }
  229. )
  230. )
  231. }
  232. //
  233. // IMAGE - VIDEO - AUDIO
  234. //
  235. if metadata.session == "" {
  236. if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) && !CCUtility.fileProviderStorageExists(appDelegate.activeDetail.metadata?.ocId, fileNameView: appDelegate.activeDetail.metadata?.fileNameView) && metadata.session == "" && metadata.typeFile == k_metadataTypeFile_image {
  237. actions.append(
  238. NCMenuAction(title: NSLocalizedString("_download_image_max_", comment: ""),
  239. icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadImageFullRes"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  240. action: { menuAction in
  241. NotificationCenter.default.postOnMainThread(name: k_notificationCenter_menuDownloadImage, userInfo: ["metadata": metadata])
  242. }
  243. )
  244. )
  245. }
  246. }
  247. if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio {
  248. if let metadataLive = NCManageDatabase.sharedInstance.isLivePhoto(metadata: metadata) {
  249. if CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView) > 0 && CCUtility.fileProviderStorageSize(metadataLive.ocId, fileNameView: metadataLive.fileNameView) > 0 {
  250. actions.append(
  251. NCMenuAction(title: NSLocalizedString("_livephoto_save_", comment: ""),
  252. icon: CCGraphics.changeThemingColorImage(UIImage(named: "livePhoto"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  253. action: { menuAction in
  254. NotificationCenter.default.postOnMainThread(name: k_notificationCenter_menuSaveLivePhoto, userInfo: ["metadata": metadata, "metadataMov": metadataLive])
  255. }
  256. )
  257. )
  258. }
  259. }
  260. }
  261. //
  262. // CLOSE
  263. //
  264. actions.append(
  265. NCMenuAction(title: NSLocalizedString("_close_", comment: ""),
  266. icon: CCGraphics.changeThemingColorImage(UIImage(named: "exit"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  267. action: { menuAction in
  268. NotificationCenter.default.postOnMainThread(name: k_notificationCenter_menuDetailClose)
  269. }
  270. )
  271. )
  272. return actions
  273. }
  274. }
  275. */