123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- //
- // NCBrandColor.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 24/04/17.
- // Copyright (c) 2017 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import UIKit
- let userAgent: String = {
- let appVersion: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
- // Original Nextcloud useragent "Mozilla/5.0 (iOS) Nextcloud-iOS/\(appVersion)"
- return "Mozilla/5.0 (iOS) Nextcloud-iOS/\(appVersion)"
- }()
- @objc class NCBrandOptions: NSObject {
- @objc static let shared: NCBrandOptions = {
- let instance = NCBrandOptions()
- return instance
- }()
- var brand: String = "SX Space"
- var textCopyrightNextcloudiOS: String = "SX Space for iOS %@ © 2024"
- var textCopyrightNextcloudServer: String = "SX Space %@"
- var loginBaseUrl: String = "https://nc.sharix-app.org"
- @objc var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com"
- var linkLoginHost: String = "https://nextcloud.com/install"
- var linkloginPreferredProviders: String = "https://nextcloud.com/signup-ios"
- var webLoginAutenticationProtocol: String = "nc://" // example "abc://"
- var privacy: String = "https://wiki.sharix-app.org/doku.php/open/doc/policy_conf"
- var sourceCode: String = "https://github.com/nextcloud/ios"
- var mobileconfig: String = "/remote.php/dav/provisioning/apple-provisioning.mobileconfig"
- var appStoreUrl: String = "https://apps.apple.com/in/app/nextcloud/id1125420102"
- // Auto Upload default folder
- var folderDefaultAutoUpload: String = "Photos"
- // Capabilities Group
- var capabilitiesGroup: String = "group.com.sharix.keychain"
- var capabilitiesGroupApps: String = "group.com.sharix.apps"
- // BRAND ONLY
- @objc public var use_AppConfig: Bool = false // Don't touch me !!
- // Use server theming color
- @objc public var use_themingColor: Bool = true
- var disable_intro: Bool = false
- var disable_request_login_url: Bool = false
- var disable_multiaccount: Bool = false
- var disable_more_external_site: Bool = false
- var disable_openin_file: Bool = false // Don't touch me !!
- var disable_crash_service: Bool = false
- var disable_log: Bool = false
- var disable_mobileconfig: Bool = false
- var disable_show_more_nextcloud_apps_in_settings: Bool = false
- var doNotAskPasscodeAtStartup: Bool = false
- var disable_source_code_in_settings: Bool = false
- // (name: "Name 1", url: "https://cloud.nextcloud.com"),(name: "Name 2", url: "https://cloud.nextcloud.com")
- var enforce_servers: [(name: String, url: String)] = []
- // Internal option behaviour
- var cleanUpDay: Int = 0 // Set default "Delete, in the cache, all files older than" possible days value are: 0, 1, 7, 30, 90, 180, 365
- // Max download/upload concurrent
- let maxConcurrentOperationDownload: Int = 5
- let maxConcurrentOperationUpload: Int = 5
- // Number of failed attempts after reset app
- let resetAppPasscodeAttempts: Int = 10
- let passcodeSecondsFail: Int = 60
- // Info Paging
- enum NCInfoPagingTab: Int, CaseIterable {
- case activity, sharing
- }
- override init() {
- // wrapper AppConfig
- if let configurationManaged = UserDefaults.standard.dictionary(forKey: "com.apple.configuration.managed"), use_AppConfig {
- if let str = configurationManaged[NCGlobal.shared.configuration_brand] as? String {
- brand = str
- }
- if let str = configurationManaged[NCGlobal.shared.configuration_disable_intro] as? String {
- disable_intro = (str as NSString).boolValue
- }
- if let str = configurationManaged[NCGlobal.shared.configuration_disable_multiaccount] as? String {
- disable_multiaccount = (str as NSString).boolValue
- }
- if let str = configurationManaged[NCGlobal.shared.configuration_disable_crash_service] as? String {
- disable_crash_service = (str as NSString).boolValue
- }
- if let str = configurationManaged[NCGlobal.shared.configuration_disable_log] as? String {
- disable_log = (str as NSString).boolValue
- }
- if let str = configurationManaged[NCGlobal.shared.configuration_disable_more_external_site] as? String {
- disable_more_external_site = (str as NSString).boolValue
- }
- if let str = configurationManaged[NCGlobal.shared.configuration_disable_openin_file] as? String {
- disable_openin_file = (str as NSString).boolValue
- }
- }
- }
- @objc func getUserAgent() -> String {
- return userAgent
- }
- }
- class NCBrandColor: NSObject {
- static let shared: NCBrandColor = {
- let instance = NCBrandColor()
- return instance
- }()
- /// This is rewrited from customet theme, default is Nextcloud color
- ///
- let customer: UIColor = UIColor(red: 48.1 / 255.0, green: 45.8 / 255.0, blue: 49.9 / 255.0, alpha: 1.0) // BLU NC : #0082c9 | new: 662d91
- var customerText: UIColor = .white
- // INTERNAL DEFINE COLORS
- private var themingColor = ThreadSafeDictionary<String, UIColor>()
- private var themingColorElement = ThreadSafeDictionary<String, UIColor>()
- private var themingColorText = ThreadSafeDictionary<String, UIColor>()
- var userColors: [CGColor] = []
- let nextcloud: UIColor = UIColor(red: 48.1 / 255.0, green: 45.8 / 255.0, blue: 49.9 / 255.0, alpha: 1.0)
- //let nextcloud: UIColor = UIColor(red: 0.0 / 255.0, green: 130.0 / 255.0, blue: 201.0 / 255.0, alpha: 1.0)
- let yellowFavorite: UIColor = UIColor(red: 248.0 / 255.0, green: 205.0 / 255.0, blue: 70.0 / 255.0, alpha: 1.0)
- let iconImageColor: UIColor = .label
- let iconImageColor2: UIColor = .secondaryLabel
- let iconImageMultiColors: [UIColor] = [.secondaryLabel, .label]
- let textColor: UIColor = .label
- let textColor2: UIColor = .secondaryLabel
- var systemMint: UIColor {
- get {
- return UIColor(red: 0.0 / 255.0, green: 199.0 / 255.0, blue: 190.0 / 255.0, alpha: 1.0)
- }
- }
- var documentIconColor: UIColor {
- get {
- return UIColor(hex: "#49abe9")!
- }
- }
- var spreadsheetIconColor: UIColor {
- get {
- return UIColor(hex: "#9abd4e")!
- }
- }
- var presentationIconColor: UIColor {
- get {
- return UIColor(hex: "#f0965f")!
- }
- }
- override init() { }
- /**
- Generate colors from the official nextcloud color.
- You can provide how many colors you want (multiplied by 3).
- if `step` = 6,
- 3 colors \* 6 will result in 18 generated colors
- */
- func createUserColors() {
- func generateColors(steps: Int = 6) -> [CGColor] {
- func stepCalc(steps: Int, color1: CGColor, color2: CGColor) -> [CGFloat] {
- var step = [CGFloat](repeating: 0, count: 3)
- step[0] = (color2.components![0] - color1.components![0]) / CGFloat(steps)
- step[1] = (color2.components![1] - color1.components![1]) / CGFloat(steps)
- step[2] = (color2.components![2] - color1.components![2]) / CGFloat(steps)
- return step
- }
- func mixPalette(steps: Int, color1: CGColor, color2: CGColor) -> [CGColor] {
- var palette = [color1]
- let step = stepCalc(steps: steps, color1: color1, color2: color2)
- let c1Components = color1.components!
- for i in 1 ..< steps {
- let r = c1Components[0] + step[0] * CGFloat(i)
- let g = c1Components[1] + step[1] * CGFloat(i)
- let b = c1Components[2] + step[2] * CGFloat(i)
- palette.append(UIColor(red: r, green: g, blue: b, alpha: 1).cgColor)
- }
- return palette
- }
- let red = UIColor(red: 182 / 255, green: 70 / 255, blue: 157 / 255, alpha: 1).cgColor
- let yellow = UIColor(red: 221 / 255, green: 203 / 255, blue: 85 / 255, alpha: 1).cgColor
- let blue = UIColor(red: 0 / 255, green: 130 / 255, blue: 201 / 255, alpha: 1).cgColor
- let palette1 = mixPalette(steps: steps, color1: red, color2: yellow)
- let palette2 = mixPalette(steps: steps, color1: yellow, color2: blue)
- let palette3 = mixPalette(steps: steps, color1: blue, color2: red)
- return palette1 + palette2 + palette3
- }
- userColors = generateColors()
- }
- @discardableResult
- func settingThemingColor(account: String) -> Bool {
- let darker: CGFloat = 30 // %
- let lighter: CGFloat = 30 // %
- var colorThemingColor: UIColor?
- var colorThemingColorElement: UIColor?
- var colorThemingColorText: UIColor?
- if NCBrandOptions.shared.use_themingColor {
- let themingColor = NCCapabilities.shared.getCapabilities(account: account).capabilityThemingColor
- let themingColorElement = NCCapabilities.shared.getCapabilities(account: account).capabilityThemingColorElement
- let themingColorText = NCCapabilities.shared.getCapabilities(account: account).capabilityThemingColorText
- // THEMING COLOR
- if themingColor.first == "#" {
- if let color = UIColor(hex: themingColor) {
- colorThemingColor = color
- } else {
- colorThemingColor = customer
- }
- } else {
- colorThemingColor = customer
- }
- // THEMING COLOR ELEMENT (control isTooLight / isTooDark)
- if themingColorElement.first == "#" {
- if let color = UIColor(hex: themingColorElement) {
- if color.isTooLight() {
- if let color = color.darker(by: darker) {
- colorThemingColorElement = color
- }
- } else if color.isTooDark() {
- if let color = color.lighter(by: lighter) {
- colorThemingColorElement = color
- }
- } else {
- colorThemingColorElement = color
- }
- } else {
- colorThemingColorElement = customer
- }
- } else {
- colorThemingColorElement = customer
- }
- // THEMING COLOR TEXT
- if themingColorText.first == "#" {
- if let color = UIColor(hex: themingColorText) {
- colorThemingColorText = color
- } else {
- colorThemingColorText = .white
- }
- } else {
- colorThemingColorText = .white
- }
- } else {
- // THEMING COLOR
- colorThemingColor = customer
- // THEMING COLOR ELEMENT (control isTooLight / isTooDark)
- if self.customer.isTooLight() {
- if let color = customer.darker(by: darker) {
- colorThemingColorElement = color
- }
- } else if customer.isTooDark() {
- if let color = customer.lighter(by: lighter) {
- colorThemingColorElement = color
- }
- } else {
- colorThemingColorElement = customer
- }
- // THEMING COLOR TEXT
- colorThemingColorText = customerText
- }
- if self.themingColor[account] != colorThemingColor || self.themingColorElement[account] != colorThemingColorElement || self.themingColorText[account] != colorThemingColorText {
- self.themingColor[account] = colorThemingColor
- self.themingColorElement[account] = colorThemingColorElement
- self.themingColorText[account] = colorThemingColorText
- return true
- }
- return false
- }
- public func getTheming(account: String?) -> UIColor {
- if let account, let color = self.themingColor[account] {
- return color
- }
- return customer
- }
- public func getElement(account: String?) -> UIColor {
- if let account, let color = self.themingColorElement[account] {
- return color
- }
- return customer
- }
- public func getText(account: String?) -> UIColor {
- if let account, let color = self.themingColorText[account] {
- return color
- }
- return .white
- }
- }
|