NCShareCommon.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // NCShareCommon.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/07/2019.
  6. // Copyright © 2019 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. import UIKit
  23. import FSCalendar
  24. import DropDown
  25. class NCShareCommon: NSObject {
  26. @objc static let shared: NCShareCommon = {
  27. let instance = NCShareCommon()
  28. return instance
  29. }()
  30. let SHARE_TYPE_USER = 0
  31. let SHARE_TYPE_GROUP = 1
  32. let SHARE_TYPE_LINK = 3
  33. let SHARE_TYPE_EMAIL = 4
  34. let SHARE_TYPE_CONTACT = 5
  35. let SHARE_TYPE_REMOTE = 6
  36. let SHARE_TYPE_CIRCLE = 7
  37. let SHARE_TYPE_GUEST = 8
  38. let SHARE_TYPE_REMOTE_GROUP = 9
  39. let SHARE_TYPE_ROOM = 10
  40. func createLinkAvatar(imageName: String, colorCircle: UIColor) -> UIImage? {
  41. let size: CGFloat = 200
  42. let bottomImage = UIImage(named: "circle.fill")!.image(color: colorCircle, size: size/2)
  43. let topImage = UIImage(named: imageName)!.image(color: .white, size: size/2)
  44. UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
  45. bottomImage.draw(in: CGRect(origin: CGPoint.zero, size: CGSize(width: size, height: size)))
  46. topImage.draw(in: CGRect(origin: CGPoint(x: size/4, y: size/4), size: CGSize(width: size/2, height: size/2)))
  47. let image = UIGraphicsGetImageFromCurrentImageContext()
  48. UIGraphicsEndImageContext()
  49. return image
  50. }
  51. func copyLink(link: String, viewController: UIViewController, sender: Any) {
  52. let objectsToShare = [link]
  53. let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
  54. if UIDevice.current.userInterfaceIdiom == .pad {
  55. if activityViewController.responds(to: #selector(getter: UIViewController.popoverPresentationController)) {
  56. activityViewController.popoverPresentationController?.sourceView = sender as? UIView
  57. activityViewController.popoverPresentationController?.sourceRect = (sender as AnyObject).bounds
  58. }
  59. }
  60. DispatchQueue.main.async {
  61. viewController.present(activityViewController, animated: true, completion: nil)
  62. }
  63. }
  64. func getImageShareType(shareType: Int) -> UIImage? {
  65. switch shareType {
  66. case SHARE_TYPE_USER:
  67. return UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label)
  68. case self.SHARE_TYPE_GROUP:
  69. return UIImage(named: "shareTypeGroup")?.imageColor(NCBrandColor.shared.label)
  70. case self.SHARE_TYPE_LINK:
  71. return UIImage(named: "shareTypeLink")?.imageColor(NCBrandColor.shared.label)
  72. case self.SHARE_TYPE_EMAIL:
  73. return UIImage(named: "shareTypeEmail")?.imageColor(NCBrandColor.shared.label)
  74. case self.SHARE_TYPE_CONTACT:
  75. return UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label)
  76. case self.SHARE_TYPE_REMOTE:
  77. return UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label)
  78. case self.SHARE_TYPE_CIRCLE:
  79. return UIImage(named: "shareTypeCircles")?.imageColor(NCBrandColor.shared.label)
  80. case self.SHARE_TYPE_GUEST:
  81. return UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label)
  82. case self.SHARE_TYPE_REMOTE_GROUP:
  83. return UIImage(named: "shareTypeGroup")?.imageColor(NCBrandColor.shared.label)
  84. case self.SHARE_TYPE_ROOM:
  85. return UIImage(named: "shareTypeRoom")?.imageColor(NCBrandColor.shared.label)
  86. default:
  87. return UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label)
  88. }
  89. }
  90. }