NCTrashListCell.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 indexPath = IndexPath()
  45. override func awakeFromNib() {
  46. super.awakeFromNib()
  47. isAccessibilityElement = true
  48. self.accessibilityCustomActions = [
  49. UIAccessibilityCustomAction(
  50. name: NSLocalizedString("_restore_", comment: ""),
  51. target: self,
  52. selector: #selector(touchUpInsideRestore)),
  53. UIAccessibilityCustomAction(
  54. name: NSLocalizedString("_delete_", comment: ""),
  55. target: self,
  56. selector: #selector(touchUpInsideMore))
  57. ]
  58. imageRestore.image = UIImage(systemName: "arrow.circlepath")
  59. imageRestore.tintColor = .gray
  60. imageMore.image = UIImage(systemName: "trash")
  61. imageMore.tintColor = .red
  62. imageItem.layer.cornerRadius = 6
  63. imageItem.layer.masksToBounds = true
  64. separator.backgroundColor = .separator
  65. separatorHeightConstraint.constant = 0.5
  66. }
  67. @IBAction func touchUpInsideMore(_ sender: Any) {
  68. delegate?.tapMoreListItem(with: objectId, image: imageItem.image, sender: sender)
  69. }
  70. @IBAction func touchUpInsideRestore(_ sender: Any) {
  71. delegate?.tapRestoreListItem(with: objectId, image: imageItem.image, sender: sender)
  72. }
  73. func selectMode(_ status: Bool) {
  74. if status {
  75. imageItemLeftConstraint.constant = 45
  76. imageSelect.isHidden = false
  77. imageRestore.isHidden = true
  78. buttonRestore.isHidden = true
  79. imageMore.isHidden = true
  80. buttonMore.isHidden = true
  81. } else {
  82. imageItemLeftConstraint.constant = 10
  83. imageSelect.isHidden = true
  84. imageRestore.isHidden = false
  85. buttonRestore.isHidden = false
  86. imageMore.isHidden = false
  87. buttonMore.isHidden = false
  88. backgroundView = nil
  89. }
  90. }
  91. func selected(_ status: Bool) {
  92. if status {
  93. var blurEffect: UIVisualEffect?
  94. var blurEffectView: UIView?
  95. imageSelect.image = NCImageCache.images.checkedYes
  96. if traitCollection.userInterfaceStyle == .dark {
  97. blurEffect = UIBlurEffect(style: .dark)
  98. blurEffectView = UIVisualEffectView(effect: blurEffect)
  99. blurEffectView?.backgroundColor = .black
  100. } else {
  101. blurEffect = UIBlurEffect(style: .extraLight)
  102. blurEffectView = UIVisualEffectView(effect: blurEffect)
  103. blurEffectView?.backgroundColor = .lightGray
  104. }
  105. blurEffectView?.frame = self.bounds
  106. blurEffectView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  107. backgroundView = blurEffectView
  108. separator.isHidden = true
  109. } else {
  110. imageSelect.image = NCImageCache.images.checkedNo
  111. backgroundView = nil
  112. separator.isHidden = false
  113. }
  114. }
  115. }