Forráskód Böngészése

Theming color

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 éve
szülő
commit
82128331c9
2 módosított fájl, 45 hozzáadás és 46 törlés
  1. 43 40
      iOSClient/Brand/NCBrand.swift
  2. 2 6
      iOSClient/Networking/NCService.swift

+ 43 - 40
iOSClient/Brand/NCBrand.swift

@@ -164,6 +164,9 @@ class NCBrandColor: NSObject {
     @objc public let yellowFavorite: UIColor = UIColor(red: 248.0/255.0, green: 205.0/255.0, blue: 70.0/255.0, alpha: 1.0)
 
     public var userColors: [CGColor] = []
+    public var themingColor: String = ""
+    public var themingColorElement: String = ""
+    public var themingColorText: String = ""
 
     @objc public var annotationColor: UIColor {
         get {
@@ -402,11 +405,47 @@ class NCBrandColor: NSObject {
 
         if NCBrandOptions.shared.use_themingColor {
 
-            let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
-            let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
-            let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
+            if let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor),
+               let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement),
+               let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText) {
+
+                self.themingColor = themingColor
+                self.themingColorElement = themingColorElement
+                self.themingColorText = themingColorText
+                
+                // COLOR
+                if themingColor?.first == "#" {
+                    if let color = UIColor(hex: themingColor) {
+                        NCBrandColor.shared.brand = color
+                    } else {
+                        NCBrandColor.shared.brand = NCBrandColor.shared.customer
+                    }
+                } else {
+                    NCBrandColor.shared.brand = NCBrandColor.shared.customer
+                }
+
+                // COLOR TEXT
+                if themingColorText?.first == "#" {
+                    if let color = UIColor(hex: themingColorText) {
+                        NCBrandColor.shared.brandText = color
+                    } else {
+                        NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
+                    }
+                } else {
+                    NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
+                }
 
-            settingBrandColor(themingColor, themingColorElement: themingColorElement, themingColorText: themingColorText)
+                // COLOR ELEMENT
+                if themingColorElement?.first == "#" {
+                    if let color = UIColor(hex: themingColorElement) {
+                        NCBrandColor.shared.brandElement = color
+                    } else {
+                        NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
+                    }
+                } else {
+                    NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
+                }
+            }
 
             if NCBrandColor.shared.brandElement.isTooLight() {
                 if let color = NCBrandColor.shared.brandElement.darker(by: darker) {
@@ -440,42 +479,6 @@ class NCBrandColor: NSObject {
     }
     #endif
 
-    @objc func settingBrandColor(_ themingColor: String?, themingColorElement: String?, themingColorText: String?) {
-
-        // COLOR
-        if themingColor?.first == "#" {
-            if let color = UIColor(hex: themingColor!) {
-                NCBrandColor.shared.brand = color
-            } else {
-                NCBrandColor.shared.brand = NCBrandColor.shared.customer
-            }
-        } else {
-            NCBrandColor.shared.brand = NCBrandColor.shared.customer
-        }
-
-        // COLOR TEXT
-        if themingColorText?.first == "#" {
-            if let color = UIColor(hex: themingColorText!) {
-                NCBrandColor.shared.brandText = color
-            } else {
-                NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
-            }
-        } else {
-            NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
-        }
-
-        // COLOR ELEMENT
-        if themingColorElement?.first == "#" {
-            if let color = UIColor(hex: themingColorElement!) {
-                NCBrandColor.shared.brandElement = color
-            } else {
-                NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
-            }
-        } else {
-            NCBrandColor.shared.brandElement = NCBrandColor.shared.brand
-        }
-    }
-
     private 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)

+ 2 - 6
iOSClient/Networking/NCService.swift

@@ -146,15 +146,11 @@ class NCService: NSObject {
 
         NCCommunication.shared.getCapabilities(queue: NCCommunicationCommon.shared.backgroundQueue) { account, data, errorCode, errorDescription in
 
-            let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
-            let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
-            let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
-
             guard errorCode == 0, let data = data else {
                 if errorCode == 401 || errorCode == 403 {
                     NCBrandColor.shared.settingThemingColor(account: account)
                     NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
-                    
+
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode, errorDescription: errorDescription)
                 }
                 return
@@ -173,7 +169,7 @@ class NCService: NSObject {
             let themingColorNew = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
             let themingColorElementNew = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
             let themingColorTextNew = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
-            if themingColorNew != themingColor || themingColorElementNew != themingColorElement || themingColorTextNew != themingColorText {
+            if themingColorNew != NCBrandColor.shared.themingColor || themingColorElementNew != NCBrandColor.shared.themingColorElement || themingColorTextNew != NCBrandColor.shared.themingColorText {
                 NCBrandColor.shared.settingThemingColor(account: account)
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
             }