NCBrand.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 %@ © 2020"
  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";
  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. override init() {
  76. if folderBrandAutoUpload != "" {
  77. folderDefaultAutoUpload = folderBrandAutoUpload
  78. }
  79. }
  80. }
  81. //MARK: - Color
  82. class NCBrandColor: NSObject {
  83. @objc static let shared: NCBrandColor = {
  84. let instance = NCBrandColor()
  85. instance.setDarkMode()
  86. return instance
  87. }()
  88. // Color
  89. @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
  90. @objc public var customerText: UIColor = .white
  91. @objc public var brand: UIColor // don't touch me
  92. @objc public var brandElement: UIColor // don't touch me
  93. @objc public var brandText: UIColor // don't touch me
  94. @objc public var connectionNo: UIColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
  95. @objc public var encrypted: UIColor = .red
  96. @objc public var backgroundView: UIColor = .white
  97. @objc public var backgroundCell: UIColor = .white
  98. @objc public var backgroundForm: UIColor = UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
  99. @objc public var textView: UIColor = .black
  100. @objc public var separator: UIColor = UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0)
  101. @objc public var tabBar: UIColor = .white
  102. @objc public let nextcloud: UIColor = UIColor(red: 0.0/255.0, green: 130.0/255.0, blue: 201.0/255.0, alpha: 1.0)
  103. @objc public let nextcloudSoft: UIColor = UIColor(red: 90.0/255.0, green: 160.0/255.0, blue: 210.0/255.0, alpha: 1.0)
  104. @objc public let icon: UIColor = UIColor(red: 104.0/255.0, green: 104.0/255.0, blue: 104.0/255.0, alpha: 1.0)
  105. @objc public let optionItem: UIColor = UIColor(red: 178.0/255.0, green: 178.0/255.0, blue: 178.0/255.0, alpha: 1.0)
  106. @objc public let graySoft: UIColor = UIColor(red: 162.0/255.0, green: 162.0/255.0, blue: 162.0/255.0, alpha: 0.5)
  107. @objc public let yellowFavorite: UIColor = UIColor(red: 248.0/255.0, green: 205.0/255.0, blue: 70.0/255.0, alpha: 1.0)
  108. @objc public let textInfo: UIColor = UIColor(red: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 1.0)
  109. @objc public var select: UIColor = .white
  110. override init() {
  111. self.brand = self.customer
  112. self.brandElement = self.customer
  113. self.brandText = self.customerText
  114. }
  115. @objc public func setDarkMode() {
  116. let darkMode = CCUtility.getDarkMode()
  117. if darkMode {
  118. tabBar = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
  119. backgroundView = .black
  120. backgroundCell = UIColor(red: 25.0/255.0, green: 25.0/255.0, blue: 25.0/255.0, alpha: 1.0)
  121. backgroundForm = .black
  122. textView = .white
  123. separator = UIColor(red: 60.0/255.0, green: 60.0/255.0, blue: 60.0/255.0, alpha: 1.0)
  124. select = UIColor.white.withAlphaComponent(0.2)
  125. } else {
  126. tabBar = .white
  127. backgroundView = .white
  128. backgroundCell = .white
  129. backgroundForm = UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)
  130. textView = .black
  131. separator = UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0)
  132. select = self.brandElement.withAlphaComponent(0.1)
  133. }
  134. }
  135. #if !EXTENSION
  136. @objc public func settingThemingColor(account: String) {
  137. let darker: CGFloat = 30 // %
  138. let lighter: CGFloat = 30 // %
  139. if NCBrandOptions.shared.use_themingColor {
  140. let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
  141. let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
  142. let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
  143. CCGraphics.settingThemingColor(themingColor, themingColorElement: themingColorElement, themingColorText: themingColorText)
  144. if NCBrandColor.shared.brandElement.isTooLight() {
  145. if let color = NCBrandColor.shared.brandElement.darker(by: darker) {
  146. NCBrandColor.shared.brandElement = color
  147. }
  148. } else if NCBrandColor.shared.brandElement.isTooDark() {
  149. if let color = NCBrandColor.shared.brandElement.lighter(by: lighter) {
  150. NCBrandColor.shared.brandElement = color
  151. }
  152. }
  153. } else {
  154. if NCBrandColor.shared.customer.isTooLight() {
  155. if let color = NCBrandColor.shared.customer.darker(by: darker) {
  156. NCBrandColor.shared.brandElement = color
  157. }
  158. } else if NCBrandColor.shared.customer.isTooDark() {
  159. if let color = NCBrandColor.shared.customer.lighter(by: lighter) {
  160. NCBrandColor.shared.brandElement = color
  161. }
  162. } else {
  163. NCBrandColor.shared.brandElement = NCBrandColor.shared.customer
  164. }
  165. NCBrandColor.shared.brand = NCBrandColor.shared.customer
  166. NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
  167. }
  168. setDarkMode()
  169. DispatchQueue.main.async {
  170. NCCollectionCommon.shared.createImagesThemingColor()
  171. NotificationCenter.default.postOnMainThread(name: k_notificationCenter_changeTheming)
  172. }
  173. }
  174. #endif
  175. }
  176. //MARK: - Global
  177. @objc class NCBrandGlobal: NSObject {
  178. @objc static let shared: NCBrandGlobal = {
  179. let instance = NCBrandGlobal()
  180. return instance
  181. }()
  182. // Directory on Group
  183. @objc let appDatabaseNextcloud = "Library/Application Support/Nextcloud"
  184. @objc let appApplicationSupport = "Library/Application Support"
  185. @objc let appUserData = "Library/Application Support/UserData"
  186. @objc let appCertificates = "Library/Application Support/Certificates"
  187. @objc let appScan = "Library/Application Support/Scan"
  188. @objc let directoryProviderStorage = "File Provider Storage"
  189. // Service Key Share
  190. @objc let serviceShareKeyChain = "Crypto Cloud"
  191. @objc let metadataKeyedUnarchiver = "it.twsweb.nextcloud.metadata"
  192. // Nextcloud version
  193. @objc let nextcloudVersion12: Int = 12
  194. let nextcloudVersion15: Int = 15
  195. let nextcloudVersion17: Int = 17
  196. let nextcloudVersion18: Int = 18
  197. let nextcloudVersion20: Int = 20
  198. // Database Realm
  199. let databaseDefault = "nextcloud.realm"
  200. let databaseSchemaVersion: UInt64 = 160
  201. // Intro selector
  202. @objc let introLogin: Int = 0
  203. @objc let introSignup: Int = 1
  204. // Avatar & Preview
  205. let avatarSize: Int = 128
  206. @objc let sizePreview: CGFloat = 1024
  207. @objc let sizeIcon: CGFloat = 512
  208. // E2EE
  209. let e2eeMaxFileSize: UInt64 = 524288000 // 500 MB
  210. let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony"
  211. @objc let e2eeVersion = "1.1"
  212. // Max Size Upload
  213. let uploadMaxFileSize: UInt64 = 524288000 // 500 MB
  214. // Max Cache Proxy Video
  215. let maxHTTPCache: Int64 = 10737418240 // 10 GB
  216. // NCSharePaging
  217. let indexPageActivity: Int = 0
  218. let indexPageComments: Int = 1
  219. let indexPageSharing: Int = 2
  220. // Nextcloud unsupported
  221. let nextcloud_unsupported_version: Int = 13
  222. // Layout
  223. let layoutList = "typeLayoutList"
  224. let layoutGrid = "typeLayoutGrid"
  225. let layoutViewMove = "LayoutMove"
  226. let layoutViewTrash = "LayoutTrash"
  227. let layoutViewOffline = "LayoutOffline"
  228. let layoutViewFavorite = "LayoutFavorite"
  229. let layoutViewFiles = "LayoutFiles"
  230. let layoutViewViewInFolder = "ViewInFolder"
  231. let layoutViewTransfers = "LayoutTransfers"
  232. let layoutViewRecent = "LayoutRecent"
  233. let layoutViewShares = "LayoutShares"
  234. // Button Type in Cell list/grid
  235. let buttonMoreMore = "more"
  236. let buttonMoreStop = "stop"
  237. // Text - OnlyOffice - Collabora
  238. let editorText = "text"
  239. let editorOnlyoffice = "onlyoffice"
  240. let editorCollabora = "collabora"
  241. let onlyofficeDocx = "onlyoffice_docx"
  242. let onlyofficeXlsx = "onlyoffice_xlsx"
  243. let onlyofficePptx = "onlyoffice_pptx"
  244. // Template
  245. let templateDocument = "document"
  246. let templateSpreadsheet = "spreadsheet"
  247. let templatePresentation = "presentation"
  248. // Rich Workspace
  249. let fileNameRichWorkspace = "Readme.md"
  250. @objc let dismissAfterSecond: TimeInterval = 4
  251. @objc let dismissAfterSecondLong: TimeInterval = 10
  252. // Error
  253. @objc let ErrorBadRequest: Int = 400
  254. @objc let ErrorResourceNotFound: Int = 404
  255. @objc let ErrorConflict: Int = 409
  256. @objc let ErrorBadServerResponse: Int = -1011
  257. @objc let ErrorInternalError: Int = -99999
  258. @objc let ErrorFileNotSaved: Int = -99998
  259. @objc let ErrorDecodeMetadata: Int = -99997
  260. @objc let ErrorE2EENotEnabled: Int = -99996
  261. @objc let ErrorOffline: Int = -99994
  262. @objc let ErrorCharactersForbidden: Int = -99993
  263. @objc let ErrorCreationFile: Int = -99992
  264. // Metadata : Status
  265. //
  266. // 1) wait download/upload
  267. // 2) in download/upload
  268. // 3) downloading/uploading
  269. // 4) done or error
  270. //
  271. @objc let metadataStatusNormal: Int = 0
  272. @objc let metadataStatustypeDownload: Int = 1
  273. @objc let metadataStatusWaitDownload: Int = 2
  274. @objc let metadataStatusInDownload: Int = 3
  275. @objc let metadataStatusDownloading: Int = 4
  276. @objc let metadataStatusDownloadError: Int = 5
  277. @objc let metadataStatusTypeUpload: Int = 6
  278. @objc let metadataStatusWaitUpload: Int = 7
  279. @objc let metadataStatusInUpload: Int = 8
  280. @objc let metadataStatusUploading: Int = 9
  281. @objc let metadataStatusUploadError: Int = 10
  282. @objc let metadataStatusUploadForcedStart: Int = 11
  283. }