NCPhotoCell.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // NCPhotoCell.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 13/07/2024.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@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. //
  23. import UIKit
  24. class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol {
  25. @IBOutlet weak var imageItem: UIImageView!
  26. @IBOutlet weak var imageSelect: UIImageView!
  27. @IBOutlet weak var imageStatus: UIImageView!
  28. @IBOutlet weak var buttonMore: UIButton!
  29. @IBOutlet weak var imageVisualEffect: UIVisualEffectView!
  30. var ocId = ""
  31. var ocIdTransfer = ""
  32. var user = ""
  33. weak var photoCellDelegate: NCPhotoCellDelegate?
  34. var fileOcId: String? {
  35. get { return ocId }
  36. set { ocId = newValue ?? "" }
  37. }
  38. var fileOcIdTransfer: String? {
  39. get { return ocIdTransfer }
  40. set { ocIdTransfer = newValue ?? "" }
  41. }
  42. var filePreviewImageView: UIImageView? {
  43. get { return imageItem }
  44. set { imageItem = newValue }
  45. }
  46. var fileUser: String? {
  47. get { return user }
  48. set { user = newValue ?? "" }
  49. }
  50. var fileStatusImage: UIImageView? {
  51. get { return imageStatus }
  52. set { imageStatus = newValue }
  53. }
  54. override func awakeFromNib() {
  55. super.awakeFromNib()
  56. initCell()
  57. }
  58. override func prepareForReuse() {
  59. super.prepareForReuse()
  60. initCell()
  61. }
  62. func initCell() {
  63. accessibilityHint = nil
  64. accessibilityLabel = nil
  65. accessibilityValue = nil
  66. imageItem.image = nil
  67. imageSelect.isHidden = true
  68. imageSelect.image = NCImageCache.shared.getImageCheckedYes()
  69. imageStatus.image = nil
  70. imageVisualEffect.clipsToBounds = true
  71. imageVisualEffect.alpha = 0.5
  72. let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:)))
  73. longPressedGesture.minimumPressDuration = 0.5
  74. longPressedGesture.delegate = self
  75. longPressedGesture.delaysTouchesBegan = true
  76. self.addGestureRecognizer(longPressedGesture)
  77. }
  78. override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? {
  79. return nil
  80. }
  81. @IBAction func touchUpInsideMore(_ sender: Any) {
  82. photoCellDelegate?.tapMorePhotoItem(with: ocId, ocIdTransfer: ocIdTransfer, image: imageItem.image, sender: sender)
  83. }
  84. @objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) {
  85. photoCellDelegate?.longPressPhotoItem(with: ocId, ocIdTransfer: ocIdTransfer, gestureRecognizer: gestureRecognizer)
  86. }
  87. fileprivate func setA11yActions() {
  88. self.accessibilityCustomActions = [
  89. UIAccessibilityCustomAction(
  90. name: NSLocalizedString("_more_", comment: ""),
  91. target: self,
  92. selector: #selector(touchUpInsideMore))
  93. ]
  94. }
  95. func setButtonMore(image: UIImage) {
  96. buttonMore.setImage(image, for: .normal)
  97. setA11yActions()
  98. }
  99. func hideButtonMore(_ status: Bool) {
  100. buttonMore.isHidden = status
  101. }
  102. func hideImageStatus(_ status: Bool) {
  103. imageStatus.isHidden = status
  104. }
  105. func selected(_ status: Bool, isEditMode: Bool) {
  106. if status {
  107. imageSelect.isHidden = false
  108. imageVisualEffect.isHidden = false
  109. imageSelect.image = NCImageCache.shared.getImageCheckedYes()
  110. } else {
  111. imageSelect.isHidden = true
  112. imageVisualEffect.isHidden = true
  113. }
  114. }
  115. func setAccessibility(label: String, value: String) {
  116. accessibilityLabel = label
  117. accessibilityValue = value
  118. }
  119. }
  120. protocol NCPhotoCellDelegate: AnyObject {
  121. func tapMorePhotoItem(with ocId: String, ocIdTransfer: String, image: UIImage?, sender: Any)
  122. func longPressPhotoItem(with objectId: String, ocIdTransfer: String, gestureRecognizer: UILongPressGestureRecognizer)
  123. }