NCPhotoCell.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 imageVisualEffect: UIVisualEffectView!
  29. @IBOutlet weak var labelTitle: UILabel!
  30. @IBOutlet weak var imageItemBottom: NSLayoutConstraint!
  31. var objectId = ""
  32. var indexPath = IndexPath()
  33. private var user = ""
  34. weak var photoCellDelegate: NCPhotoCellDelegate?
  35. var namedButtonMore = ""
  36. var fileObjectId: String? {
  37. get { return objectId }
  38. set { objectId = newValue ?? "" }
  39. }
  40. var filePreviewImageView: UIImageView? {
  41. get { return imageItem }
  42. set { imageItem = newValue }
  43. }
  44. var filePreviewImageBottom: NSLayoutConstraint? {
  45. get { return imageItemBottom }
  46. set { imageItemBottom = newValue}
  47. }
  48. var fileUser: String? {
  49. get { return user }
  50. set { user = newValue ?? "" }
  51. }
  52. var fileTitleLabel: UILabel? {
  53. get { return labelTitle }
  54. set { labelTitle = newValue }
  55. }
  56. var fileInfoLabel: UILabel? {
  57. get { return nil }
  58. set { }
  59. }
  60. var fileSubinfoLabel: UILabel? {
  61. get { return nil }
  62. set { }
  63. }
  64. var fileStatusImage: UIImageView? {
  65. get { return imageStatus }
  66. set { imageStatus = newValue }
  67. }
  68. var fileLocalImage: UIImageView? {
  69. get { return nil }
  70. set { }
  71. }
  72. var fileFavoriteImage: UIImageView? {
  73. get { return nil }
  74. set { }
  75. }
  76. override func awakeFromNib() {
  77. super.awakeFromNib()
  78. initCell()
  79. }
  80. override func prepareForReuse() {
  81. super.prepareForReuse()
  82. initCell()
  83. }
  84. func initCell() {
  85. accessibilityHint = nil
  86. accessibilityLabel = nil
  87. accessibilityValue = nil
  88. imageVisualEffect.clipsToBounds = true
  89. imageVisualEffect.alpha = 0.5
  90. imageSelect.isHidden = true
  91. imageSelect.image = NCImageCache.images.checkedYes
  92. let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:)))
  93. longPressedGesture.minimumPressDuration = 0.5
  94. longPressedGesture.delegate = self
  95. longPressedGesture.delaysTouchesBegan = true
  96. self.addGestureRecognizer(longPressedGesture)
  97. }
  98. override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? {
  99. return nil
  100. }
  101. @objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) {
  102. photoCellDelegate?.longPressGridItem(with: objectId, indexPath: indexPath, gestureRecognizer: gestureRecognizer)
  103. }
  104. func selected(_ status: Bool, isEditMode: Bool) {
  105. if status {
  106. imageSelect.isHidden = false
  107. imageVisualEffect.isHidden = false
  108. } else {
  109. imageSelect.isHidden = true
  110. imageVisualEffect.isHidden = true
  111. }
  112. }
  113. func setAccessibility(label: String, value: String) {
  114. accessibilityLabel = label
  115. accessibilityValue = value
  116. }
  117. func setIconOutlines() {
  118. if imageStatus.image != nil {
  119. imageStatus.makeCircularBackground(withColor: .systemBackground)
  120. } else {
  121. imageStatus.backgroundColor = .clear
  122. }
  123. }
  124. }
  125. protocol NCPhotoCellDelegate: AnyObject {
  126. func longPressGridItem(with objectId: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer)
  127. }