NCBrand.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //
  2. // NCBrandColor.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/04/17.
  6. // Copyright (c) 2017 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. //MARK: - Configuration
  25. @objc class NCBrandConfiguration: NSObject {
  26. @objc static let shared: NCBrandConfiguration = {
  27. let instance = NCBrandConfiguration()
  28. return instance
  29. }()
  30. @objc public let configuration_bundleId: String = "it.twsweb.Nextcloud"
  31. @objc public let configuration_serverUrl: String = "serverUrl"
  32. @objc public let configuration_username: String = "username"
  33. @objc public let configuration_password: String = "password"
  34. }
  35. //MARK: - Options
  36. @objc class NCBrandOptions: NSObject {
  37. @objc static let shared: NCBrandOptions = {
  38. let instance = NCBrandOptions()
  39. return instance
  40. }()
  41. @objc public var brand: String = "Nextcloud"
  42. @objc public var mailMe: String = "ios@nextcloud.com"
  43. @objc public var textCopyrightNextcloudiOS: String = "Nextcloud Coherence for iOS %@ © 2021"
  44. @objc public var textCopyrightNextcloudServer: String = "Nextcloud Server %@"
  45. @objc public var loginBaseUrl: String = "https://cloud.nextcloud.com"
  46. @objc public var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com"
  47. @objc public var linkLoginHost: String = "https://nextcloud.com/install"
  48. @objc public var linkloginPreferredProviders: String = "https://nextcloud.com/signup-ios";
  49. @objc public var webLoginAutenticationProtocol: String = "nc://" // example "abc://"
  50. // Personalized
  51. @objc public var webCloseViewProtocolPersonalized: String = "" // example "abc://change/plan" Don't touch me !!
  52. @objc public var folderBrandAutoUpload: String = "" // example "_auto_upload_folder_" Don't touch me !!
  53. // Auto Upload default folder
  54. @objc public var folderDefaultAutoUpload: String = "Photos"
  55. // Capabilities Group
  56. @objc public var capabilitiesGroups: String = "group.it.twsweb.Crypto-Cloud"
  57. // User Agent
  58. @objc public var userAgent: String = "Nextcloud-iOS" // Don't touch me !!
  59. // Options
  60. @objc public var use_login_web_personalized: Bool = false // Don't touch me !!
  61. @objc public var use_default_auto_upload: Bool = false
  62. @objc public var use_themingColor: Bool = true
  63. //@objc public var use_themingBackground: Bool = true // Deprecated
  64. @objc public var use_themingLogo: Bool = false
  65. @objc public var use_storeLocalAutoUploadAll: Bool = false
  66. @objc public var use_configuration: Bool = false // Don't touch me !!
  67. @objc public var use_loginflowv2: Bool = false // Don't touch me !!
  68. @objc public var disable_intro: Bool = false
  69. @objc public var disable_request_login_url: Bool = false
  70. @objc public var disable_multiaccount: Bool = false
  71. @objc public var disable_manage_account: Bool = false
  72. @objc public var disable_more_external_site: Bool = false
  73. @objc public var disable_openin_file: Bool = false // Don't touch me !!
  74. @objc public var disable_crash_service: Bool = false
  75. @objc public var disable_request_account: Bool = false
  76. override init() {
  77. if folderBrandAutoUpload != "" {
  78. folderDefaultAutoUpload = folderBrandAutoUpload
  79. }
  80. }
  81. }
  82. //MARK: - Color
  83. class NCBrandColor: NSObject {
  84. @objc static let shared: NCBrandColor = {
  85. let instance = NCBrandColor()
  86. instance.setDarkMode()
  87. instance.createImagesThemingColor()
  88. return instance
  89. }()
  90. struct cacheImages {
  91. static var file = UIImage()
  92. static var shared = UIImage()
  93. static var canShare = UIImage()
  94. static var shareByLink = UIImage()
  95. static var favorite = UIImage()
  96. static var comment = UIImage()
  97. static var livePhoto = UIImage()
  98. static var offlineFlag = UIImage()
  99. static var local = UIImage()
  100. static var folderEncrypted = UIImage()
  101. static var folderSharedWithMe = UIImage()
  102. static var folderPublic = UIImage()
  103. static var folderGroup = UIImage()
  104. static var folderExternal = UIImage()
  105. static var folderAutomaticUpload = UIImage()
  106. static var folder = UIImage()
  107. static var checkedYes = UIImage()
  108. static var checkedNo = UIImage()
  109. static var buttonMore = UIImage()
  110. static var buttonStop = UIImage()
  111. }
  112. // Color
  113. @objc public let customer: UIColor = UIColor(red: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 1.0) // BLU NC : #0082c9
  114. @objc public var customerText: UIColor = .white
  115. @objc public var brand: UIColor // don't touch me
  116. @objc public var brandElement: UIColor // don't touch me
  117. @objc public var brandText: UIColor // don't touch me
  118. @objc public var connectionNo: UIColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
  119. @objc public var encrypted: UIColor = .red
  120. @objc public var backgroundView: UIColor = .white
  121. @objc public var backgroundForm: UIColor = UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
  122. @objc public var textView: UIColor = .black
  123. @objc public var separator: UIColor = UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0)
  124. @objc public var tabBar: UIColor = .white
  125. @objc public let nextcloud: UIColor = UIColor(red: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 1.0)
  126. @objc public let nextcloudSoft: UIColor = UIColor(red: 90.0/255.0, green: 160.0/255.0, blue: 210.0/255.0, alpha: 1.0)
  127. @objc public let icon: UIColor = UIColor(red: 104.0/255.0, green: 104.0/255.0, blue: 104.0/255.0, alpha: 1.0)
  128. @objc public let optionItem: UIColor = UIColor(red: 178.0/255.0, green: 178.0/255.0, blue: 178.0/255.0, alpha: 1.0)
  129. @objc public let graySoft: UIColor = UIColor(red: 162.0/255.0, green: 162.0/255.0, blue: 162.0/255.0, alpha: 0.5)
  130. @objc public let yellowFavorite: UIColor = UIColor(red: 248.0/255.0, green: 205.0/255.0, blue: 70.0/255.0, alpha: 1.0)
  131. @objc public let textInfo: UIColor = UIColor(red: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 1.0)
  132. @objc public var select: UIColor = .white
  133. @objc public var avatarBorder: UIColor = .white
  134. override init() {
  135. self.brand = self.customer
  136. self.brandElement = self.customer
  137. self.brandText = self.customerText
  138. }
  139. private func createImagesThemingColor() {
  140. cacheImages.file = UIImage.init(named: "file")!
  141. cacheImages.shared = UIImage(named: "share")!.image(color: graySoft, size: 50)
  142. cacheImages.canShare = UIImage(named: "share")!.image(color: graySoft, size: 50)
  143. cacheImages.shareByLink = UIImage(named: "sharebylink")!.image(color: graySoft, size: 50)
  144. cacheImages.favorite = NCUtility.shared.loadImage(named: "star.fill", color: yellowFavorite)
  145. cacheImages.comment = UIImage(named: "comment")!.image(color: graySoft, size: 50)
  146. cacheImages.livePhoto = NCUtility.shared.loadImage(named: "livephoto", color: textView)
  147. cacheImages.offlineFlag = UIImage.init(named: "offlineFlag")!
  148. cacheImages.local = UIImage.init(named: "local")!
  149. let folderWidth: CGFloat = UIScreen.main.bounds.width / 3
  150. cacheImages.folderEncrypted = UIImage(named: "folderEncrypted")!.image(color: brandElement, size: folderWidth)
  151. cacheImages.folderSharedWithMe = UIImage(named: "folder_shared_with_me")!.image(color: brandElement, size: folderWidth)
  152. cacheImages.folderPublic = UIImage(named: "folder_public")!.image(color: brandElement, size: folderWidth)
  153. cacheImages.folderGroup = UIImage(named: "folder_group")!.image(color: brandElement, size: folderWidth)
  154. cacheImages.folderExternal = UIImage(named: "folder_external")!.image(color: brandElement, size: folderWidth)
  155. cacheImages.folderAutomaticUpload = UIImage(named: "folderAutomaticUpload")!.image(color: brandElement, size: folderWidth)
  156. cacheImages.folder = UIImage(named: "folder")!.image(color: brandElement, size: folderWidth)
  157. cacheImages.checkedYes = NCUtility.shared.loadImage(named: "checkmark.circle.fill", color: .darkGray)
  158. cacheImages.checkedNo = NCUtility.shared.loadImage(named: "circle", color: graySoft)
  159. cacheImages.buttonMore = UIImage(named: "more")!.image(color: graySoft, size: 50)
  160. cacheImages.buttonStop = UIImage(named: "stop")!.image(color: graySoft, size: 50)
  161. }
  162. @objc public func setDarkMode() {
  163. let darkMode = CCUtility.getDarkMode()
  164. if darkMode {
  165. tabBar = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
  166. backgroundView = .black
  167. backgroundForm = UIColor(red: 32.0/255.0, green: 32.0/255.0, blue: 32.0/255.0, alpha: 1.0)
  168. textView = .white
  169. separator = UIColor(red: 60.0/255.0, green: 60.0/255.0, blue: 60.0/255.0, alpha: 1.0)
  170. select = UIColor.white.withAlphaComponent(0.2)
  171. avatarBorder = .black
  172. } else {
  173. tabBar = .white
  174. backgroundView = .white
  175. backgroundForm = UIColor(red: 242.0/255.0, green: 242.0/255.0, blue: 242.0/255.0, alpha: 1.0)
  176. textView = .black
  177. separator = UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0)
  178. select = self.brandElement.withAlphaComponent(0.1)
  179. avatarBorder = .white
  180. }
  181. }
  182. #if !EXTENSION
  183. public func settingThemingColor(account: String) {
  184. let darker: CGFloat = 30 // %
  185. let lighter: CGFloat = 30 // %
  186. if NCBrandOptions.shared.use_themingColor {
  187. let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
  188. let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
  189. let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
  190. settingBrandColor(themingColor, themingColorElement: themingColorElement, themingColorText: themingColorText)
  191. if NCBrandColor.shared.brandElement.isTooLight() {
  192. if let color = NCBrandColor.shared.brandElement.darker(by: darker) {
  193. NCBrandColor.shared.brandElement = color
  194. }
  195. } else if NCBrandColor.shared.brandElement.isTooDark() {
  196. if let color = NCBrandColor.shared.brandElement.lighter(by: lighter) {
  197. NCBrandColor.shared.brandElement = color
  198. }
  199. }
  200. } else {
  201. if NCBrandColor.shared.customer.isTooLight() {
  202. if let color = NCBrandColor.shared.customer.darker(by: darker) {
  203. NCBrandColor.shared.brandElement = color
  204. }
  205. } else if NCBrandColor.shared.customer.isTooDark() {
  206. if let color = NCBrandColor.shared.customer.lighter(by: lighter) {
  207. NCBrandColor.shared.brandElement = color
  208. }
  209. } else {
  210. NCBrandColor.shared.brandElement = NCBrandColor.shared.customer
  211. }
  212. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  213. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  214. }
  215. setDarkMode()
  216. DispatchQueue.main.async {
  217. self.createImagesThemingColor()
  218. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
  219. }
  220. }
  221. #endif
  222. @objc func settingBrandColor(_ themingColor: String?, themingColorElement: String?, themingColorText: String?) {
  223. // COLOR
  224. if themingColor?.first == "#" {
  225. if let color = UIColor(hex: themingColor!) {
  226. NCBrandColor.shared.brand = color
  227. } else {
  228. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  229. }
  230. } else {
  231. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  232. }
  233. // COLOR TEXT
  234. if themingColorText?.first == "#" {
  235. if let color = UIColor(hex: themingColorText!) {
  236. NCBrandColor.shared.brandText = color
  237. } else {
  238. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  239. }
  240. } else {
  241. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  242. }
  243. // COLOR ELEMENT
  244. if themingColorElement?.first == "#" {
  245. if let color = UIColor(hex: themingColorElement!) {
  246. NCBrandColor.shared.brandElement = color
  247. } else {
  248. NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
  249. }
  250. } else {
  251. NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
  252. }
  253. }
  254. }