NCSectionHeaderFooter.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. import MarkdownKit
  25. class NCSectionHeaderMenu: UICollectionReusableView {
  26. @IBOutlet weak var buttonMore: UIButton!
  27. @IBOutlet weak var buttonSwitch: UIButton!
  28. @IBOutlet weak var buttonOrder: UIButton!
  29. @IBOutlet weak var buttonOrderWidthConstraint: NSLayoutConstraint!
  30. @IBOutlet weak var viewRichWorkspace: UIView!
  31. @IBOutlet weak var viewRichWorkspaceHeightConstraint: NSLayoutConstraint!
  32. @IBOutlet weak var textViewRichWorkspace: UITextView!
  33. @IBOutlet weak var separator: UIView!
  34. var delegate: NCSectionHeaderMenuDelegate?
  35. private var markdownParser = MarkdownParser()
  36. override func awakeFromNib() {
  37. super.awakeFromNib()
  38. buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchList"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), for: .normal)
  39. buttonOrder.setTitle("", for: .normal)
  40. buttonOrder.setTitleColor(NCBrandColor.sharedInstance.brandElement, for: .normal)
  41. buttonMore.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), for: .normal)
  42. separator.backgroundColor = NCBrandColor.sharedInstance.separator
  43. self.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  44. }
  45. func setTitleSorted(datasourceTitleButton: String) {
  46. let title = NSLocalizedString(datasourceTitleButton, comment: "")
  47. let size = title.size(withAttributes:[.font: buttonOrder.titleLabel?.font as Any])
  48. buttonOrder.setTitle(title, for: .normal)
  49. buttonOrderWidthConstraint.constant = size.width + 5
  50. }
  51. func setStatusButton(count: Int) {
  52. if count == 0 {
  53. buttonSwitch.isEnabled = false
  54. buttonOrder.isEnabled = false
  55. buttonMore.isEnabled = false
  56. } else {
  57. buttonSwitch.isEnabled = true
  58. buttonOrder.isEnabled = true
  59. buttonMore.isEnabled = true
  60. }
  61. }
  62. func setRichWorkspaceText(richWorkspaceText: String?) {
  63. guard let richWorkspaceText = richWorkspaceText else { return }
  64. textViewRichWorkspace.attributedText = markdownParser.parse(richWorkspaceText)
  65. }
  66. @IBAction func touchUpInsideMore(_ sender: Any) {
  67. delegate?.tapMoreHeader(sender: sender)
  68. }
  69. @IBAction func touchUpInsideSwitch(_ sender: Any) {
  70. delegate?.tapSwitchHeader(sender: sender)
  71. }
  72. @IBAction func touchUpInsideOrder(_ sender: Any) {
  73. delegate?.tapOrderHeader(sender: sender)
  74. }
  75. }
  76. protocol NCSectionHeaderMenuDelegate {
  77. func tapSwitchHeader(sender: Any)
  78. func tapMoreHeader(sender: Any)
  79. func tapOrderHeader(sender: Any)
  80. }
  81. class NCSectionHeader: UICollectionReusableView {
  82. @IBOutlet weak var labelSection: UILabel!
  83. override func awakeFromNib() {
  84. super.awakeFromNib()
  85. self.backgroundColor = NCBrandColor.sharedInstance.select
  86. }
  87. func setTitleLabel(title: String) {
  88. /*
  89. var title = ""
  90. if sectionDatasource.sections.object(at: section) is String {
  91. title = sectionDatasource.sections.object(at: section) as! String
  92. }
  93. if sectionDatasource.sections.object(at: section) is Date {
  94. let titleDate = sectionDatasource.sections.object(at: section) as! Date
  95. title = CCUtility.getTitleSectionDate(titleDate)
  96. }
  97. */
  98. if title.contains("download") {
  99. labelSection.text = NSLocalizedString("_title_section_download_", comment: "")
  100. } else if title.contains("upload") {
  101. labelSection.text = NSLocalizedString("_title_section_upload_", comment: "")
  102. } else {
  103. labelSection.text = NSLocalizedString(title, comment: "")
  104. }
  105. }
  106. }
  107. class NCSectionFooter: UICollectionReusableView {
  108. @IBOutlet weak var labelSection: UILabel!
  109. override func awakeFromNib() {
  110. super.awakeFromNib()
  111. self.backgroundColor = UIColor.clear
  112. labelSection.textColor = NCBrandColor.sharedInstance.icon
  113. }
  114. func setTitleLabel(directories: Int, files: Int, size: Double) {
  115. var foldersText = ""
  116. var filesText = ""
  117. if directories > 1 {
  118. foldersText = "\(directories) " + NSLocalizedString("_folders_", comment: "")
  119. } else if directories == 1 {
  120. foldersText = "1 " + NSLocalizedString("_folder_", comment: "")
  121. }
  122. if files > 1 {
  123. filesText = "\(files) " + NSLocalizedString("_files_", comment: "") + " " + CCUtility.transformedSize(size)
  124. } else if files == 1 {
  125. filesText = "1 " + NSLocalizedString("_file_", comment: "") + " " + CCUtility.transformedSize(size)
  126. }
  127. if foldersText == "" {
  128. labelSection.text = filesText
  129. } else if filesText == "" {
  130. labelSection.text = foldersText
  131. } else {
  132. labelSection.text = foldersText + ", " + filesText
  133. }
  134. }
  135. }