AppDelegate+Menu.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. 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 menuPanelController = MenuPanelController()
  110. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  111. menuPanelController.delegate = mainMenuViewController
  112. menuPanelController.set(contentViewController: mainMenuViewController)
  113. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  114. viewController.present(menuPanelController, animated: true, completion: nil)
  115. }
  116. }