NCSectionFooter.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // NCSectionFooter.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 20/07/24.
  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 Foundation
  24. import UIKit
  25. protocol NCSectionFooterDelegate: AnyObject {
  26. func tapButtonSection(_ sender: Any, metadataForSection: NCMetadataForSection?)
  27. }
  28. class NCSectionFooter: UICollectionReusableView {
  29. @IBOutlet weak var buttonSection: UIButton!
  30. @IBOutlet weak var activityIndicatorSection: UIActivityIndicatorView!
  31. @IBOutlet weak var labelSection: UILabel!
  32. @IBOutlet weak var separator: UIView!
  33. @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
  34. @IBOutlet weak var buttonSectionHeightConstraint: NSLayoutConstraint!
  35. weak var delegate: NCSectionFooterDelegate?
  36. var metadataForSection: NCMetadataForSection?
  37. let utilityFileSystem = NCUtilityFileSystem()
  38. override func awakeFromNib() {
  39. super.awakeFromNib()
  40. self.backgroundColor = .clear
  41. labelSection.textColor = NCBrandColor.shared.textColor2
  42. labelSection.text = ""
  43. separator.backgroundColor = .separator
  44. separatorHeightConstraint.constant = 0.5
  45. buttonIsHidden(true)
  46. activityIndicatorSection.isHidden = true
  47. activityIndicatorSection.color = NCBrandColor.shared.textColor
  48. }
  49. func setTitleLabel(directories: Int, files: Int, size: Int64) {
  50. var foldersText = ""
  51. var filesText = ""
  52. if directories > 1 {
  53. foldersText = "\(directories) " + NSLocalizedString("_folders_", comment: "")
  54. } else if directories == 1 {
  55. foldersText = "1 " + NSLocalizedString("_folder_", comment: "")
  56. }
  57. if files > 1 {
  58. filesText = "\(files) " + NSLocalizedString("_files_", comment: "") + " • " + utilityFileSystem.transformedSize(size)
  59. } else if files == 1 {
  60. filesText = "1 " + NSLocalizedString("_file_", comment: "") + " • " + utilityFileSystem.transformedSize(size)
  61. }
  62. if foldersText.isEmpty {
  63. labelSection.text = filesText
  64. } else if filesText.isEmpty {
  65. labelSection.text = foldersText
  66. } else {
  67. labelSection.text = foldersText + " • " + filesText
  68. }
  69. }
  70. func setTitleLabel(_ text: String) {
  71. labelSection.text = text
  72. }
  73. func setButtonText(_ text: String) {
  74. buttonSection.setTitle(text, for: .normal)
  75. }
  76. func separatorIsHidden(_ isHidden: Bool) {
  77. separator.isHidden = isHidden
  78. }
  79. func buttonIsHidden(_ isHidden: Bool) {
  80. buttonSection.isHidden = isHidden
  81. if isHidden {
  82. buttonSectionHeightConstraint.constant = 0
  83. } else {
  84. buttonSectionHeightConstraint.constant = NCGlobal.shared.heightFooterButton
  85. }
  86. }
  87. func showActivityIndicatorSection() {
  88. buttonSection.isHidden = true
  89. buttonSectionHeightConstraint.constant = NCGlobal.shared.heightFooterButton
  90. activityIndicatorSection.isHidden = false
  91. activityIndicatorSection.startAnimating()
  92. }
  93. func hideActivityIndicatorSection() {
  94. activityIndicatorSection.stopAnimating()
  95. activityIndicatorSection.isHidden = true
  96. }
  97. // MARK: - Action
  98. @IBAction func touchUpInsideButton(_ sender: Any) {
  99. delegate?.tapButtonSection(sender, metadataForSection: metadataForSection)
  100. }
  101. }