NCShareCommon.swift 4.7 KB

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