NCCreateMenuAdd.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <m.faggiana@twsweb.it>
  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. let fontButton = [NSAttributedString.Key.font:UIFont(name: "HelveticaNeue", size: 16)!, NSAttributedString.Key.foregroundColor: UIColor.black]
  28. let fontEncrypted = [NSAttributedString.Key.font:UIFont(name: "HelveticaNeue", size: 16)!, NSAttributedString.Key.foregroundColor: NCBrandColor.sharedInstance.encrypted as UIColor]
  29. let fontCancel = [NSAttributedString.Key.font:UIFont(name: "HelveticaNeue-Bold", size: 17)!, NSAttributedString.Key.foregroundColor: UIColor.black]
  30. let fontDisable = [NSAttributedString.Key.font:UIFont(name: "HelveticaNeue", size: 16)!, NSAttributedString.Key.foregroundColor: UIColor.darkGray]
  31. var colorIcon = NCBrandColor.sharedInstance.brandElement
  32. @objc init (themingColor : UIColor) {
  33. super.init()
  34. colorIcon = themingColor
  35. }
  36. @objc func createMenu(viewController: UIViewController, view : UIView) {
  37. var items = [ActionSheetItem]()
  38. items.append(ActionSheetItem(title: NSLocalizedString("_upload_photos_videos_", comment: ""), value: 1, image: CCGraphics.changeThemingColorImage(UIImage(named: "media"), multiplier:1, color: NCBrandColor.sharedInstance.icon)))
  39. items.append(ActionSheetItem(title: NSLocalizedString("_upload_file_", comment: ""), value: 2, image: CCGraphics.changeThemingColorImage(UIImage(named: "file"), multiplier:1, color: NCBrandColor.sharedInstance.icon)))
  40. items.append(ActionSheetItem(title: NSLocalizedString("_upload_file_text_", comment: ""), value: 3, image: CCGraphics.changeThemingColorImage(UIImage(named: "file_txt"), multiplier:1, color: NCBrandColor.sharedInstance.icon)))
  41. if #available(iOS 11.0, *) {
  42. items.append(ActionSheetItem(title: NSLocalizedString("_scans_document_", comment: ""), value: 4, image: CCGraphics.changeThemingColorImage(UIImage(named: "scan"), multiplier:2, color: NCBrandColor.sharedInstance.icon)))
  43. }
  44. items.append(ActionSheetItem(title: NSLocalizedString("_create_folder_", comment: ""), value: 5, image: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), multiplier:1, color: colorIcon)))
  45. // items.append(ActionSheetSectionTitle(title: "Cheap"))
  46. // items.append(ActionSheetSectionMargin())
  47. /*
  48. let appearanceSectionMargin = ActionSheetAppearance.standard
  49. //appearanceSectionMargin. = 10
  50. appearanceSectionMargin.backgroundColor = UIColor.red
  51. let itemSectionMargin = ActionSheetSectionTitle(title: "Cheap")
  52. itemSectionMargin.customAppearance = appearanceSectionMargin
  53. items.append(itemSectionMargin)
  54. */
  55. if let richdocumentsMimetypes = NCManageDatabase.sharedInstance.getRichdocumentsMimetypes() {
  56. if richdocumentsMimetypes.count > 0 {
  57. items.append(ActionSheetItem(title: NSLocalizedString("_create_new_document_", comment: ""), value: 6, image: UIImage.init(named: "document_menu")))
  58. items.append(ActionSheetItem(title: NSLocalizedString("_create_new_spreadsheet", comment: ""), value: 7, image: UIImage(named: "file_xls_menu")))
  59. items.append(ActionSheetItem(title: NSLocalizedString("_create_new_presentation_", comment: ""), value: 8, image: UIImage(named: "file_ppt_menu")))
  60. }
  61. }
  62. items.append(ActionSheetCancelButton(title: NSLocalizedString("_cancel_", comment: "")))
  63. let actionSheet = ActionSheet(items: items) { sheet, item in
  64. if item.value as? Int == 1 { self.appDelegate.activeMain.openAssetsPickerController() }
  65. if item.value as? Int == 2 { self.appDelegate.activeMain.openImportDocumentPicker() }
  66. if item.value as? Int == 3 {
  67. let storyboard = UIStoryboard(name: "NCText", bundle: nil)
  68. let controller = storyboard.instantiateViewController(withIdentifier: "NCText")
  69. controller.modalPresentationStyle = UIModalPresentationStyle.pageSheet
  70. self.appDelegate.activeMain.present(controller, animated: true, completion: nil)
  71. }
  72. if item.value as? Int == 4 {
  73. if #available(iOS 11.0, *) {
  74. NCCreateScanDocument.sharedInstance.openScannerDocument(viewController: self.appDelegate.activeMain, openScan: true)
  75. }
  76. }
  77. if item.value as? Int == 5 { self.appDelegate.activeMain.createFolder() }
  78. if item.value as? Int == 6 {
  79. let viewController = NCCreateFormUploadRichdocuments.init(typeTemplate: k_richdocument_document)
  80. let navigationController = UINavigationController.init(rootViewController: viewController)
  81. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  82. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  83. }
  84. if item.value as? Int == 7 { print("Cancel buttons has the value `true`") }
  85. if item.value as? Int == 8 { print("Cancel buttons has the value `true`") }
  86. if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
  87. }
  88. actionSheet.present(in: viewController, from: view)
  89. }
  90. }