CCMain+Menu.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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
  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() -> [MenuAction] {
  28. var actions = [MenuAction]()
  29. actions.append(
  30. MenuAction(
  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" && CCUtility.getAscendingSettings()) {
  39. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  40. } else {
  41. CCUtility.setOrderSettings("fileName")
  42. CCUtility.setAscendingSettings(true)
  43. }
  44. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  45. }
  46. )
  47. )
  48. actions.append(
  49. MenuAction(
  50. title: NSLocalizedString("_order_by_date_more_recent_", comment: ""),
  51. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateMoreRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  52. onTitle: NSLocalizedString("_order_by_date_less_recent_", comment: ""),
  53. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortDateLessRecent"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  54. selected: CCUtility.getOrderSettings() == "date",
  55. on: CCUtility.getAscendingSettings(),
  56. action: { menuAction in
  57. if(CCUtility.getOrderSettings() == "date" && CCUtility.getAscendingSettings()) {
  58. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  59. } else {
  60. CCUtility.setOrderSettings("date")
  61. CCUtility.setAscendingSettings(true)
  62. }
  63. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  64. }
  65. )
  66. )
  67. actions.append(
  68. MenuAction(
  69. title: NSLocalizedString("_order_by_size_smallest_", comment: ""),
  70. icon: CCGraphics.changeThemingColorImage(UIImage(named: "sortSmallest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  71. onTitle: NSLocalizedString("_order_by_size_largest_", comment: ""),
  72. onIcon: CCGraphics.changeThemingColorImage(UIImage(named: "sortLargest"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  73. selected: CCUtility.getOrderSettings() == "size",
  74. on: CCUtility.getAscendingSettings(),
  75. action: { menuAction in
  76. if(CCUtility.getOrderSettings() == "size" && CCUtility.getAscendingSettings()) {
  77. CCUtility.setAscendingSettings(!CCUtility.getAscendingSettings())
  78. } else {
  79. CCUtility.setOrderSettings("size")
  80. CCUtility.setAscendingSettings(true)
  81. }
  82. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  83. }
  84. )
  85. )
  86. actions.append(
  87. MenuAction(
  88. title: NSLocalizedString("_directory_on_top_no_", comment: ""),
  89. icon: CCGraphics.changeThemingColorImage(UIImage(named: "foldersOnTop"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  90. selected: CCUtility.getDirectoryOnTop(),
  91. on: CCUtility.getDirectoryOnTop(),
  92. action: { menuAction in
  93. CCUtility.setDirectoryOnTop(!CCUtility.getDirectoryOnTop())
  94. NotificationCenter.default.post(name: Notification.Name.init(rawValue: "clearDateReadDataSource"), object: nil)
  95. }
  96. )
  97. )
  98. return actions
  99. }
  100. @objc func toggleMenu(viewController: UIViewController) {
  101. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  102. mainMenuViewController.actions = self.initSortMenu()
  103. let menuPanelController = MenuPanelController()
  104. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  105. menuPanelController.delegate = mainMenuViewController
  106. menuPanelController.set(contentViewController: mainMenuViewController)
  107. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  108. viewController.present(menuPanelController, animated: true, completion: nil)
  109. }
  110. @objc func toggleSelectMenu(viewController: UIViewController) {
  111. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  112. mainMenuViewController.actions = self.initSelectMenu()
  113. let menuPanelController = MenuPanelController()
  114. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  115. menuPanelController.delegate = mainMenuViewController
  116. menuPanelController.set(contentViewController: mainMenuViewController)
  117. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  118. viewController.present(menuPanelController, animated: true, completion: nil)
  119. }
  120. private func initSelectMenu() -> [MenuAction] {
  121. var actions = [MenuAction]()
  122. actions.append(
  123. MenuAction(
  124. title: NSLocalizedString("_select_all_", comment: ""),
  125. icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  126. action: { menuAction in
  127. self.didSelectAll()
  128. }
  129. )
  130. )
  131. actions.append(
  132. MenuAction(
  133. title: NSLocalizedString("_move_selected_files_", comment: ""),
  134. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  135. action: { menuAction in
  136. self.moveOpenWindow(self.tableView.indexPathsForSelectedRows)
  137. }
  138. )
  139. )
  140. actions.append(
  141. MenuAction(
  142. title: NSLocalizedString("_download_selected_files_folders_", comment: ""),
  143. icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  144. action: { menuAction in
  145. self.downloadSelectedFilesFolders()
  146. }
  147. )
  148. )
  149. actions.append(
  150. MenuAction(
  151. title: NSLocalizedString("_save_selected_files_", comment: ""),
  152. icon: CCGraphics.changeThemingColorImage(UIImage(named: "saveSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  153. action: { menuAction in
  154. self.saveSelectedFiles()
  155. }
  156. )
  157. )
  158. actions.append(
  159. MenuAction(
  160. title: NSLocalizedString("_delete_selected_files_", comment: ""),
  161. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  162. action: { menuAction in
  163. self.deleteFile()
  164. }
  165. )
  166. )
  167. return actions
  168. }
  169. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) -> [MenuAction] {
  170. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  171. let autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
  172. let autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(appDelegate.activeUrl)
  173. var actions = [MenuAction]()
  174. if (metadata.directory) {
  175. var lockDirectory = false
  176. var isOffline = false
  177. let isFolderEncrypted = CCUtility.isFolderEncrypted("\(self.serverUrl ?? "")/\(metadata.fileName)", account: appDelegate.activeAccount)
  178. var passcodeTitle = NSLocalizedString("_protect_passcode_", comment: "")
  179. let dirServerUrl = CCUtility.stringAppendServerUrl(self.metadata.serverUrl, addFileName: metadata.fileName)!
  180. if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, dirServerUrl)) {
  181. if (CCUtility.getBlockCode() != nil && appDelegate.sessionePasscodeLock == nil) {
  182. lockDirectory = true
  183. }
  184. if (directory.lock) {
  185. passcodeTitle = NSLocalizedString("_protect_passcode_", comment: "")
  186. }
  187. isOffline = directory.offline
  188. }
  189. actions.append(
  190. MenuAction(
  191. title: metadata.fileNameView,
  192. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
  193. action: { menuAction in
  194. }
  195. )
  196. )
  197. actions.append(
  198. MenuAction(
  199. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  200. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  201. action: { menuAction in
  202. self.settingFavorite(metadata, favorite: !metadata.favorite)
  203. }
  204. )
  205. )
  206. if (!lockDirectory && !isFolderEncrypted) {
  207. actions.append(
  208. MenuAction(
  209. title: NSLocalizedString("_details_", comment: ""),
  210. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  211. action: { menuAction in
  212. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  213. }
  214. )
  215. )
  216. }
  217. if(!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !lockDirectory && !metadata.e2eEncrypted) {
  218. actions.append(
  219. MenuAction(
  220. title: NSLocalizedString("_rename_", comment: ""),
  221. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  222. action: { menuAction in
  223. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  224. alertController.addTextField { (textField) in
  225. textField.text = metadata.fileNameView
  226. textField.delegate = self as? UITextFieldDelegate
  227. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  228. ), for: UIControl.Event.editingChanged)
  229. }
  230. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  231. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  232. let fileName = alertController.textFields![0].text
  233. self.perform(#selector(self.renameFile(_:)), on: .main, with: [metadata, fileName!], waitUntilDone: false)
  234. })
  235. okAction.isEnabled = false
  236. alertController.addAction(cancelAction)
  237. alertController.addAction(okAction)
  238. self.present(alertController, animated: true, completion: nil)
  239. }
  240. )
  241. )
  242. }
  243. if (!(metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory) && !lockDirectory && !isFolderEncrypted) {
  244. actions.append(
  245. MenuAction(
  246. title: NSLocalizedString("_move_", comment: ""),
  247. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  248. action: { menuAction in
  249. self.moveOpenWindow([indexPath])
  250. }
  251. )
  252. )
  253. }
  254. if (!isFolderEncrypted) {
  255. actions.append(
  256. MenuAction(
  257. title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
  258. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  259. action: { menuAction in
  260. NCManageDatabase.sharedInstance.setDirectory(serverUrl: dirServerUrl, offline: !isOffline, account: appDelegate.activeAccount)
  261. if(isOffline) {
  262. CCSynchronize.shared()?.readFolder(dirServerUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  263. }
  264. DispatchQueue.main.async {
  265. self.tableView.reloadRows(at: [indexPath], with: .none)
  266. }
  267. }
  268. )
  269. )
  270. }
  271. actions.append(
  272. MenuAction(
  273. title: passcodeTitle,
  274. icon: CCGraphics.changeThemingColorImage(UIImage(named: "settingsPasscodeYES"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  275. action: { menuAction in
  276. self.perform(#selector(self.comandoLockPassword))
  277. }
  278. )
  279. )
  280. if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  281. actions.append(
  282. MenuAction(
  283. title: NSLocalizedString("_remove_available_offline_", comment: ""),
  284. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  285. action: { menuAction in
  286. DispatchQueue.global(qos: .userInitiated).async {
  287. 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)
  288. DispatchQueue.main.async {
  289. if(error != nil) {
  290. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  291. } else {
  292. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  293. self.readFolder(self.serverUrl)
  294. }
  295. }
  296. }
  297. }
  298. )
  299. )
  300. }
  301. if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.activeAccount)) {
  302. actions.append(
  303. MenuAction(
  304. title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
  305. icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  306. action: { menuAction in
  307. DispatchQueue.global(qos: .userInitiated).async {
  308. 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)
  309. DispatchQueue.main.async {
  310. if(error != nil) {
  311. NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: (error! as NSError).code)
  312. } else {
  313. NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
  314. self.readFolder(self.serverUrl)
  315. }
  316. }
  317. }
  318. }
  319. )
  320. )
  321. }
  322. } else {
  323. var iconHeader: UIImage!
  324. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  325. iconHeader = icon
  326. } else {
  327. iconHeader = UIImage(named: metadata.iconName)
  328. }
  329. actions.append(
  330. MenuAction(
  331. title: metadata.fileNameView,
  332. icon: iconHeader, action: { menuAction in
  333. }
  334. )
  335. )
  336. actions.append(
  337. MenuAction(
  338. title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
  339. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  340. action: { menuAction in
  341. self.settingFavorite(metadata, favorite: !metadata.favorite)
  342. }
  343. )
  344. )
  345. if (!metadataFolder.e2eEncrypted) {
  346. actions.append(
  347. MenuAction(
  348. title: NSLocalizedString("_details_", comment: ""),
  349. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  350. action: { menuAction in
  351. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  352. }
  353. )
  354. )
  355. }
  356. if(!NCBrandOptions.sharedInstance.disable_openin_file) {
  357. actions.append(
  358. MenuAction(title: NSLocalizedString("_open_in_", comment: ""),
  359. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  360. action: { menuAction in
  361. self.perform(#selector(self.openinFile(_:)))
  362. }
  363. )
  364. )
  365. }
  366. actions.append(
  367. MenuAction(
  368. title: NSLocalizedString("_rename_", comment: ""),
  369. icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  370. action: { menuAction in
  371. let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
  372. alertController.addTextField { (textField) in
  373. textField.text = metadata.fileNameView
  374. textField.delegate = self as? UITextFieldDelegate
  375. textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
  376. ), for: UIControl.Event.editingChanged)
  377. }
  378. let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
  379. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
  380. let fileName = alertController.textFields![0].text
  381. self.perform(#selector(self.renameFile(_:)), on: .main, with: [metadata, fileName!], waitUntilDone: false)
  382. })
  383. okAction.isEnabled = false
  384. alertController.addAction(cancelAction)
  385. alertController.addAction(okAction)
  386. self.present(alertController, animated: true, completion: nil)
  387. }
  388. )
  389. )
  390. if (!metadataFolder.e2eEncrypted) {
  391. actions.append(
  392. MenuAction(
  393. title: NSLocalizedString("_move_", comment: ""),
  394. icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  395. action: { menuAction in
  396. self.moveOpenWindow([indexPath])
  397. }
  398. )
  399. )
  400. }
  401. if(NCUtility.sharedInstance.isEditImage(metadata.fileNameView as NSString) != nil && !metadataFolder.e2eEncrypted && metadata.status == k_metadataStatusNormal) {
  402. actions.append(
  403. MenuAction(title: NSLocalizedString("_modify_photo_", comment: ""),
  404. icon: CCGraphics.changeThemingColorImage(UIImage(named: "modifyPhoto"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  405. action: { menuAction in
  406. metadata.session = k_download_session
  407. metadata.sessionError = ""
  408. metadata.sessionSelector = selectorDownloadEditPhoto
  409. metadata.status = Int(k_metadataStatusWaitDownload)
  410. _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
  411. appDelegate.startLoadAutoDownloadUpload()
  412. }
  413. )
  414. )
  415. }
  416. if (!metadataFolder.e2eEncrypted) {
  417. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  418. var title: String!
  419. if (localFile == nil || localFile!.offline == false) {
  420. title = NSLocalizedString("_set_available_offline_", comment: "")
  421. } else {
  422. title = NSLocalizedString("_remove_available_offline_", comment: "")
  423. }
  424. actions.append(
  425. MenuAction(
  426. title: title,
  427. icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  428. action: { menuAction in
  429. if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
  430. metadata.session = k_download_session
  431. metadata.sessionError = ""
  432. metadata.sessionSelector = selectorLoadOffline
  433. metadata.status = Int(k_metadataStatusWaitDownload)
  434. _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
  435. NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: self.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
  436. appDelegate.startLoadAutoDownloadUpload()
  437. } else {
  438. NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
  439. DispatchQueue.main.async {
  440. self.tableView.reloadRows(at: [indexPath], with: .none)
  441. }
  442. }
  443. }
  444. )
  445. )
  446. }
  447. }
  448. actions.append(
  449. MenuAction(
  450. title: NSLocalizedString("_delete_", comment: ""),
  451. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
  452. action: { menuAction in
  453. self.actionDelete(indexPath)
  454. }
  455. )
  456. )
  457. return actions
  458. }
  459. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) {
  460. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  461. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata, metadataFolder: metadataFolder)
  462. let menuPanelController = MenuPanelController()
  463. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  464. menuPanelController.delegate = mainMenuViewController
  465. menuPanelController.set(contentViewController: mainMenuViewController)
  466. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  467. viewController.present(menuPanelController, animated: true, completion: nil)
  468. }
  469. }