marinofaggiana 4 years ago
parent
commit
9e85968c90

+ 0 - 3
iOSClient/AppDelegate.h

@@ -140,9 +140,6 @@
 // Push Notification
 - (void)pushNotification;
 
-// Theming Color
-- (void)settingThemingColorBrand;
-
 // Maintenance Mode
 - (void)maintenanceMode:(BOOL)mode;
 

+ 1 - 52
iOSClient/AppDelegate.m

@@ -287,7 +287,7 @@
     [CCUtility setCertificateError:self.account error:NO];
     
     // Setting Theming
-    [self settingThemingColorBrand];
+    [[NCBrandColor sharedInstance] settingThemingColor];
     
     // If AVPlayer in play -> Stop
     if (self.player != nil && self.player.rate != 0) {
@@ -734,57 +734,6 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Theming Color =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)settingThemingColorBrand
-{
-    if (self.account.length == 0 || self.maintenanceMode)
-        return;
-    
-    if ([NCBrandOptions sharedInstance].use_themingColor) {
-        
-        NSString *themingColor = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.account elements:NCElementsJSON.shared.capabilitiesThemingColor];
-        NSString *themingColorElement = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.account elements:NCElementsJSON.shared.capabilitiesThemingColorElement];
-        NSString *themingColorText = [[NCManageDatabase sharedInstance] getCapabilitiesServerStringWithAccount:self.account elements:NCElementsJSON.shared.capabilitiesThemingColorText];
-
-        [CCGraphics settingThemingColor:themingColor themingColorElement:themingColorElement themingColorText:themingColorText];
-        
-        BOOL isTooLight = NCBrandColor.sharedInstance.brandElement.isTooLight;
-        BOOL isTooDark = NCBrandColor.sharedInstance.brandElement.isTooDark;
-        
-        if (isTooLight) {
-            NCBrandColor.sharedInstance.brandElement = [NCBrandColor.sharedInstance.brandElement darkerBy:10];
-        } else if (isTooDark) {
-            NCBrandColor.sharedInstance.brandElement = [NCBrandColor.sharedInstance.brandElement lighterBy:40];
-        }
-    
-    } else {
-    
-        BOOL isTooLight = NCBrandColor.sharedInstance.customer.isTooLight;
-        BOOL isTooDark = NCBrandColor.sharedInstance.customer.isTooDark;
-        
-        if (isTooLight) {
-            NCBrandColor.sharedInstance.brandElement = [NCBrandColor.sharedInstance.customer darkerBy:10];
-        } else if (isTooDark) {
-            NCBrandColor.sharedInstance.brandElement = [NCBrandColor.sharedInstance.customer lighterBy:40];
-        } else {
-            NCBrandColor.sharedInstance.brandElement = NCBrandColor.sharedInstance.customer;
-        }
-        
-        NCBrandColor.sharedInstance.brand = NCBrandColor.sharedInstance.customer;
-        NCBrandColor.sharedInstance.brandText = NCBrandColor.sharedInstance.customerText;
-    }
-        
-    [NCBrandColor.sharedInstance setDarkMode];
-    
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        [[NCCollectionCommon shared] createImagesThemingColor];
-        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_changeTheming object:nil];
-    });
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Fetch =====
 #pragma --------------------------------------------------------------------------------------------

+ 54 - 0
iOSClient/Brand/NCBrand.swift

@@ -153,4 +153,58 @@ class NCBrandColor: NSObject {
             select = self.brandElement.withAlphaComponent(0.1)
         }
     }
+    
+#if !EXTENSION
+    @objc public func settingThemingColor() {
+        
+        let appDelegate = UIApplication.shared.delegate as! AppDelegate
+        let darker: CGFloat = 10
+        let lighter: CGFloat = 40
+
+        if NCBrandOptions.sharedInstance.use_themingColor {
+            
+            let themingColor = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
+            
+            let themingColorElement = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
+            
+            let themingColorText = NCManageDatabase.sharedInstance.getCapabilitiesServerString(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
+            
+            CCGraphics.settingThemingColor(themingColor, themingColorElement: themingColorElement, themingColorText: themingColorText)
+                        
+            if NCBrandColor.sharedInstance.brandElement.isTooLight() {
+                if let color = NCBrandColor.sharedInstance.brandElement.darker(by: darker) {
+                    NCBrandColor.sharedInstance.brandElement = color
+                }
+            } else if NCBrandColor.sharedInstance.brandElement.isTooDark() {
+                if let color = NCBrandColor.sharedInstance.brandElement.lighter(by: lighter) {
+                    NCBrandColor.sharedInstance.brandElement = color
+                }
+            }           
+            
+        } else {
+            
+            if NCBrandColor.sharedInstance.customer.isTooLight() {
+                if let color = NCBrandColor.sharedInstance.customer.darker(by: darker) {
+                    NCBrandColor.sharedInstance.brandElement = color
+                }
+            } else if NCBrandColor.sharedInstance.customer.isTooDark() {
+                if let color = NCBrandColor.sharedInstance.customer.lighter(by: lighter) {
+                    NCBrandColor.sharedInstance.brandElement = color
+                }
+            } else {
+                NCBrandColor.sharedInstance.brandElement = NCBrandColor.sharedInstance.customer
+            }
+            
+            NCBrandColor.sharedInstance.brand = NCBrandColor.sharedInstance.customer
+            NCBrandColor.sharedInstance.brandText = NCBrandColor.sharedInstance.customerText
+        }
+        
+        setDarkMode()
+        
+        DispatchQueue.main.async {
+            NCCollectionCommon.shared.createImagesThemingColor()
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_changeTheming)
+        }
+    }
+#endif
 }

+ 1 - 1
iOSClient/Main/NCMainTabBar.swift

@@ -52,7 +52,7 @@ import Foundation
                     CCUtility.setDarkMode(false)
                 }
             }
-            appDelegate.settingThemingColorBrand()
+            NCBrandColor.sharedInstance.settingThemingColor()
         }
     }
     

+ 3 - 3
iOSClient/Networking/NCService.swift

@@ -156,7 +156,7 @@ class NCService: NSObject {
                 self.appDelegate.settingSetupCommunication(account)
             
                 // Theming
-                self.appDelegate.settingThemingColorBrand()
+                NCBrandColor.sharedInstance.settingThemingColor()
             
                 // File Sharing
                 let isFilesSharingEnabled = NCManageDatabase.sharedInstance.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
@@ -206,14 +206,14 @@ class NCService: NSObject {
                 
             } else if errorCode != 0 {
                 
-                self.appDelegate.settingThemingColorBrand()
+                NCBrandColor.sharedInstance.settingThemingColor()
                 
                 if errorCode == 401 || errorCode == 403 {
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account)
                 }
                 
             } else {
-                self.appDelegate.settingThemingColorBrand()
+                NCBrandColor.sharedInstance.settingThemingColor()
             }
         }
     }