NCColorPicker.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // NCColorPicker.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/07/22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. class NCColorPicker: UIViewController {
  11. @IBOutlet weak var closeButton: UIButton!
  12. @IBOutlet weak var titleLabel: UILabel!
  13. @IBOutlet weak var orangeButton: UIButton!
  14. @IBOutlet weak var redButton: UIButton!
  15. @IBOutlet weak var purpleButton: UIButton!
  16. @IBOutlet weak var blueButton: UIButton!
  17. @IBOutlet weak var brownButton: UIButton!
  18. @IBOutlet weak var greenButton: UIButton!
  19. @IBOutlet weak var grayButton: UIButton!
  20. @IBOutlet weak var cyanButton: UIButton!
  21. @IBOutlet weak var yellowButton: UIButton!
  22. @IBOutlet weak var systemIndigoButton: UIButton!
  23. @IBOutlet weak var systemMintButton: UIButton!
  24. @IBOutlet weak var systemPinkButton: UIButton!
  25. @IBOutlet weak var systemTealButton: UIButton!
  26. @IBOutlet weak var systemBlueButton: UIButton!
  27. @IBOutlet weak var defaultButton: UIButton!
  28. var metadata: tableMetadata?
  29. var tapAction: UITapGestureRecognizer?
  30. // MARK: - View Life Cycle
  31. override func viewDidLoad() {
  32. super.viewDidLoad()
  33. view.backgroundColor = NCBrandColor.shared.secondarySystemBackground
  34. closeButton.setImage(NCUtility.shared.loadImage(named: "xmark", color: NCBrandColor.shared.label), for: .normal)
  35. titleLabel.text = NSLocalizedString("_select_color_", comment: "")
  36. orangeButton.backgroundColor = .orange
  37. orangeButton.layer.cornerRadius = 5
  38. orangeButton.layer.masksToBounds = true
  39. redButton.backgroundColor = .red
  40. redButton.layer.cornerRadius = 5
  41. redButton.layer.masksToBounds = true
  42. purpleButton.backgroundColor = .purple
  43. purpleButton.layer.cornerRadius = 5
  44. purpleButton.layer.masksToBounds = true
  45. blueButton.backgroundColor = .blue
  46. blueButton.layer.cornerRadius = 5
  47. blueButton.layer.masksToBounds = true
  48. brownButton.backgroundColor = .brown
  49. brownButton.layer.cornerRadius = 5
  50. brownButton.layer.masksToBounds = true
  51. greenButton.backgroundColor = .green
  52. greenButton.layer.cornerRadius = 5
  53. greenButton.layer.masksToBounds = true
  54. grayButton.backgroundColor = .gray
  55. grayButton.layer.cornerRadius = 5
  56. grayButton.layer.masksToBounds = true
  57. cyanButton.backgroundColor = .cyan
  58. cyanButton.layer.cornerRadius = 5
  59. cyanButton.layer.masksToBounds = true
  60. yellowButton.backgroundColor = .yellow
  61. yellowButton.layer.cornerRadius = 5
  62. yellowButton.layer.masksToBounds = true
  63. systemBlueButton.backgroundColor = NCBrandColor.shared.systemBlue
  64. systemBlueButton.layer.cornerRadius = 5
  65. systemBlueButton.layer.masksToBounds = true
  66. systemMintButton.backgroundColor = NCBrandColor.shared.systemMint
  67. systemMintButton.layer.cornerRadius = 5
  68. systemMintButton.layer.masksToBounds = true
  69. systemPinkButton.backgroundColor = NCBrandColor.shared.systemPink
  70. systemPinkButton.layer.cornerRadius = 5
  71. systemPinkButton.layer.masksToBounds = true
  72. systemTealButton.backgroundColor = NCBrandColor.shared.systemTeal
  73. systemTealButton.layer.cornerRadius = 5
  74. systemTealButton.layer.masksToBounds = true
  75. systemIndigoButton.backgroundColor = NCBrandColor.shared.systemIndigo
  76. systemIndigoButton.layer.cornerRadius = 5
  77. systemIndigoButton.layer.masksToBounds = true
  78. defaultButton.backgroundColor = NCBrandColor.shared.brandElement
  79. defaultButton.layer.cornerRadius = 5
  80. defaultButton.layer.masksToBounds = true
  81. }
  82. // MARK: - Action
  83. @IBAction func closeAction(_ sender: UIButton) {
  84. dismiss(animated: true)
  85. }
  86. @IBAction func orangeButtonAction(_ sender: AnyObject) {
  87. updateColor(hexColor: UIColor.orange.hexString)
  88. }
  89. @IBAction func redButtonAction(_ sender: AnyObject) {
  90. updateColor(hexColor: UIColor.red.hexString)
  91. }
  92. @IBAction func purpleButtonAction(_ sender: AnyObject) {
  93. updateColor(hexColor: UIColor.purple.hexString)
  94. }
  95. @IBAction func blueButtonAction(_ sender: AnyObject) {
  96. updateColor(hexColor: UIColor.blue.hexString)
  97. }
  98. @IBAction func brownButtonAction(_ sender: AnyObject) {
  99. updateColor(hexColor: UIColor.brown.hexString)
  100. }
  101. @IBAction func greenButtonAction(_ sender: AnyObject) {
  102. updateColor(hexColor: UIColor.green.hexString)
  103. }
  104. @IBAction func grayButtonAction(_ sender: AnyObject) {
  105. updateColor(hexColor: UIColor.gray.hexString)
  106. }
  107. @IBAction func cyanButtonAction(_ sender: AnyObject) {
  108. updateColor(hexColor: UIColor.cyan.hexString)
  109. }
  110. @IBAction func yellowButtonAction(_ sender: AnyObject) {
  111. updateColor(hexColor: UIColor.yellow.hexString)
  112. }
  113. @IBAction func systemIndigoButtonAction(_ sender: AnyObject) {
  114. updateColor(hexColor: NCBrandColor.shared.systemIndigo.hexString)
  115. }
  116. @IBAction func systemMintButtonAction(_ sender: AnyObject) {
  117. updateColor(hexColor: NCBrandColor.shared.systemMint.hexString)
  118. }
  119. @IBAction func systemPinkButtonAction(_ sender: AnyObject) {
  120. updateColor(hexColor: NCBrandColor.shared.systemPink.hexString)
  121. }
  122. @IBAction func systemTealButtonAction(_ sender: AnyObject) {
  123. updateColor(hexColor: NCBrandColor.shared.systemTeal.hexString)
  124. }
  125. @IBAction func systemBlueButtonAction(_ sender: AnyObject) {
  126. updateColor(hexColor: NCBrandColor.shared.systemBlue.hexString)
  127. }
  128. @IBAction func defaultButtonAction(_ sender: AnyObject) {
  129. updateColor(hexColor: nil)
  130. }
  131. func updateColor(hexColor: String?) {
  132. if let metadata = metadata {
  133. let serverUrl = metadata.serverUrl + "/" + metadata.fileName
  134. if NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, colorFolder: hexColor, account: metadata.account) != nil {
  135. self.dismiss(animated: true)
  136. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl": metadata.serverUrl])
  137. }
  138. }
  139. self.dismiss(animated: true)
  140. }
  141. }