NCSectionHeaderFooter.swift 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // NCSectionHeaderFooter.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 Foundation
  24. class NCSectionHeaderMenu: 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 viewLabelSection: UIView!
  30. @IBOutlet weak var labelSection: UILabel!
  31. @IBOutlet weak var labelSectionHeightConstraint: NSLayoutConstraint!
  32. @IBOutlet weak var separator: UIView!
  33. var delegate: NCSectionHeaderMenuDelegate?
  34. override func awakeFromNib() {
  35. super.awakeFromNib()
  36. buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchList"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
  37. buttonOrder.setTitle("", for: .normal)
  38. buttonOrder.setTitleColor(NCBrandColor.sharedInstance.brandElement, for: .normal)
  39. buttonMore.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
  40. viewLabelSection.backgroundColor = NCBrandColor.sharedInstance.select
  41. separator.backgroundColor = NCBrandColor.sharedInstance.separator
  42. self.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  43. }
  44. func setTitleSorted(datasourceTitleButton: String) {
  45. let title = NSLocalizedString(datasourceTitleButton, comment: "")
  46. let size = title.size(withAttributes:[.font: buttonOrder.titleLabel?.font as Any])
  47. buttonOrder.setTitle(title, for: .normal)
  48. buttonOrderWidthConstraint.constant = size.width + 5
  49. }
  50. func setTitleLabel(sectionDatasource: CCSectionDataSourceMetadata, section: Int) {
  51. var title = ""
  52. if sectionDatasource.sections.object(at: section) is String {
  53. title = sectionDatasource.sections.object(at: section) as! String
  54. }
  55. if sectionDatasource.sections.object(at: section) is Date {
  56. let titleDate = sectionDatasource.sections.object(at: section) as! Date
  57. title = CCUtility.getTitleSectionDate(titleDate)
  58. }
  59. if title.contains("download") {
  60. labelSection.text = NSLocalizedString("_title_section_download_", comment: "")
  61. } else if title.contains("upload") {
  62. labelSection.text = NSLocalizedString("_title_section_upload_", comment: "")
  63. } else {
  64. labelSection.text = NSLocalizedString(title, comment: "")
  65. }
  66. }
  67. func setStatusButton(count: Int) {
  68. if 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?.tapMoreHeader(sender: sender)
  80. }
  81. @IBAction func touchUpInsideSwitch(_ sender: Any) {
  82. delegate?.tapSwitchHeader(sender: sender)
  83. }
  84. @IBAction func touchUpInsideOrder(_ sender: Any) {
  85. delegate?.tapOrderHeader(sender: sender)
  86. }
  87. }
  88. protocol NCSectionHeaderMenuDelegate {
  89. func tapSwitchHeader(sender: Any)
  90. func tapMoreHeader(sender: Any)
  91. func tapOrderHeader(sender: Any)
  92. }
  93. class NCSectionHeader: UICollectionReusableView {
  94. @IBOutlet weak var labelSection: UILabel!
  95. override func awakeFromNib() {
  96. super.awakeFromNib()
  97. self.backgroundColor = NCBrandColor.sharedInstance.select
  98. }
  99. func setTitleLabel(sectionDatasource: CCSectionDataSourceMetadata, section: Int) {
  100. var title = ""
  101. if sectionDatasource.sections.object(at: section) is String {
  102. title = sectionDatasource.sections.object(at: section) as! String
  103. }
  104. if sectionDatasource.sections.object(at: section) is Date {
  105. let titleDate = sectionDatasource.sections.object(at: section) as! Date
  106. title = CCUtility.getTitleSectionDate(titleDate)
  107. }
  108. if title.contains("download") {
  109. labelSection.text = NSLocalizedString("_title_section_download_", comment: "")
  110. } else if title.contains("upload") {
  111. labelSection.text = NSLocalizedString("_title_section_upload_", comment: "")
  112. } else {
  113. labelSection.text = NSLocalizedString(title, comment: "")
  114. }
  115. }
  116. }
  117. class NCSectionFooter: UICollectionReusableView {
  118. @IBOutlet weak var labelSection: UILabel!
  119. override func awakeFromNib() {
  120. super.awakeFromNib()
  121. self.backgroundColor = UIColor.clear
  122. labelSection.textColor = NCBrandColor.sharedInstance.icon
  123. }
  124. func setTitleLabel(sectionDatasource: CCSectionDataSourceMetadata) {
  125. var foldersText = ""
  126. var filesText = ""
  127. if sectionDatasource.directories > 1 {
  128. foldersText = "\(sectionDatasource.directories) " + NSLocalizedString("_folders_", comment: "")
  129. } else if sectionDatasource.directories == 1 {
  130. foldersText = "1 " + NSLocalizedString("_folder_", comment: "")
  131. }
  132. if sectionDatasource.files > 1 {
  133. filesText = "\(sectionDatasource.files) " + NSLocalizedString("_files_", comment: "") + " " + CCUtility.transformedSize(sectionDatasource.totalSize)
  134. } else if sectionDatasource.files == 1 {
  135. filesText = "1 " + NSLocalizedString("_file_", comment: "") + " " + CCUtility.transformedSize(sectionDatasource.totalSize)
  136. }
  137. if foldersText == "" {
  138. labelSection.text = filesText
  139. } else if filesText == "" {
  140. labelSection.text = foldersText
  141. } else {
  142. labelSection.text = foldersText + ", " + filesText
  143. }
  144. }
  145. }