NCShareLinkCell.swift 3.4 KB

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