AppDelegate+Menu.swift 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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(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. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: appDelegate.activeMain)
  53. }))
  54. }
  55. #endif
  56. 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
  57. NCMainCommon.sharedInstance.startAudioRecorder()
  58. }))
  59. 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
  60. appDelegate.activeMain.createFolder()
  61. }))
  62. if let capabilities = NCManageDatabase.sharedInstance.getCapabilites(account: appDelegate.activeAccount) {
  63. if (capabilities.versionMajor >= k_nextcloud_version_18_0 && (self.activeMain.richWorkspaceText == nil || self.activeMain.richWorkspaceText.count == 0)) {
  64. actions.append(MenuAction(title: NSLocalizedString("_add_folder_info_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "addFolderInfo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  65. self.activeMain.createRichWorkspace()
  66. }))
  67. }
  68. }
  69. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  70. if richdocumentsMimetypes.count > 0 {
  71. actions.append(MenuAction(title: NSLocalizedString("_create_new_document_", comment: ""), icon: UIImage.init(named: "create_file_document")!,
  72. action: { menuAction in
  73. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  74. return
  75. }
  76. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  77. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  78. viewController.typeTemplate = k_richdocument_document
  79. viewController.serverUrl = appDelegate.activeMain.serverUrl
  80. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  81. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  82. }))
  83. actions.append(MenuAction(title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), icon: UIImage(named: "create_file_xls")!,
  84. action: { menuAction in
  85. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  86. return
  87. }
  88. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  89. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  90. viewController.typeTemplate = k_richdocument_spreadsheet
  91. viewController.serverUrl = appDelegate.activeMain.serverUrl
  92. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  93. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  94. }))
  95. actions.append(MenuAction(title: NSLocalizedString("_create_new_presentation_", comment: ""), icon: UIImage(named: "create_file_ppt")!,
  96. action: { menuAction in
  97. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController() else {
  98. return
  99. }
  100. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  101. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadDocuments
  102. viewController.typeTemplate = k_richdocument_presentation
  103. viewController.serverUrl = appDelegate.activeMain.serverUrl
  104. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  105. appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  106. }))
  107. }
  108. }
  109. return actions
  110. }
  111. @objc public func showMenuIn(viewController: UIViewController) {
  112. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  113. mainMenuViewController.actions = self.initMenu()
  114. let menuPanelController = MenuPanelController()
  115. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  116. menuPanelController.delegate = mainMenuViewController
  117. menuPanelController.set(contentViewController: mainMenuViewController)
  118. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  119. viewController.present(menuPanelController, animated: true, completion: nil)
  120. }
  121. }