NCTrashListCell.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // NCTrashListCell.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 08/10/2018.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. // Copyright © 2022 Henrik Storch. All rights reserved.
  8. //
  9. // Author Henrik Storch <henrik.storch@nextcloud.com>
  10. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import UIKit
  26. protocol NCTrashListCellDelegate: AnyObject {
  27. func tapRestoreListItem(with objectId: String, image: UIImage?, sender: Any)
  28. func tapMoreListItem(with objectId: String, image: UIImage?, sender: Any)
  29. }
  30. class NCTrashListCell: UICollectionViewCell, NCTrashCellProtocol {
  31. @IBOutlet weak var imageItem: UIImageView!
  32. @IBOutlet weak var imageItemLeftConstraint: NSLayoutConstraint!
  33. @IBOutlet weak var imageSelect: UIImageView!
  34. @IBOutlet weak var labelTitle: UILabel!
  35. @IBOutlet weak var labelInfo: UILabel!
  36. @IBOutlet weak var imageRestore: UIImageView!
  37. @IBOutlet weak var imageMore: UIImageView!
  38. @IBOutlet weak var buttonMore: UIButton!
  39. @IBOutlet weak var buttonRestore: UIButton!
  40. @IBOutlet weak var separator: UIView!
  41. @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
  42. weak var delegate: NCTrashListCellDelegate?
  43. var objectId = ""
  44. var account = ""
  45. override func awakeFromNib() {
  46. super.awakeFromNib()
  47. initCell()
  48. }
  49. override func prepareForReuse() {
  50. super.prepareForReuse()
  51. initCell()
  52. }
  53. func initCell() {
  54. isAccessibilityElement = true
  55. self.accessibilityCustomActions = [
  56. UIAccessibilityCustomAction(
  57. name: NSLocalizedString("_restore_", comment: ""),
  58. target: self,
  59. selector: #selector(touchUpInsideRestore)),
  60. UIAccessibilityCustomAction(
  61. name: NSLocalizedString("_delete_", comment: ""),
  62. target: self,
  63. selector: #selector(touchUpInsideMore))
  64. ]
  65. imageRestore.image = NCUtility().loadImage(named: "arrow.circlepath", colors: [NCBrandColor.shared.iconImageColor])
  66. imageMore.image = NCUtility().loadImage(named: "trash", colors: [.red])
  67. imageItem.layer.cornerRadius = 6
  68. imageItem.layer.masksToBounds = true
  69. separator.backgroundColor = .separator
  70. separatorHeightConstraint.constant = 0.5
  71. }
  72. @IBAction func touchUpInsideMore(_ sender: Any) {
  73. delegate?.tapMoreListItem(with: objectId, image: imageItem.image, sender: sender)
  74. }
  75. @IBAction func touchUpInsideRestore(_ sender: Any) {
  76. delegate?.tapRestoreListItem(with: objectId, image: imageItem.image, sender: sender)
  77. }
  78. func selected(_ status: Bool, isEditMode: Bool, account: String) {
  79. if isEditMode {
  80. imageItemLeftConstraint.constant = 45
  81. imageSelect.isHidden = false
  82. imageRestore.isHidden = true
  83. buttonRestore.isHidden = true
  84. imageMore.isHidden = true
  85. buttonMore.isHidden = true
  86. } else {
  87. imageItemLeftConstraint.constant = 10
  88. imageSelect.isHidden = true
  89. imageRestore.isHidden = false
  90. buttonRestore.isHidden = false
  91. imageMore.isHidden = false
  92. buttonMore.isHidden = false
  93. backgroundView = nil
  94. }
  95. if status {
  96. var blurEffectView: UIView?
  97. blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
  98. blurEffectView?.backgroundColor = .lightGray
  99. blurEffectView?.frame = self.bounds
  100. blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  101. imageSelect.image = NCImageCache.shared.getImageCheckedYes()
  102. backgroundView = blurEffectView
  103. separator.isHidden = true
  104. } else {
  105. imageSelect.image = NCImageCache.shared.getImageCheckedNo()
  106. backgroundView = nil
  107. separator.isHidden = false
  108. }
  109. }
  110. }