NCTrashSectionHeaderFooter.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 <m.faggiana@twsweb.it>
  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. 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. var delegate: NCTrashSectionHeaderMenuDelegate?
  31. override func awakeFromNib() {
  32. super.awakeFromNib()
  33. // Button More
  34. let capabilities = NCManageDatabase.sharedInstance.getCapabilites()
  35. if capabilities != nil && capabilities!.versionMajor >= Int(k_trash_version_available_more_fix) {
  36. buttonMore.isHidden = false
  37. } else {
  38. buttonMore.isHidden = true
  39. }
  40. buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchList"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
  41. buttonOrder.setTitle("", for: .normal)
  42. buttonOrder.setTitleColor(NCBrandColor.sharedInstance.icon, for: .normal)
  43. buttonMore.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
  44. separator.backgroundColor = NCBrandColor.sharedInstance.seperator
  45. }
  46. func setTitleOrder(datasourceSorted: String, datasourceAscending: Bool) {
  47. // Order (∨∧▽△)
  48. var title = ""
  49. switch datasourceSorted {
  50. case "fileName":
  51. if datasourceAscending == true { title = NSLocalizedString("_order_by_name_a_z_", comment: "") }
  52. if datasourceAscending == false { title = NSLocalizedString("_order_by_name_z_a_", comment: "") }
  53. case "date":
  54. if datasourceAscending == false { title = NSLocalizedString("_order_by_date_more_recent_", comment: "") }
  55. if datasourceAscending == true { title = NSLocalizedString("_order_by_date_less_recent_", comment: "") }
  56. case "size":
  57. if datasourceAscending == true { title = NSLocalizedString("_order_by_size_smallest_", comment: "") }
  58. if datasourceAscending == false { title = NSLocalizedString("_order_by_size_largest_", comment: "") }
  59. default:
  60. title = NSLocalizedString("_order_by_", comment: "") + " " + datasourceSorted
  61. }
  62. title = title + " ▽"
  63. let size = title.size(withAttributes:[.font: buttonOrder.titleLabel?.font as Any])
  64. buttonOrder.setTitle(title, for: .normal)
  65. buttonOrderWidthConstraint.constant = size.width + 5
  66. }
  67. func setStatusButton(datasource: [tableTrash]) {
  68. if datasource.count == 0 {
  69. buttonSwitch.isEnabled = false
  70. buttonOrder.isEnabled = false
  71. buttonMore.isEnabled = false
  72. } else {
  73. buttonSwitch.isEnabled = true
  74. buttonOrder.isEnabled = true
  75. buttonMore.isEnabled = true
  76. }
  77. }
  78. @IBAction func touchUpInsideMore(_ sender: Any) {
  79. delegate?.tapMoreHeaderMenu(sender: sender)
  80. }
  81. @IBAction func touchUpInsideSwitch(_ sender: Any) {
  82. delegate?.tapSwitchHeaderMenu(sender: sender)
  83. }
  84. @IBAction func touchUpInsideOrder(_ sender: Any) {
  85. delegate?.tapOrderHeaderMenu(sender: sender)
  86. }
  87. }
  88. protocol NCTrashSectionHeaderMenuDelegate {
  89. func tapSwitchHeaderMenu(sender: Any)
  90. func tapMoreHeaderMenu(sender: Any)
  91. func tapOrderHeaderMenu(sender: Any)
  92. }
  93. class NCTrashSectionFooter: UICollectionReusableView {
  94. @IBOutlet weak var labelFooter: UILabel!
  95. override func awakeFromNib() {
  96. super.awakeFromNib()
  97. labelFooter.textColor = NCBrandColor.sharedInstance.icon
  98. }
  99. func setTitleLabelFooter(datasource: [tableTrash]) {
  100. var folders: Int = 0, foldersText = ""
  101. var files: Int = 0, filesText = ""
  102. var size: Double = 0
  103. for record: tableTrash in datasource {
  104. if record.directory {
  105. folders += 1
  106. } else {
  107. files += 1
  108. size = size + record.size
  109. }
  110. }
  111. if folders > 1 {
  112. foldersText = "\(folders) " + NSLocalizedString("_folders_", comment: "")
  113. } else if folders == 1 {
  114. foldersText = "1 " + NSLocalizedString("_folder_", comment: "")
  115. }
  116. if files > 1 {
  117. filesText = "\(files) " + NSLocalizedString("_files_", comment: "") + " " + CCUtility.transformedSize(size)
  118. } else if files == 1 {
  119. filesText = "1 " + NSLocalizedString("_file_", comment: "") + " " + CCUtility.transformedSize(size)
  120. }
  121. if foldersText == "" {
  122. labelFooter.text = filesText
  123. } else if filesText == "" {
  124. labelFooter.text = foldersText
  125. } else {
  126. labelFooter.text = foldersText + ", " + filesText
  127. }
  128. }
  129. }