NCShareLinkCell.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // NCShareLinkCell.swift
  3. // Nextcloud
  4. //
  5. // Created by Henrik Storch on 15.11.2021.
  6. // Copyright © 2021 Henrik Storch. All rights reserved.
  7. //
  8. // Author Henrik Storch <henrik.storch@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. class NCShareLinkCell: UITableViewCell {
  24. @IBOutlet private weak var imageItem: UIImageView!
  25. @IBOutlet private weak var labelTitle: UILabel!
  26. @IBOutlet private weak var descriptionLabel: UILabel!
  27. @IBOutlet private weak var menuButton: UIButton!
  28. @IBOutlet private weak var copyButton: UIButton!
  29. var tableShare: tableShare?
  30. weak var delegate: NCShareLinkCellDelegate?
  31. var isInternalLink = false
  32. override func prepareForReuse() {
  33. super.prepareForReuse()
  34. isInternalLink = false
  35. tableShare = nil
  36. }
  37. func setupCellUI() {
  38. var imageName: String
  39. var imageBGColor: UIColor
  40. var menuImageName = "shareMenu"
  41. menuButton.isHidden = isInternalLink
  42. descriptionLabel.isHidden = !isInternalLink
  43. copyButton.isHidden = !isInternalLink && tableShare == nil
  44. if isInternalLink {
  45. imageName = "shareInternalLink"
  46. imageBGColor = .gray
  47. labelTitle.text = NSLocalizedString("_share_internal_link_", comment: "")
  48. descriptionLabel.text = NSLocalizedString("_share_internal_link_des_", comment: "")
  49. } else {
  50. labelTitle.text = NSLocalizedString("_share_link_", comment: "")
  51. if let tableShare = tableShare {
  52. if !tableShare.label.isEmpty {
  53. labelTitle.text? += " (\(tableShare.label))"
  54. }
  55. } else {
  56. menuImageName = "shareAdd"
  57. }
  58. imageName = "sharebylink"
  59. imageBGColor = NCBrandColor.shared.brandElement
  60. menuButton.setImage(UIImage(named: menuImageName)?.image(color: .gray, size: 50), for: .normal)
  61. }
  62. labelTitle.textColor = NCBrandColor.shared.label
  63. imageItem.image = NCShareCommon.shared.createLinkAvatar(imageName: imageName, colorCircle: imageBGColor)
  64. copyButton.setImage(UIImage(named: "shareCopy")?.image(color: .gray, size: 50), for: .normal)
  65. }
  66. @IBAction func touchUpCopy(_ sender: Any) {
  67. delegate?.tapCopy(with: tableShare, sender: sender)
  68. }
  69. @IBAction func touchUpMenu(_ sender: Any) {
  70. delegate?.tapMenu(with: tableShare, sender: sender)
  71. }
  72. }
  73. protocol NCShareLinkCellDelegate: AnyObject {
  74. func tapCopy(with tableShare: tableShare?, sender: Any)
  75. func tapMenu(with tableShare: tableShare?, sender: Any)
  76. }