CCMain+Menu.swift 27 KB

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