NCCreateMenuAdd.swift 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // NCCreateMenuAdd.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 14/11/2018.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. import Sheeeeeeeeet
  25. class NCCreateMenuAdd: NSObject {
  26. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  27. @objc init(viewController: UIViewController, view : UIView) {
  28. super.init()
  29. var items = [MenuItem]()
  30. ActionSheetTableView.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
  31. ActionSheetTableView.appearance().separatorColor = NCBrandColor.sharedInstance.separator
  32. ActionSheetItemCell.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
  33. ActionSheetItemCell.appearance().titleColor = NCBrandColor.sharedInstance.textView
  34. items.append(MenuItem(title: NSLocalizedString("_upload_photos_videos_", comment: ""), value: 10, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  35. items.append(MenuItem(title: NSLocalizedString("_upload_file_", comment: ""), value: 20, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  36. if NCBrandOptions.sharedInstance.use_imi_viewer {
  37. items.append(MenuItem(title: NSLocalizedString("_im_create_new_file", tableName: "IMLocalizable", bundle: Bundle.main, value: "", comment: ""), value: 21, image: CCGraphics.scale(UIImage.init(named: "imagemeter"), to: CGSize(width: 25, height: 25), isAspectRation: true)))
  38. }
  39. items.append(MenuItem(title: NSLocalizedString("_upload_file_text_", comment: ""), value: 30, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  40. #if !targetEnvironment(simulator)
  41. if #available(iOS 11.0, *) {
  42. items.append(MenuItem(title: NSLocalizedString("_scans_document_", comment: ""), value: 40, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  43. }
  44. #endif
  45. items.append(MenuItem(title: NSLocalizedString("_create_voice_memo_", comment: ""), value: 50, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  46. items.append(MenuItem(title: NSLocalizedString("_create_folder_", comment: ""), value: 60, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement)))
  47. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  48. if richdocumentsMimetypes.count > 0 {
  49. items.append(MenuItem(title: NSLocalizedString("_create_new_document_", comment: ""), value: 70, image: UIImage.init(named: "create_file_document")))
  50. items.append(MenuItem(title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), value: 80, image: UIImage(named: "create_file_xls")))
  51. items.append(MenuItem(title: NSLocalizedString("_create_new_presentation_", comment: ""), value: 90, image: UIImage(named: "create_file_ppt")))
  52. }
  53. }
  54. items.append(CancelButton(title: NSLocalizedString("_cancel_", comment: "")))
  55. let actionSheet = ActionSheet(menu: Menu(items: items), action: { (shhet, item) in
  56. if item.value as? Int == 10 { self.appDelegate.activeMain.openAssetsPickerController() }
  57. if item.value as? Int == 20 { self.appDelegate.activeMain.openImportDocumentPicker() }
  58. if item.value as? Int == 21 {
  59. _ = IMCreate.init(serverUrl: self.appDelegate.activeMain.serverUrl)
  60. }
  61. if item.value as? Int == 30 {
  62. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  63. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  64. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  65. self.appDelegate.activeMain.present(controller, animated: true, completion: nil)
  66. }
  67. if item.value as? Int == 40 {
  68. if #available(iOS 11.0, *) {
  69. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: self.appDelegate.activeMain)
  70. }
  71. }
  72. if item.value as? Int == 50 { NCMainCommon.sharedInstance.startAudioRecorder() }
  73. if item.value as? Int == 60 { self.appDelegate.activeMain.createFolder() }
  74. if item.value as? Int == 70 {
  75. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadRichdocuments", bundle: nil).instantiateInitialViewController() else {
  76. return
  77. }
  78. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  79. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadRichdocuments
  80. viewController.typeTemplate = k_richdocument_document
  81. viewController.serverUrl = self.appDelegate.activeMain.serverUrl
  82. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  83. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  84. }
  85. if item.value as? Int == 80 {
  86. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadRichdocuments", bundle: nil).instantiateInitialViewController() else {
  87. return
  88. }
  89. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  90. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadRichdocuments
  91. viewController.typeTemplate = k_richdocument_spreadsheet
  92. viewController.serverUrl = self.appDelegate.activeMain.serverUrl
  93. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  94. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  95. }
  96. if item.value as? Int == 90 {
  97. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadRichdocuments", bundle: nil).instantiateInitialViewController() else {
  98. return
  99. }
  100. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  101. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadRichdocuments
  102. viewController.typeTemplate = k_richdocument_presentation
  103. viewController.serverUrl = self.appDelegate.activeMain.serverUrl
  104. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  105. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  106. }
  107. if item is CancelButton { print("Cancel buttons has the value `true`") }
  108. })
  109. actionSheet.present(in: viewController, from: view)
  110. }
  111. }