NCTrashSectionHeaderFooter.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // NCTrashSectionHeaderFooter.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. class NCTrashSectionHeaderMenu: UICollectionReusableView {
  25. @IBOutlet weak var buttonMore: UIButton!
  26. @IBOutlet weak var buttonSwitch: UIButton!
  27. @IBOutlet weak var buttonOrder: UIButton!
  28. @IBOutlet weak var buttonOrderWidthConstraint: NSLayoutConstraint!
  29. @IBOutlet weak var separator: UIView!
  30. @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint!
  31. var delegate: NCTrashSectionHeaderMenuDelegate?
  32. override func awakeFromNib() {
  33. super.awakeFromNib()
  34. buttonSwitch.setImage(UIImage.init(named: "switchList")!.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
  35. buttonOrder.setTitle("", for: .normal)
  36. buttonOrder.setTitleColor(NCBrandColor.shared.brandElement, for: .normal)
  37. buttonMore.setImage(UIImage.init(named: "more")!.image(color: NCBrandColor.shared.gray, size: 25), for: .normal)
  38. separator.backgroundColor = NCBrandColor.shared.separator
  39. separatorHeightConstraint.constant = 0.5
  40. backgroundColor = NCBrandColor.shared.systemBackground
  41. }
  42. func setTitleSorted(datasourceTitleButton: String) {
  43. let title = NSLocalizedString(datasourceTitleButton, comment: "")
  44. let size = title.size(withAttributes:[.font: buttonOrder.titleLabel?.font as Any])
  45. buttonOrder.setTitle(title, for: .normal)
  46. buttonOrderWidthConstraint.constant = size.width + 5
  47. }
  48. func setStatusButton(datasource: [tableTrash]) {
  49. if datasource.count == 0 {
  50. buttonSwitch.isEnabled = false
  51. buttonOrder.isEnabled = false
  52. buttonMore.isEnabled = false
  53. } else {
  54. buttonSwitch.isEnabled = true
  55. buttonOrder.isEnabled = true
  56. buttonMore.isEnabled = true
  57. }
  58. }
  59. @IBAction func touchUpInsideMore(_ sender: Any) {
  60. delegate?.tapMoreHeaderMenu(sender: sender)
  61. }
  62. @IBAction func touchUpInsideSwitch(_ sender: Any) {
  63. delegate?.tapSwitchHeaderMenu(sender: sender)
  64. }
  65. @IBAction func touchUpInsideOrder(_ sender: Any) {
  66. delegate?.tapOrderHeaderMenu(sender: sender)
  67. }
  68. }
  69. protocol NCTrashSectionHeaderMenuDelegate {
  70. func tapSwitchHeaderMenu(sender: Any)
  71. func tapMoreHeaderMenu(sender: Any)
  72. func tapOrderHeaderMenu(sender: Any)
  73. }
  74. class NCTrashSectionFooter: UICollectionReusableView {
  75. @IBOutlet weak var labelFooter: UILabel!
  76. override func awakeFromNib() {
  77. super.awakeFromNib()
  78. labelFooter.textColor = NCBrandColor.shared.gray
  79. }
  80. func setTitleLabelFooter(datasource: [tableTrash]) {
  81. var folders: Int = 0, foldersText = ""
  82. var files: Int = 0, filesText = ""
  83. var size: Int64 = 0
  84. for record: tableTrash in datasource {
  85. if record.directory {
  86. folders += 1
  87. } else {
  88. files += 1
  89. size = size + record.size
  90. }
  91. }
  92. if folders > 1 {
  93. foldersText = "\(folders) " + NSLocalizedString("_folders_", comment: "")
  94. } else if folders == 1 {
  95. foldersText = "1 " + NSLocalizedString("_folder_", comment: "")
  96. }
  97. if files > 1 {
  98. filesText = "\(files) " + NSLocalizedString("_files_", comment: "") + " " + CCUtility.transformedSize(size)
  99. } else if files == 1 {
  100. filesText = "1 " + NSLocalizedString("_file_", comment: "") + " " + CCUtility.transformedSize(size)
  101. }
  102. if foldersText == "" {
  103. labelFooter.text = filesText
  104. } else if filesText == "" {
  105. labelFooter.text = foldersText
  106. } else {
  107. labelFooter.text = foldersText + ", " + filesText
  108. }
  109. }
  110. }