NCSectionFirstHeaderEmptyData.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // NCSectionFirstHeaderEmptyData.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/10/2018.
  6. // Copyright © 2018 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. import MarkdownKit
  25. protocol NCSectionFirstHeaderEmptyDataDelegate: AnyObject {
  26. func tapButtonTransfer(_ sender: Any)
  27. }
  28. class NCSectionFirstHeaderEmptyData: UICollectionReusableView {
  29. @IBOutlet weak var viewTransfer: UIView!
  30. @IBOutlet weak var viewTransferHeightConstraint: NSLayoutConstraint!
  31. @IBOutlet weak var buttonTransfer: UIButton!
  32. @IBOutlet weak var imageButtonTransfer: UIImageView!
  33. @IBOutlet weak var labelTransfer: UILabel!
  34. @IBOutlet weak var progressTransfer: UIProgressView!
  35. @IBOutlet weak var transferSeparatorBottom: UIView!
  36. @IBOutlet weak var transferSeparatorBottomHeightConstraint: NSLayoutConstraint!
  37. @IBOutlet weak var emptyImage: UIImageView!
  38. @IBOutlet weak var emptyTitle: UILabel!
  39. @IBOutlet weak var emptyDescription: UILabel!
  40. weak var delegate: NCSectionFirstHeaderEmptyDataDelegate?
  41. override func awakeFromNib() {
  42. super.awakeFromNib()
  43. initHeader()
  44. }
  45. override func prepareForReuse() {
  46. super.prepareForReuse()
  47. initHeader()
  48. }
  49. func initHeader() {
  50. viewTransferHeightConstraint.constant = 0
  51. viewTransfer.isHidden = true
  52. buttonTransfer.backgroundColor = .clear
  53. buttonTransfer.setImage(nil, for: .normal)
  54. buttonTransfer.layer.cornerRadius = 6
  55. buttonTransfer.layer.masksToBounds = true
  56. imageButtonTransfer.image = NCUtility().loadImage(named: "stop.circle")
  57. imageButtonTransfer.tintColor = .white
  58. labelTransfer.text = ""
  59. progressTransfer.progress = 0
  60. progressTransfer.tintColor = NCBrandColor.shared.brandElement
  61. progressTransfer.trackTintColor = NCBrandColor.shared.brandElement.withAlphaComponent(0.2)
  62. transferSeparatorBottom.backgroundColor = .separator
  63. transferSeparatorBottomHeightConstraint.constant = 0.5
  64. emptyImage.image = nil
  65. emptyTitle.text = ""
  66. emptyDescription.text = ""
  67. }
  68. // MARK: - Action
  69. @IBAction func touchUpTransfer(_ sender: Any) {
  70. delegate?.tapButtonTransfer(sender)
  71. }
  72. // MARK: - Transfer
  73. func setViewTransfer(isHidden: Bool, ocId: String? = nil, text: String? = nil, progress: Float? = nil) {
  74. labelTransfer.text = text
  75. viewTransfer.isHidden = isHidden
  76. progressTransfer.progress = 0
  77. if isHidden {
  78. viewTransferHeightConstraint.constant = 0
  79. } else {
  80. var image: UIImage?
  81. if let ocId,
  82. let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  83. image = NCUtility().getIcon(metadata: metadata)?.darken()
  84. if image == nil {
  85. image = NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true)
  86. buttonTransfer.backgroundColor = .lightGray
  87. } else {
  88. buttonTransfer.backgroundColor = .clear
  89. }
  90. }
  91. viewTransferHeightConstraint.constant = NCGlobal.shared.heightHeaderTransfer
  92. if let progress {
  93. progressTransfer.progress = progress
  94. }
  95. }
  96. }
  97. }