CCMain+Menu.swift 29 KB

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