CCMain+Menu.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. //
  2. // CCMain+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.01.20.
  6. // Copyright © 2020 Philippe Weidmann. All rights reserved.
  7. // Copyright © 2020 Marino Faggiana All rights reserved.
  8. //
  9. // Author Philippe Weidmann <philippe.weidmann@infomaniak.com>
  10. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import FloatingPanel
  26. extension CCMain {
  27. private func initSortMenu() -> [NCMenuAction] {
  28. var actions = [NCMenuAction]()
  29. actions.append(
  30. NCMenuAction(
  31. title: NSLocalizedString("_order_by_name_a_z_", comment: ""),
  32. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortFileNameAZ"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  33. onTitle: NSLocalizedString("_order_by_name_z_a_", comment: ""),
  34. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortFileNameZA"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  35. selected: CCUtility.getOrderSettings() == "fileName",
  36. on: CCUtility.getAscendingSettings(),
  37. action: { menuAction in
  38. if(CCUtility.getOrderSettings() == "fileName") {
  39. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  40. } else {
  41. CCUtility.setOrderSettings("fileName")
  42. }
  43. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  44. }
  45. )
  46. )
  47. actions.append(
  48. NCMenuAction(
  49. title: NSLocalizedString("_order_by_date_more_recent_", comment: ""),
  50. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateMoreRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  51. onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
  52. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateLessRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  53. selected: CCUtility.getOrderSettings() == "date",
  54. on: CCUtility.getAscendingSettings(),
  55. action: { menuAction in
  56. if(CCUtility.getOrderSettings() == "date") {
  57. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  58. } else {
  59. CCUtility.setOrderSettings("date")
  60. }
  61. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  62. }
  63. )
  64. )
  65. actions.append(
  66. NCMenuAction(
  67. title: NSLocalizedString("_order_by_size_smallest_", comment: ""),
  68. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortSmallest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  69. onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
  70. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortLargest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  71. selected: CCUtility.getOrderSettings() == "size",
  72. on: CCUtility.getAscendingSettings(),
  73. action: { menuAction in
  74. if(CCUtility.getOrderSettings() == "size") {
  75. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  76. } else {
  77. CCUtility.setOrderSettings("size")
  78. }
  79. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  80. }
  81. )
  82. )
  83. actions.append(
  84. NCMenuAction(
  85. title: NSLocalizedString("_directory_on_top_no_", comment: ""),
  86. icon: CCGraphics.changeThemingColorImage(UIImage(named: "foldersOnTop"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  87. selected: CCUtility.getDirectoryOnTop(),
  88. on: CCUtility.getDirectoryOnTop(),
  89. action: { menuAction in
  90. CCUtility.setDirectoryOnTop(!CCUtility.getDirectoryOnTop())
  91. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_clearDateReadDataSource), object: nil)
  92. }
  93. )
  94. )
  95. return actions
  96. }
  97. @objc func toggleMenu(viewController: UIViewController) {
  98. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  99. mainMenuViewController.actions = self.initSortMenu()
  100. let menuPanelController = NCMenuPanelController()
  101. menuPanelController.parentPresenter = viewController
  102. menuPanelController.delegate = mainMenuViewController
  103. menuPanelController.set(contentViewController: mainMenuViewController)
  104. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  105. viewController.present(menuPanelController, animated: true, completion: nil)
  106. }
  107. @objc func toggleSelectMenu(viewController: UIViewController) {
  108. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  109. mainMenuViewController.actions = self.initSelectMenu()
  110. let menuPanelController = NCMenuPanelController()
  111. menuPanelController.parentPresenter = viewController
  112. menuPanelController.delegate = mainMenuViewController
  113. menuPanelController.set(contentViewController: mainMenuViewController)
  114. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  115. viewController.present(menuPanelController, animated: true, completion: nil)
  116. }
  117. private func initSelectMenu() -> [NCMenuAction] {
  118. var actions = [NCMenuAction]()
  119. actions.append(
  120. NCMenuAction(
  121. title: NSLocalizedString("_select_all_", comment: ""),
  122. icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  123. action: { menuAction in
  124. self.didSelectAll()
  125. }
  126. )
  127. )
  128. actions.append(
  129. NCMenuAction(
  130. title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
  131. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  132. action: { menuAction in
  133. self.moveOpenWindow(self.tableView.indexPathsForSelectedRows)
  134. }
  135. )
  136. )
  137. actions.append(
  138. NCMenuAction(
  139. title: NSLocalizedString("_download_selected_files_folders_", comment: ""),
  140. icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  141. action: { menuAction in
  142. self.downloadSelectedFilesFolders()
  143. }
  144. )
  145. )
  146. actions.append(
  147. NCMenuAction(
  148. title: NSLocalizedString("_save_selected_files_", comment: ""),
  149. icon: CCGraphics.changeThemingColorImage(UIImage(named: "saveSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  150. action: { menuAction in
  151. self.saveSelectedFiles()
  152. }
  153. )
  154. )
  155. actions.append(
  156. NCMenuAction(
  157. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  158. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  159. action: { menuAction in
  160. self.deleteMetadatas()
  161. }
  162. )
  163. )
  164. return actions
  165. }
  166. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) -> [NCMenuAction] {
  167. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  168. let autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
  169. let autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(appDelegate.activeUrl)
  170. var actions = [NCMenuAction]()
  171. if (metadata.directory) {
  172. var isDirectoryLock = false
  173. var isOffline = false
  174. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl+"/"+metadata.fileName, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
  175. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!)) {
  176. if (directory.lock && CCUtility.getBlockCode() != nil && appDelegate.sessionePasscodeLock == nil) {
  177. isDirectoryLock = true
  178. }
  179. isOffline = directory.offline
  180. }
  181. actions.append(
  182. NCMenuAction(
  183. title: metadata.fileNameView,
  184. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
  185. action: nil
  186. )
  187. )
  188. actions.append(
  189. NCMenuAction(
  190. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  191. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  192. action: { menuAction in
  193. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  194. }
  195. )
  196. )
  197. if (!isDirectoryLock && !isFolderEncrypted) {
  198. actions.append(
  199. NCMenuAction(
  200. title: NSLocalizedString("_details_", comment: ""),
  201. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  202. action: { menuAction in
  203. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  204. }
  205. )
  206. )
  207. }
  208. if(!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !isDirectoryLock && !metadata.e2eEncrypted) {
  209. actions.append(
  210. NCMenuAction(
  211. title: NSLocalizedString("_rename_", comment: ""),
  212. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  213. action: { menuAction in
  214. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  215. alertController.addTextField { (textField) in
  216. textField.text = metadata.fileNameView
  217. textField.delegate = self as? UITextFieldDelegate
  218. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  219. ), for: UIControl.Event.editingChanged)
  220. }
  221. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  222. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  223. let fileNameNew = alertController.textFields![0].text
  224. NCNetworking.sharedInstance.renameMetadata(metadata, fileNameNew: fileNameNew!, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  225. })
  226. okAction.isEnabled = false
  227. alertController.addAction(cancelAction)
  228. alertController.addAction(okAction)
  229. self.present(alertController, animated: true, completion: nil)
  230. }
  231. )
  232. )
  233. }
  234. if (!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !isDirectoryLock && !isFolderEncrypted) {
  235. actions.append(
  236. NCMenuAction(
  237. title: NSLocalizedString("_move_or_copy_", comment: ""),
  238. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  239. action: { menuAction in
  240. self.moveOpenWindow([indexPath])
  241. }
  242. )
  243. )
  244. }
  245. if (!isFolderEncrypted) {
  246. actions.append(
  247. NCMenuAction(
  248. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  249. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  250. action: { menuAction in
  251. let serverUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
  252. NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, offline: !isOffline, account: appDelegate.activeAccount)
  253. if(isOffline) {
  254. CCSynchronize.shared()?.readFolder(serverUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  255. }
  256. DispatchQueue.main.async {
  257. self.tableView.reloadRows(at: [indexPath], with: .none)
  258. }
  259. }
  260. )
  261. )
  262. }
  263. actions.append(
  264. NCMenuAction(
  265. title: isDirectoryLock ? NSLocalizedString("_remove_passcode_", comment: "") : NSLocalizedString("_protect_passcode_", comment: ""),
  266. icon: CCGraphics.changeThemingColorImage(UIImage(named: "settingsPasscodeYES"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  267. action: { menuAction in
  268. self.perform(#selector(self.comandoLockPassword))
  269. }
  270. )
  271. )
  272. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  273. actions.append(
  274. NCMenuAction(
  275. title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
  276. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  277. action: { menuAction in
  278. DispatchQueue.global(qos: .userInitiated).async {
  279. let error = NCNetworkingEndToEnd.sharedManager()?.markFolderEncrypted(onServerUrl: "\(self.serverUrl ?? "")/\(metadata.fileName)", ocId: metadata.ocId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  280. DispatchQueue.main.async {
  281. if(error != nil) {
  282. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  283. } else {
  284. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  285. self.readFolder(self.serverUrl)
  286. }
  287. }
  288. }
  289. }
  290. )
  291. )
  292. }
  293. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  294. actions.append(
  295. NCMenuAction(
  296. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  297. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  298. action: { menuAction in
  299. DispatchQueue.global(qos: .userInitiated).async {
  300. let error = NCNetworkingEndToEnd.sharedManager()?.deletemarkEndToEndFolderEncrypted(onServerUrl: "\(self.serverUrl ?? "")/\(metadata.fileName)", ocId: metadata.ocId, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl)
  301. DispatchQueue.main.async {
  302. if(error != nil) {
  303. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  304. } else {
  305. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  306. self.readFolder(self.serverUrl)
  307. }
  308. }
  309. }
  310. }
  311. )
  312. )
  313. }
  314. } else {
  315. var iconHeader: UIImage!
  316. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  317. iconHeader = icon
  318. } else {
  319. iconHeader = UIImage(named: metadata.iconName)
  320. }
  321. actions.append(
  322. NCMenuAction(
  323. title: metadata.fileNameView,
  324. icon: iconHeader,
  325. action: nil
  326. )
  327. )
  328. actions.append(
  329. NCMenuAction(
  330. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  331. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  332. action: { menuAction in
  333. NCNetworking.sharedInstance.favoriteMetadata(metadata, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
  334. }
  335. )
  336. )
  337. if (!metadataFolder.e2eEncrypted) {
  338. actions.append(
  339. NCMenuAction(
  340. title: NSLocalizedString("_details_", comment: ""),
  341. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  342. action: { menuAction in
  343. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  344. }
  345. )
  346. )
  347. }
  348. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  349. actions.append(
  350. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  351. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  352. action: { menuAction in
  353. self.tableView.setEditing(false, animated: true)
  354. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  355. }
  356. )
  357. )
  358. }
  359. actions.append(
  360. NCMenuAction(
  361. title: NSLocalizedString("_rename_", comment: ""),
  362. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  363. action: { menuAction in
  364. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  365. alertController.addTextField { (textField) in
  366. textField.text = metadata.fileNameView
  367. textField.delegate = self as? UITextFieldDelegate
  368. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  369. ), for: UIControl.Event.editingChanged)
  370. }
  371. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  372. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  373. let fileNameNew = alertController.textFields![0].text
  374. NCNetworking.sharedInstance.renameMetadata(metadata, fileNameNew: fileNameNew!, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl, viewController: self) { (errorCode, errorDescription) in }
  375. })
  376. okAction.isEnabled = false
  377. alertController.addAction(cancelAction)
  378. alertController.addAction(okAction)
  379. self.present(alertController, animated: true, completion: nil)
  380. }
  381. )
  382. )
  383. if (!metadataFolder.e2eEncrypted) {
  384. actions.append(
  385. NCMenuAction(
  386. title: NSLocalizedString("_move_or_copy_", comment: ""),
  387. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  388. action: { menuAction in
  389. self.moveOpenWindow([indexPath])
  390. }
  391. )
  392. )
  393. }
  394. if (NCUtility.sharedInstance.isEditImage(metadata.fileNameView as NSString) != nil && !metadataFolder.e2eEncrypted && metadata.status == k_metadataStatusNormal) {
  395. actions.append(
  396. NCMenuAction(title: NSLocalizedString("_modify_photo_", comment: ""),
  397. icon: CCGraphics.changeThemingColorImage(UIImage(named: "modifyPhoto"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  398. action: { menuAction in
  399. metadata.session = k_download_session
  400. metadata.sessionError = ""
  401. metadata.sessionSelector = selectorDownloadEditPhoto
  402. metadata.status = Int(k_metadataStatusWaitDownload)
  403. NCManageDatabase.sharedInstance.addMetadata(metadata)
  404. appDelegate.startLoadAutoDownloadUpload()
  405. }
  406. )
  407. )
  408. }
  409. if (!metadataFolder.e2eEncrypted) {
  410. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  411. var title: String!
  412. if (localFile == nil || localFile!.offline == false) {
  413. title = NSLocalizedString("_set_available_offline_", comment: "")
  414. } else {
  415. title = NSLocalizedString("_remove_available_offline_", comment: "")
  416. }
  417. actions.append(
  418. NCMenuAction(
  419. title: title,
  420. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  421. action: { menuAction in
  422. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  423. metadata.session = k_download_session
  424. metadata.sessionError = ""
  425. metadata.sessionSelector = selectorLoadOffline
  426. metadata.status = Int(k_metadataStatusWaitDownload)
  427. NCManageDatabase.sharedInstance.addMetadata(metadata)
  428. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  429. appDelegate.startLoadAutoDownloadUpload()
  430. } else {
  431. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  432. DispatchQueue.main.async {
  433. self.tableView.reloadRows(at: [indexPath], with: .none)
  434. }
  435. }
  436. }
  437. )
  438. )
  439. }
  440. }
  441. actions.append(
  442. NCMenuAction(
  443. title: NSLocalizedString("_delete_", comment: ""),
  444. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  445. action: { menuAction in
  446. self.actionDelete(indexPath)
  447. }
  448. )
  449. )
  450. return actions
  451. }
  452. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) {
  453. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  454. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata, metadataFolder: metadataFolder)
  455. let menuPanelController = NCMenuPanelController()
  456. menuPanelController.parentPresenter = viewController
  457. menuPanelController.delegate = mainMenuViewController
  458. menuPanelController.set(contentViewController: mainMenuViewController)
  459. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  460. viewController.present(menuPanelController, animated: true, completion: nil)
  461. }
  462. }