NCShareLinkCell.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 menuImageName = "ellipsis"
  40. menuButton.isHidden = isInternalLink
  41. descriptionLabel.isHidden = !isInternalLink
  42. copyButton.isHidden = !isInternalLink && tableShare == nil
  43. copyButton.accessibilityLabel = NSLocalizedString("_copy_", comment: "")
  44. menuButton.accessibilityLabel = NSLocalizedString("_more_", comment: "")
  45. if isInternalLink {
  46. labelTitle.text = NSLocalizedString("_share_internal_link_", comment: "")
  47. descriptionLabel.text = NSLocalizedString("_share_internal_link_des_", comment: "")
  48. imageItem.image = NCUtility().loadImage(named: "square.and.arrow.up.circle.fill", colors: [NCBrandColor.shared.iconImageColor2])
  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 = "plus"
  57. menuButton.accessibilityLabel = NSLocalizedString("_add_", comment: "")
  58. }
  59. imageItem.image = NCUtility().loadImage(named: "link.circle.fill", colors: [NCBrandColor.shared.getElement(account: tableShare?.account)])
  60. menuButton.setImage(NCUtility().loadImage(named: menuImageName, colors: [NCBrandColor.shared.iconImageColor]), for: .normal)
  61. }
  62. labelTitle.textColor = NCBrandColor.shared.textColor
  63. }
  64. @IBAction func touchUpCopy(_ sender: Any) {
  65. delegate?.tapCopy(with: tableShare, sender: sender)
  66. }
  67. @IBAction func touchUpMenu(_ sender: Any) {
  68. delegate?.tapMenu(with: tableShare, sender: sender)
  69. }
  70. }
  71. protocol NCShareLinkCellDelegate: AnyObject {
  72. func tapCopy(with tableShare: tableShare?, sender: Any)
  73. func tapMenu(with tableShare: tableShare?, sender: Any)
  74. }