AppDelegate+Menu.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // AppDelegate+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 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(
  18. MenuAction(
  19. title: NSLocalizedString("_upload_photos_videos_", comment: ""),
  20. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  21. action: { menuAction in
  22. appDelegate.activeMain.openAssetsPickerController()
  23. }
  24. )
  25. )
  26. actions.append(
  27. MenuAction(
  28. title: NSLocalizedString("_upload_file_", comment: ""),
  29. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  30. action: { menuAction in
  31. appDelegate.activeMain.openImportDocumentPicker()
  32. }
  33. )
  34. )
  35. if NCBrandOptions.sharedInstance.use_imi_viewer {
  36. actions.append(
  37. MenuAction(
  38. title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""),
  39. icon: CCGraphics.scale(UIImage(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true),
  40. action: { menuAction in
  41. _ = IMCreate.init(serverUrl: appDelegate.activeMain.serverUrl)
  42. }
  43. )
  44. )
  45. }
  46. if isNextcloudTextAvailable {
  47. actions.append(
  48. MenuAction(title: NSLocalizedString("_create_nextcloudtext_document_", comment: ""),
  49. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  50. action: { menuAction in
  51. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  52. return
  53. }
  54. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  55. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  56. viewController.typeTemplate = k_nextcloudtext_document
  57. viewController.serverUrl = appDelegate.activeMain.serverUrl
  58. viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
  59. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  60. }
  61. )
  62. )
  63. } else {
  64. actions.append(
  65. MenuAction(
  66. title: NSLocalizedString("_upload_file_text_", comment: ""),
  67. icon: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  68. action: { menuAction in
  69. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  70. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  71. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  72. appDelegate.activeMain.present(controller, animated: true, completion: nil)
  73. }
  74. )
  75. )
  76. }
  77. #if !targetEnvironment(simulator)
  78. if #available(iOS 11.0, *) {
  79. actions.append(
  80. MenuAction(
  81. title: NSLocalizedString("_scans_document_", comment: ""),
  82. icon: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  83. action: { menuAction in
  84. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  85. }
  86. )
  87. )
  88. }
  89. #endif
  90. actions.append(
  91. MenuAction(
  92. title: NSLocalizedString("_create_voice_memo_", comment: ""),
  93. icon: CCGraphics.changeThemingColorImage(UIImage(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  94. action: { menuAction in
  95. NCMainCommon.sharedInstance.startAudioRecorder()
  96. }
  97. )
  98. )
  99. actions.append(
  100. MenuAction(title: NSLocalizedString("_create_folder_", comment: ""),
  101. icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  102. action: { menuAction in
  103. appDelegate.activeMain.createFolder()
  104. }
  105. )
  106. )
  107. if let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: appDelegate.activeAccount) {
  108. if (capabilities.versionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) {
  109. actions.append(
  110. MenuAction(
  111. title: NSLocalizedString("_add_folder_info_", comment: ""),
  112. icon: CCGraphics.changeThemingColorImage(UIImage(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  113. action: { menuAction in
  114. self.activeMain.createRichWorkspace()
  115. }
  116. )
  117. )
  118. }
  119. }
  120. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  121. if richdocumentsMimetypes.count > 0 {
  122. actions.append(
  123. MenuAction(
  124. title: NSLocalizedString("_create_new_document_", comment: ""),
  125. icon: UIImage(named: "create_file_document")!,
  126. action: { menuAction in
  127. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  128. return
  129. }
  130. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  131. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  132. viewController.typeTemplate = k_richdocument_document
  133. viewController.serverUrl = appDelegate.activeMain.serverUrl
  134. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  135. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  136. }
  137. )
  138. )
  139. actions.append(
  140. MenuAction(
  141. title: NSLocalizedString("_create_new_spreadsheet_", comment: ""),
  142. icon: UIImage(named: "create_file_xls")!,
  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_spreadsheet
  150. viewController.serverUrl = appDelegate.activeMain.serverUrl
  151. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  152. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  153. }
  154. )
  155. )
  156. actions.append(
  157. MenuAction(
  158. title: NSLocalizedString("_create_new_presentation_", comment: ""),
  159. icon: UIImage(named: "create_file_ppt")!,
  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_presentation
  167. viewController.serverUrl = appDelegate.activeMain.serverUrl
  168. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  169. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  170. }
  171. )
  172. )
  173. }
  174. }
  175. return actions
  176. }
  177. @objc public func showMenuIn(viewController: UIViewController) {
  178. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  179. mainMenuViewController.actions = self.initMenu()
  180. let menuPanelController = MenuPanelController()
  181. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  182. menuPanelController.delegate = mainMenuViewController
  183. menuPanelController.set(contentViewController: mainMenuViewController)
  184. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  185. viewController.present(menuPanelController, animated: true, completion: nil)
  186. }
  187. }