NCCreateMenuAdd.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 = [ActionSheetItem]()
  30. items.append(ActionSheetItem(title: NSLocalizedString("_upload_photos_videos_", comment: ""), value: 1, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_photo"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  31. items.append(ActionSheetItem(title: NSLocalizedString("_upload_file_", comment: ""), value: 2, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  32. items.append(ActionSheetItem(title: NSLocalizedString("_upload_file_text_", comment: ""), value: 3, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  33. #if !targetEnvironment(simulator)
  34. if #available(iOS 11.0, *) {
  35. items.append(ActionSheetItem(title: NSLocalizedString("_scans_document_", comment: ""), value: 4, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "scan"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  36. }
  37. #endif
  38. items.append(ActionSheetItem(title: NSLocalizedString("_create_voice_memo_", comment: ""), value: 5, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "microphone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
  39. items.append(ActionSheetItem(title: NSLocalizedString("_create_folder_", comment: ""), value: 6, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement)))
  40. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes(account: appDelegate.activeAccount) {
  41. if richdocumentsMimetypes.count > 0 {
  42. items.append(ActionSheetItem(title: NSLocalizedString("_create_new_document_", comment: ""), value: 7, image: UIImage.init(named: "create_file_document")))
  43. items.append(ActionSheetItem(title: NSLocalizedString("_create_new_spreadsheet_", comment: ""), value: 8, image: UIImage(named: "create_file_xls")))
  44. items.append(ActionSheetItem(title: NSLocalizedString("_create_new_presentation_", comment: ""), value: 9, image: UIImage(named: "create_file_ppt")))
  45. }
  46. }
  47. items.append(ActionSheetCancelButton(title: NSLocalizedString("_cancel_", comment: "")))
  48. let actionSheet = ActionSheet(items: items) { sheet, item in
  49. if item.value as? Int == 1 { self.appDelegate.activeMain.openAssetsPickerController() }
  50. if item.value as? Int == 2 { self.appDelegate.activeMain.openImportDocumentPicker() }
  51. if item.value as? Int == 3 {
  52. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  53. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  54. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  55. self.appDelegate.activeMain.present(controller, animated: true, completion: nil)
  56. }
  57. if item.value as? Int == 4 {
  58. if #available(iOS 11.0, *) {
  59. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: self.appDelegate.activeMain, openScan: true)
  60. }
  61. }
  62. if item.value as? Int == 5 { NCMainCommon.sharedInstance.startAudioRecorder() }
  63. if item.value as? Int == 6 { self.appDelegate.activeMain.createFolder() }
  64. if item.value as? Int == 7 {
  65. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadRichdocuments", bundle: nil).instantiateInitialViewController() else {
  66. return
  67. }
  68. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  69. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadRichdocuments
  70. viewController.typeTemplate = k_richdocument_document
  71. viewController.serverUrl = self.appDelegate.activeMain.serverUrl
  72. viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
  73. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  74. }
  75. if item.value as? Int == 8 {
  76. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadRichdocuments", bundle: nil).instantiateInitialViewController() else {
  77. return
  78. }
  79. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  80. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadRichdocuments
  81. viewController.typeTemplate = k_richdocument_spreadsheet
  82. viewController.serverUrl = self.appDelegate.activeMain.serverUrl
  83. viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
  84. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  85. }
  86. if item.value as? Int == 9 {
  87. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadRichdocuments", bundle: nil).instantiateInitialViewController() else {
  88. return
  89. }
  90. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  91. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadRichdocuments
  92. viewController.typeTemplate = k_richdocument_presentation
  93. viewController.serverUrl = self.appDelegate.activeMain.serverUrl
  94. viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
  95. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  96. }
  97. if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
  98. }
  99. ActionSheetTableView.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
  100. ActionSheetTableView.appearance().separatorColor = NCBrandColor.sharedInstance.separator
  101. ActionSheetItemCell.appearance().backgroundColor = NCBrandColor.sharedInstance.backgroundForm
  102. ActionSheetItemCell.appearance().titleColor = NCBrandColor.sharedInstance.textView
  103. actionSheet.present(in: viewController, from: view)
  104. }
  105. }