NCShareCommon.swift 4.3 KB

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