NCShareLinkCell.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // FIXME: FATAL - Object has been deleted or invalidated
  53. if !tableShare.label.isEmpty {
  54. labelTitle.text? += " (\(tableShare.label))"
  55. }
  56. } else {
  57. menuImageName = "shareAdd"
  58. }
  59. imageName = "sharebylink"
  60. imageBGColor = NCBrandColor.shared.brandElement
  61. menuButton.setImage(UIImage(named: menuImageName)?.image(color: .gray, size: 50), for: .normal)
  62. }
  63. labelTitle.textColor = NCBrandColor.shared.label
  64. imageItem.image = NCShareCommon.shared.createLinkAvatar(imageName: imageName, colorCircle: imageBGColor)
  65. copyButton.setImage(UIImage(named: "shareCopy")?.image(color: .gray, size: 50), for: .normal)
  66. }
  67. @IBAction func touchUpCopy(_ sender: Any) {
  68. delegate?.tapCopy(with: tableShare, sender: sender)
  69. }
  70. @IBAction func touchUpMenu(_ sender: Any) {
  71. delegate?.tapMenu(with: tableShare, sender: sender)
  72. }
  73. }
  74. protocol NCShareLinkCellDelegate: AnyObject {
  75. func tapCopy(with tableShare: tableShare?, sender: Any)
  76. func tapMenu(with tableShare: tableShare?, sender: Any)
  77. }