MainMenuManager.swift 34 KB

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