NCBrand.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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" // Deprecated
  43. @objc public var textCopyrightNextcloudiOS: String = "Nextcloud Liquid 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. @objc public var privacy: String = "https://nextcloud.com/privacy"
  51. @objc public var sourceCode: String = "https://github.com/nextcloud/ios"
  52. // Personalized
  53. @objc public var webCloseViewProtocolPersonalized: String = "" // example "abc://change/plan" Don't touch me !!
  54. @objc public var folderBrandAutoUpload: String = "" // example "_auto_upload_folder_" Don't touch me !!
  55. // Auto Upload default folder
  56. @objc public var folderDefaultAutoUpload: String = "Photos"
  57. // Capabilities Group
  58. @objc public var capabilitiesGroups: String = "group.it.twsweb.Crypto-Cloud"
  59. // User Agent
  60. @objc public var userAgent: String = "Nextcloud-iOS" // Don't touch me !!
  61. // Options
  62. @objc public var use_login_web_personalized: Bool = false // Don't touch me !!
  63. @objc public var use_default_auto_upload: Bool = false
  64. @objc public var use_themingColor: Bool = true
  65. //@objc public var use_themingBackground: Bool = true // Deprecated
  66. @objc public var use_themingLogo: Bool = false
  67. @objc public var use_storeLocalAutoUploadAll: Bool = false
  68. @objc public var use_configuration: Bool = false // Don't touch me !!
  69. @objc public var use_loginflowv2: Bool = false // Don't touch me !!
  70. @objc public var disable_intro: Bool = false
  71. @objc public var disable_request_login_url: Bool = false
  72. @objc public var disable_multiaccount: Bool = false
  73. @objc public var disable_manage_account: Bool = false
  74. @objc public var disable_more_external_site: Bool = false
  75. @objc public var disable_openin_file: Bool = false // Don't touch me !!
  76. @objc public var disable_crash_service: Bool = false
  77. @objc public var disable_request_account: Bool = false
  78. @objc public var disable_log: Bool = false
  79. @objc public var disable_background_color: Bool = true
  80. @objc public var disable_background_image: Bool = true
  81. override init() {
  82. if folderBrandAutoUpload != "" {
  83. folderDefaultAutoUpload = folderBrandAutoUpload
  84. }
  85. }
  86. }
  87. //MARK: - Color
  88. class NCBrandColor: NSObject {
  89. @objc static let shared: NCBrandColor = {
  90. let instance = NCBrandColor()
  91. instance.createImagesThemingColor()
  92. return instance
  93. }()
  94. struct cacheImages {
  95. static var file = UIImage()
  96. static var shared = UIImage()
  97. static var canShare = UIImage()
  98. static var shareByLink = UIImage()
  99. static var favorite = UIImage()
  100. static var comment = UIImage()
  101. static var livePhoto = UIImage()
  102. static var offlineFlag = UIImage()
  103. static var local = UIImage()
  104. static var folderEncrypted = UIImage()
  105. static var folderSharedWithMe = UIImage()
  106. static var folderPublic = UIImage()
  107. static var folderGroup = UIImage()
  108. static var folderExternal = UIImage()
  109. static var folderAutomaticUpload = UIImage()
  110. static var folder = UIImage()
  111. static var checkedYes = UIImage()
  112. static var checkedNo = UIImage()
  113. static var buttonMore = UIImage()
  114. static var buttonStop = UIImage()
  115. static var buttonRestore = UIImage()
  116. }
  117. // Color
  118. @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
  119. @objc public var customerText: UIColor = .white
  120. @objc public var brand: UIColor // don't touch me
  121. @objc public var brandElement: UIColor // don't touch me
  122. @objc public var brandText: UIColor // don't touch me
  123. @objc public let nextcloud: UIColor = UIColor(red: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 1.0)
  124. @objc public let gray: UIColor = UIColor(red: 104.0/255.0, green: 104.0/255.0, blue: 104.0/255.0, alpha: 1.0)
  125. @objc public let lightGray: UIColor = UIColor(red: 229.0/255.0, green: 229.0/229.0, blue: 104.0/255.0, alpha: 1.0)
  126. @objc public let yellowFavorite: UIColor = UIColor(red: 248.0/255.0, green: 205.0/255.0, blue: 70.0/255.0, alpha: 1.0)
  127. @objc public var systemBackground: UIColor {
  128. get {
  129. if #available(iOS 13, *) {
  130. return .systemBackground
  131. } else {
  132. return .white
  133. }
  134. }
  135. }
  136. @objc public var secondarySystemBackground: UIColor {
  137. get {
  138. if #available(iOS 13, *) {
  139. return .secondarySystemBackground
  140. } else {
  141. return UIColor(red: 0.95, green: 0.95, blue: 0.97, alpha: 1.0)
  142. }
  143. }
  144. }
  145. @objc public var tertiarySystemBackground: UIColor {
  146. get {
  147. if #available(iOS 13, *) {
  148. return .tertiarySystemBackground
  149. } else {
  150. return UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
  151. }
  152. }
  153. }
  154. @objc public var systemGroupedBackground: UIColor {
  155. get {
  156. if #available(iOS 13, *) {
  157. return .systemGroupedBackground
  158. } else {
  159. return UIColor(red: 0.95, green: 0.95, blue: 0.97, alpha: 1.0)
  160. }
  161. }
  162. }
  163. @objc public var secondarySystemGroupedBackground: UIColor {
  164. get {
  165. if #available(iOS 13, *) {
  166. return .secondarySystemGroupedBackground
  167. } else {
  168. return .white
  169. }
  170. }
  171. }
  172. @objc public var label: UIColor {
  173. get {
  174. if #available(iOS 13, *) {
  175. return .label
  176. } else {
  177. return .black
  178. }
  179. }
  180. }
  181. @objc public var separator: UIColor {
  182. get {
  183. if #available(iOS 13, *) {
  184. return .separator
  185. } else {
  186. return UIColor(red: 0.89, green: 0.89, blue: 0.89, alpha: 1.0)
  187. }
  188. }
  189. }
  190. @objc public var opaqueSeparator: UIColor {
  191. get {
  192. if #available(iOS 13, *) {
  193. return .opaqueSeparator
  194. } else {
  195. return UIColor(red: 0.78, green: 0.78, blue: 0.78, alpha: 1.0)
  196. }
  197. }
  198. }
  199. @objc public var systemGray: UIColor {
  200. get {
  201. if #available(iOS 13, *) {
  202. return .systemGray
  203. } else {
  204. return UIColor(red: 0.56, green: 0.56, blue: 0.58, alpha: 1.0)
  205. }
  206. }
  207. }
  208. @objc public var systemGray2: UIColor {
  209. get {
  210. if #available(iOS 13, *) {
  211. return .systemGray2
  212. } else {
  213. return UIColor(red: 0.68, green: 0.68, blue: 0.7, alpha: 1.0)
  214. }
  215. }
  216. }
  217. @objc public var systemGray3: UIColor {
  218. get {
  219. if #available(iOS 13, *) {
  220. return .systemGray3
  221. } else {
  222. return UIColor(red: 0.78, green: 0.78, blue: 0.8, alpha: 1.0)
  223. }
  224. }
  225. }
  226. @objc public var systemGray4: UIColor {
  227. get {
  228. if #available(iOS 13, *) {
  229. return .systemGray4
  230. } else {
  231. return UIColor(red: 0.82, green: 0.82, blue: 0.84, alpha: 1.0)
  232. }
  233. }
  234. }
  235. @objc public var systemGray5: UIColor {
  236. get {
  237. if #available(iOS 13, *) {
  238. return .systemGray5
  239. } else {
  240. return UIColor(red: 0.9, green: 0.9, blue: 0.92, alpha: 1.0)
  241. }
  242. }
  243. }
  244. @objc public var systemGray6: UIColor {
  245. get {
  246. if #available(iOS 13, *) {
  247. return .systemGray6
  248. } else {
  249. return UIColor(red: 0.95, green: 0.95, blue: 0.97, alpha: 1.0)
  250. }
  251. }
  252. }
  253. @objc public var systemFill: UIColor {
  254. get {
  255. if #available(iOS 13, *) {
  256. return .systemFill
  257. } else {
  258. return UIColor(red: 120/255, green: 120/255, blue: 120/255, alpha: 1.0)
  259. }
  260. }
  261. }
  262. override init() {
  263. self.brand = self.customer
  264. self.brandElement = self.customer
  265. self.brandText = self.customerText
  266. }
  267. public func createImagesThemingColor() {
  268. let gray: UIColor = UIColor(red: 162.0/255.0, green: 162.0/255.0, blue: 162.0/255.0, alpha: 0.5)
  269. cacheImages.file = UIImage.init(named: "file")!
  270. cacheImages.shared = UIImage(named: "share")!.image(color: gray, size: 50)
  271. cacheImages.canShare = UIImage(named: "share")!.image(color: gray, size: 50)
  272. cacheImages.shareByLink = UIImage(named: "sharebylink")!.image(color: gray, size: 50)
  273. cacheImages.favorite = NCUtility.shared.loadImage(named: "star.fill", color: yellowFavorite)
  274. cacheImages.comment = UIImage(named: "comment")!.image(color: gray, size: 50)
  275. cacheImages.livePhoto = NCUtility.shared.loadImage(named: "livephoto", color: label)
  276. cacheImages.offlineFlag = UIImage.init(named: "offlineFlag")!
  277. cacheImages.local = UIImage.init(named: "local")!
  278. let folderWidth: CGFloat = UIScreen.main.bounds.width / 3
  279. cacheImages.folderEncrypted = UIImage(named: "folderEncrypted")!.image(color: brandElement, size: folderWidth)
  280. cacheImages.folderSharedWithMe = UIImage(named: "folder_shared_with_me")!.image(color: brandElement, size: folderWidth)
  281. cacheImages.folderPublic = UIImage(named: "folder_public")!.image(color: brandElement, size: folderWidth)
  282. cacheImages.folderGroup = UIImage(named: "folder_group")!.image(color: brandElement, size: folderWidth)
  283. cacheImages.folderExternal = UIImage(named: "folder_external")!.image(color: brandElement, size: folderWidth)
  284. cacheImages.folderAutomaticUpload = UIImage(named: "folderAutomaticUpload")!.image(color: brandElement, size: folderWidth)
  285. cacheImages.folder = UIImage(named: "folder")!.image(color: brandElement, size: folderWidth)
  286. cacheImages.checkedYes = NCUtility.shared.loadImage(named: "checkmark.circle.fill", color: .systemBlue)
  287. cacheImages.checkedNo = NCUtility.shared.loadImage(named: "circle", color: gray)
  288. cacheImages.buttonMore = UIImage(named: "more")!.image(color: gray, size: 50)
  289. cacheImages.buttonStop = UIImage(named: "stop")!.image(color: gray, size: 50)
  290. cacheImages.buttonRestore = UIImage(named: "restore")!.image(color: gray, size: 50)
  291. }
  292. #if !EXTENSION
  293. public func settingThemingColor(account: String) {
  294. let darker: CGFloat = 30 // %
  295. let lighter: CGFloat = 30 // %
  296. if NCBrandOptions.shared.use_themingColor {
  297. let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
  298. let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
  299. let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
  300. settingBrandColor(themingColor, themingColorElement: themingColorElement, themingColorText: themingColorText)
  301. if NCBrandColor.shared.brandElement.isTooLight() {
  302. if let color = NCBrandColor.shared.brandElement.darker(by: darker) {
  303. NCBrandColor.shared.brandElement = color
  304. }
  305. } else if NCBrandColor.shared.brandElement.isTooDark() {
  306. if let color = NCBrandColor.shared.brandElement.lighter(by: lighter) {
  307. NCBrandColor.shared.brandElement = color
  308. }
  309. }
  310. } else {
  311. if NCBrandColor.shared.customer.isTooLight() {
  312. if let color = NCBrandColor.shared.customer.darker(by: darker) {
  313. NCBrandColor.shared.brandElement = color
  314. }
  315. } else if NCBrandColor.shared.customer.isTooDark() {
  316. if let color = NCBrandColor.shared.customer.lighter(by: lighter) {
  317. NCBrandColor.shared.brandElement = color
  318. }
  319. } else {
  320. NCBrandColor.shared.brandElement = NCBrandColor.shared.customer
  321. }
  322. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  323. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  324. }
  325. DispatchQueue.main.async {
  326. self.createImagesThemingColor()
  327. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
  328. }
  329. }
  330. #endif
  331. @objc func settingBrandColor(_ themingColor: String?, themingColorElement: String?, themingColorText: String?) {
  332. // COLOR
  333. if themingColor?.first == "#" {
  334. if let color = UIColor(hex: themingColor!) {
  335. NCBrandColor.shared.brand = color
  336. } else {
  337. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  338. }
  339. } else {
  340. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  341. }
  342. // COLOR TEXT
  343. if themingColorText?.first == "#" {
  344. if let color = UIColor(hex: themingColorText!) {
  345. NCBrandColor.shared.brandText = color
  346. } else {
  347. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  348. }
  349. } else {
  350. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  351. }
  352. // COLOR ELEMENT
  353. if themingColorElement?.first == "#" {
  354. if let color = UIColor(hex: themingColorElement!) {
  355. NCBrandColor.shared.brandElement = color
  356. } else {
  357. NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
  358. }
  359. } else {
  360. NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
  361. }
  362. }
  363. }