NCShareLinkCell.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. copyButton.accessibilityLabel = NSLocalizedString("_copy_", comment: "")
  45. menuButton.accessibilityLabel = NSLocalizedString("_more_", comment: "")
  46. if isInternalLink {
  47. imageName = "shareInternalLink"
  48. imageBGColor = .gray
  49. labelTitle.text = NSLocalizedString("_share_internal_link_", comment: "")
  50. descriptionLabel.text = NSLocalizedString("_share_internal_link_des_", comment: "")
  51. } else {
  52. labelTitle.text = NSLocalizedString("_share_link_", comment: "")
  53. if let tableShare = tableShare {
  54. if !tableShare.label.isEmpty {
  55. labelTitle.text? += " (\(tableShare.label))"
  56. }
  57. } else {
  58. menuImageName = "shareAdd"
  59. menuButton.accessibilityLabel = NSLocalizedString("_add_", comment: "")
  60. }
  61. imageName = "sharebylink"
  62. imageBGColor = NCBrandColor.shared.brandElement
  63. menuButton.setImage(UIImage(named: menuImageName)?.image(color: .gray, size: 50), for: .normal)
  64. }
  65. labelTitle.textColor = .label
  66. imageItem.image = NCShareCommon.shared.createLinkAvatar(imageName: imageName, colorCircle: imageBGColor)
  67. copyButton.setImage(UIImage(named: "shareCopy")?.image(color: .gray, size: 50), for: .normal)
  68. }
  69. @IBAction func touchUpCopy(_ sender: Any) {
  70. delegate?.tapCopy(with: tableShare, sender: sender)
  71. }
  72. @IBAction func touchUpMenu(_ sender: Any) {
  73. delegate?.tapMenu(with: tableShare, sender: sender)
  74. }
  75. }
  76. protocol NCShareLinkCellDelegate: AnyObject {
  77. func tapCopy(with tableShare: tableShare?, sender: Any)
  78. func tapMenu(with tableShare: tableShare?, sender: Any)
  79. }