AppDelegate+Menu.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // AppDelegate+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 AppDelegate {
  27. private func initMenu() -> [NCMenuAction] {
  28. var actions = [NCMenuAction]()
  29. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  30. var isNextcloudTextAvailable = false
  31. if appDelegate.reachability.isReachable() && NCBrandBeta.shared.directEditing && NCManageDatabase.sharedInstance.getDirectEditingCreators(account: appDelegate.activeAccount) != nil {
  32. isNextcloudTextAvailable = true
  33. }
  34. actions.append(
  35. NCMenuAction(
  36. title: NSLocalizedString("_upload_photos_videos_", comment: ""),
  37. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  38. action: { menuAction in
  39. appDelegate.activeMain.openAssetsPickerController()
  40. }
  41. )
  42. )
  43. actions.append(
  44. NCMenuAction(
  45. title: NSLocalizedString("_upload_file_", comment: ""),
  46. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  47. action: { menuAction in
  48. appDelegate.activeMain.openImportDocumentPicker()
  49. }
  50. )
  51. )
  52. if NCBrandOptions.sharedInstance.use_imi_viewer {
  53. actions.append(
  54. NCMenuAction(
  55. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
  56. icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
  57. action: { menuAction in
  58. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl)
  59. }
  60. )
  61. )
  62. }
  63. if isNextcloudTextAvailable {
  64. actions.append(
  65. NCMenuAction(title: NSLocalizedString("_create_nextcloudtext_document_", comment: ""),
  66. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  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_nextcloudtext_document
  74. viewController.serverUrl = appDelegate.activeMain.serverUrl
  75. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  76. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  77. }
  78. )
  79. )
  80. } else {
  81. actions.append(
  82. NCMenuAction(
  83. title: NSLocalizedString("_upload_file_text_", comment: ""),
  84. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  85. action: { menuAction in
  86. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  87. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  88. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  89. appDelegate.activeMain.present(controller, animated: true, completion: nil)
  90. }
  91. )
  92. )
  93. }
  94. #if !targetEnvironment(simulator)
  95. if #available(iOS 11.0, *) {
  96. actions.append(
  97. NCMenuAction(
  98. title: NSLocalizedString("_scans_document_", comment: ""),
  99. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  100. action: { menuAction in
  101. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  102. }
  103. )
  104. )
  105. }
  106. #endif
  107. actions.append(
  108. NCMenuAction(
  109. title: NSLocalizedString("_create_voice_memo_", comment: ""),
  110. icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  111. action: { menuAction in
  112. NCMainCommon.sharedInstance.startAudioRecorder()
  113. }
  114. )
  115. )
  116. actions.append(
  117. NCMenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  118. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  119. action: { menuAction in
  120. appDelegate.activeMain.createFolder()
  121. }
  122. )
  123. )
  124. if let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: appDelegate.activeAccount) {
  125. if (capabilities.versionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) {
  126. actions.append(
  127. NCMenuAction(
  128. title: NSLocalizedString("_add_folder_info_", comment: ""),
  129. icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  130. action: { menuAction in
  131. self.activeMain.createRichWorkspace()
  132. }
  133. )
  134. )
  135. }
  136. }
  137. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  138. if richdocumentsMimetypes.count > 0 {
  139. actions.append(
  140. NCMenuAction(
  141. title: NSLocalizedString("_create_new_document_", comment: ""),
  142. icon: UIImage(named: "create_file_document")!,
  143. action: { menuAction in
  144. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  145. return
  146. }
  147. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  148. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  149. viewController.typeTemplate = k_richdocument_document
  150. viewController.serverUrl = appDelegate.activeMain.serverUrl
  151. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  152. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  153. }
  154. )
  155. )
  156. actions.append(
  157. NCMenuAction(
  158. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  159. icon: UIImage(named: "create_file_xls")!,
  160. action: { menuAction in
  161. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  162. return
  163. }
  164. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  165. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  166. viewController.typeTemplate = k_richdocument_spreadsheet
  167. viewController.serverUrl = appDelegate.activeMain.serverUrl
  168. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  169. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  170. }
  171. )
  172. )
  173. actions.append(
  174. NCMenuAction(
  175. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  176. icon: UIImage(named: "create_file_ppt")!,
  177. action: { menuAction in
  178. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  179. return
  180. }
  181. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  182. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  183. viewController.typeTemplate = k_richdocument_presentation
  184. viewController.serverUrl = appDelegate.activeMain.serverUrl
  185. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  186. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  187. }
  188. )
  189. )
  190. }
  191. }
  192. return actions
  193. }
  194. @objc public func showMenuIn(viewController: UIViewController) {
  195. let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
  196. mainMenuViewController.actions = self.initMenu()
  197. let menuPanelController = NCMenuPanelController()
  198. menuPanelController.parentPresenter = viewController
  199. menuPanelController.delegate = mainMenuViewController
  200. menuPanelController.set(contentViewController: mainMenuViewController)
  201. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  202. viewController.present(menuPanelController, animated: true, completion: nil)
  203. }
  204. }