CCMain+Menu.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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: "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: "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: "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: "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_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: NCBrandColor.sharedInstance.icon),
  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 lockDirectory = false
  173. var isOffline = false
  174. let isFolderEncrypted = CCUtility.isFolderEncrypted("\(self.serverUrl ?? "")/\(metadata.fileName)", account: appDelegate.activeAccount)
  175. var passcodeTitle = NSLocalizedString("_protect_passcode_", comment: "")
  176. let dirServerUrl = CCUtility.stringAppendServerUrl(self.metadata.serverUrl, addFileName: metadata.fileName)!
  177. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl)) {
  178. if (CCUtility.getBlockCode() != nil && appDelegate.sessionePasscodeLock == nil) {
  179. lockDirectory = true
  180. }
  181. if (directory.lock) {
  182. passcodeTitle = NSLocalizedString("_protect_passcode_", comment: "")
  183. }
  184. isOffline = directory.offline
  185. }
  186. actions.append(
  187. NCMenuAction(
  188. title: metadata.fileNameView,
  189. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
  190. action: nil
  191. )
  192. )
  193. actions.append(
  194. NCMenuAction(
  195. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  196. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  197. action: { menuAction in
  198. self.settingFavorite(metadata, favorite: !metadata.favorite)
  199. }
  200. )
  201. )
  202. if (!lockDirectory && !isFolderEncrypted) {
  203. actions.append(
  204. NCMenuAction(
  205. title: NSLocalizedString("_details_", comment: ""),
  206. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  207. action: { menuAction in
  208. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  209. }
  210. )
  211. )
  212. }
  213. if(!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !lockDirectory && !metadata.e2eEncrypted) {
  214. actions.append(
  215. NCMenuAction(
  216. title: NSLocalizedString("_rename_", comment: ""),
  217. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  218. action: { menuAction in
  219. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  220. alertController.addTextField { (textField) in
  221. textField.text = metadata.fileNameView
  222. textField.delegate = self as? UITextFieldDelegate
  223. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  224. ), for: UIControl.Event.editingChanged)
  225. }
  226. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  227. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  228. let fileName = alertController.textFields![0].text
  229. self.perform(#selector(self.renameFile(_:)), on: .main, with: [metadata, fileName!], waitUntilDone: false)
  230. })
  231. okAction.isEnabled = false
  232. alertController.addAction(cancelAction)
  233. alertController.addAction(okAction)
  234. self.present(alertController, animated: true, completion: nil)
  235. }
  236. )
  237. )
  238. }
  239. if (!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !lockDirectory && !isFolderEncrypted) {
  240. actions.append(
  241. NCMenuAction(
  242. title: NSLocalizedString("_move_", comment: ""),
  243. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  244. action: { menuAction in
  245. self.moveOpenWindow([indexPath])
  246. }
  247. )
  248. )
  249. }
  250. if (!isFolderEncrypted) {
  251. actions.append(
  252. NCMenuAction(
  253. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  254. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  255. action: { menuAction in
  256. NCManageDatabase.sharedInstance.setDirectory(serverUrl: dirServerUrl, offline: !isOffline, account: appDelegate.activeAccount)
  257. if(isOffline) {
  258. CCSynchronize.shared()?.readFolder(dirServerUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  259. }
  260. DispatchQueue.main.async {
  261. self.tableView.reloadRows(at: [indexPath], with: .none)
  262. }
  263. }
  264. )
  265. )
  266. }
  267. actions.append(
  268. NCMenuAction(
  269. title: passcodeTitle,
  270. icon: CCGraphics.changeThemingColorImage(UIImage(named: "settingsPasscodeYES"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  271. action: { menuAction in
  272. self.perform(#selector(self.comandoLockPassword))
  273. }
  274. )
  275. )
  276. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  277. actions.append(
  278. NCMenuAction(
  279. title: NSLocalizedString("_remove_available_offline_", comment: ""),
  280. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  281. action: { menuAction in
  282. DispatchQueue.global(qos: .userInitiated).async {
  283. 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)
  284. DispatchQueue.main.async {
  285. if(error != nil) {
  286. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  287. } else {
  288. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  289. self.readFolder(self.serverUrl)
  290. }
  291. }
  292. }
  293. }
  294. )
  295. )
  296. }
  297. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  298. actions.append(
  299. NCMenuAction(
  300. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  301. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  302. action: { menuAction in
  303. DispatchQueue.global(qos: .userInitiated).async {
  304. 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)
  305. DispatchQueue.main.async {
  306. if(error != nil) {
  307. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  308. } else {
  309. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  310. self.readFolder(self.serverUrl)
  311. }
  312. }
  313. }
  314. }
  315. )
  316. )
  317. }
  318. } else {
  319. var iconHeader: UIImage!
  320. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  321. iconHeader = icon
  322. } else {
  323. iconHeader = UIImage(named: metadata.iconName)
  324. }
  325. actions.append(
  326. NCMenuAction(
  327. title: metadata.fileNameView,
  328. icon: iconHeader,
  329. action: nil
  330. )
  331. )
  332. actions.append(
  333. NCMenuAction(
  334. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  335. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  336. action: { menuAction in
  337. self.settingFavorite(metadata, favorite: !metadata.favorite)
  338. }
  339. )
  340. )
  341. if (!metadataFolder.e2eEncrypted) {
  342. actions.append(
  343. NCMenuAction(
  344. title: NSLocalizedString("_details_", comment: ""),
  345. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  346. action: { menuAction in
  347. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  348. }
  349. )
  350. )
  351. }
  352. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  353. actions.append(
  354. NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  355. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  356. action: { menuAction in
  357. self.tableView.setEditing(false, animated: true)
  358. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  359. }
  360. )
  361. )
  362. }
  363. if(metadata.typeFile != k_metadataTypeFile_imagemeter) {
  364. actions.append(
  365. NCMenuAction(
  366. title: NSLocalizedString("_rename_", comment: ""),
  367. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  368. action: { menuAction in
  369. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  370. alertController.addTextField { (textField) in
  371. textField.text = metadata.fileNameView
  372. textField.delegate = self as? UITextFieldDelegate
  373. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  374. ), for: UIControl.Event.editingChanged)
  375. }
  376. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  377. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  378. let fileName = alertController.textFields![0].text
  379. self.perform(#selector(self.renameFile(_:)), on: .main, with: [metadata, fileName!], waitUntilDone: false)
  380. })
  381. okAction.isEnabled = false
  382. alertController.addAction(cancelAction)
  383. alertController.addAction(okAction)
  384. self.present(alertController, animated: true, completion: nil)
  385. }
  386. )
  387. )
  388. }
  389. if (!metadataFolder.e2eEncrypted) {
  390. actions.append(
  391. NCMenuAction(
  392. title: NSLocalizedString("_move_", comment: ""),
  393. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  394. action: { menuAction in
  395. self.moveOpenWindow([indexPath])
  396. }
  397. )
  398. )
  399. }
  400. if(NCUtility.sharedInstance.isEditImage(metadata.fileNameView as NSString) != nil && !metadataFolder.e2eEncrypted && metadata.status == k_metadataStatusNormal) {
  401. actions.append(
  402. NCMenuAction(title: NSLocalizedString("_modify_photo_", comment: ""),
  403. icon: CCGraphics.changeThemingColorImage(UIImage(named: "modifyPhoto"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  404. action: { menuAction in
  405. metadata.session = k_download_session
  406. metadata.sessionError = ""
  407. metadata.sessionSelector = selectorDownloadEditPhoto
  408. metadata.status = Int(k_metadataStatusWaitDownload)
  409. _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
  410. appDelegate.startLoadAutoDownloadUpload()
  411. }
  412. )
  413. )
  414. }
  415. if (!metadataFolder.e2eEncrypted) {
  416. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  417. var title: String!
  418. if (localFile == nil || localFile!.offline == false) {
  419. title = NSLocalizedString("_set_available_offline_", comment: "")
  420. } else {
  421. title = NSLocalizedString("_remove_available_offline_", comment: "")
  422. }
  423. actions.append(
  424. NCMenuAction(
  425. title: title,
  426. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  427. action: { menuAction in
  428. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  429. metadata.session = k_download_session
  430. metadata.sessionError = ""
  431. metadata.sessionSelector = selectorLoadOffline
  432. metadata.status = Int(k_metadataStatusWaitDownload)
  433. _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
  434. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  435. appDelegate.startLoadAutoDownloadUpload()
  436. } else {
  437. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  438. DispatchQueue.main.async {
  439. self.tableView.reloadRows(at: [indexPath], with: .none)
  440. }
  441. }
  442. }
  443. )
  444. )
  445. }
  446. }
  447. actions.append(
  448. NCMenuAction(
  449. title: NSLocalizedString("_delete_", comment: ""),
  450. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  451. action: { menuAction in
  452. self.actionDelete(indexPath)
  453. }
  454. )
  455. )
  456. return actions
  457. }
  458. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) {
  459. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  460. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata, metadataFolder: metadataFolder)
  461. let menuPanelController = NCMenuPanelController()
  462. menuPanelController.parentPresenter = viewController
  463. menuPanelController.delegate = mainMenuViewController
  464. menuPanelController.set(contentViewController: mainMenuViewController)
  465. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  466. viewController.present(menuPanelController, animated: true, completion: nil)
  467. }
  468. }