Browse Source

remove switch darkmode

marinofaggiana 4 years ago
parent
commit
c01d51df47

+ 10 - 11
iOSClient/AppDelegate.swift

@@ -55,6 +55,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     var listOfflineVC: [String:NCOffline] = [:]
     var listProgress: [String:NCGlobal.progressType] = [:]
     
+    @objc var darkMode: Bool = false
     var disableSharesView: Bool = false
     var documentPickerViewController: NCDocumentPickerViewController?
     var networkingProcessUpload: NCNetworkingProcessUpload?
@@ -146,13 +147,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         
         // Detect Dark mode
         if #available(iOS 13.0, *) {
-            if CCUtility.getDarkModeDetect() {
-                if UITraitCollection.current.userInterfaceStyle == .dark {
-                    CCUtility.setDarkMode(true)
-                } else {
-                    CCUtility.setDarkMode(false)
-                }
+            if UITraitCollection.current.userInterfaceStyle == .dark {
+                darkMode = true
+            } else {
+                darkMode = false
             }
+        } else {
+            darkMode = false
         }
         
         // Background task: register
@@ -280,7 +281,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         NCPushNotification.shared().pushNotification()
         
         // Setting Theming
-        NCBrandColor.shared.settingThemingColor(account: account)
+        NCBrandColor.shared.settingThemingColor(account: account, darkMode: darkMode)
         
         // Start Auto Upload
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { (_) in }
@@ -650,10 +651,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         
         if passcodeViewController == nil {
             passcodeViewController = TOPasscodeViewController.init(style: .translucentLight, passcodeType: .sixDigits)
-            if #available(iOS 13.0, *) {
-                if UITraitCollection.current.userInterfaceStyle == .dark {
-                    passcodeViewController?.style = .translucentDark
-                }
+            if darkMode {
+                passcodeViewController?.style = .translucentDark
             }
             passcodeViewController?.delegate = self
             passcodeViewController?.keypadButtonShowLettering = false

+ 7 - 8
iOSClient/Brand/NCBrand.swift

@@ -102,7 +102,6 @@ import UIKit
 class NCBrandColor: NSObject {
     @objc static let shared: NCBrandColor = {
         let instance = NCBrandColor()
-        instance.setDarkMode()
         instance.createImagesThemingColor()
         return instance
     }()
@@ -146,7 +145,7 @@ class NCBrandColor: NSObject {
     @objc public var connectionNo:          UIColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
     @objc public var encrypted:             UIColor = .red
     @objc public var backgroundView:        UIColor = .white
-    @objc public var backgroundForm:        UIColor = UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
+    @objc public var backgroundForm:        UIColor = UIColor(red: 229.0/255.0, green: 229.0/255.0, blue: 234.0/255.0, alpha: 1.0)  // Gray (5) Light
     @objc public var backgroundSettings:    UIColor = UIColor(red: 242.0/255.0, green: 242.0/255.0, blue: 247.0/255.0, alpha: 1.0)  // Gray (6) Light
     @objc public var cellSettings:          UIColor = .white
     @objc public var textView:              UIColor = .black
@@ -160,7 +159,7 @@ class NCBrandColor: NSObject {
     @objc public let graySoft:              UIColor = UIColor(red: 162.0/255.0, green: 162.0/255.0, blue: 162.0/255.0, alpha: 0.5)
     @objc public let yellowFavorite:        UIColor = UIColor(red: 248.0/255.0, green: 205.0/255.0, blue: 70.0/255.0, alpha: 1.0)
     @objc public let textInfo:              UIColor = UIColor(red: 153.0/255.0, green: 153.0/255.0, blue: 153.0/255.0, alpha: 1.0)
-    @objc public var select:                UIColor = .white
+    @objc public var select:                UIColor = .lightGray
     @objc public var avatarBorder:          UIColor = .white
 
     override init() {
@@ -199,9 +198,9 @@ class NCBrandColor: NSObject {
         cacheImages.buttonStop = UIImage(named: "stop")!.image(color: graySoft, size: 50)
     }
     
-    @objc public func setDarkMode() {
-        let darkMode = CCUtility.getDarkMode()
-        if darkMode {
+    @objc public func setDarkMode(_ dark: Bool) {
+
+        if dark {
             
             tabBar = UIColor(red: 28.0/255.0, green: 28.0/255.0, blue: 30.0/255.0, alpha: 1.0)                          // Gray (6) Dark
             navigationBar = .black
@@ -236,7 +235,7 @@ class NCBrandColor: NSObject {
     }
     
 #if !EXTENSION
-    public func settingThemingColor(account: String) {
+public func settingThemingColor(account: String, darkMode: Bool) {
         
         let darker: CGFloat = 30    // %
         let lighter: CGFloat = 30   // %
@@ -279,7 +278,7 @@ class NCBrandColor: NSObject {
             NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
         }
         
-        setDarkMode()
+        setDarkMode(darkMode)
         
         DispatchQueue.main.async {
             self.createImagesThemingColor()

+ 9 - 7
iOSClient/Main/NCMainTabBar.swift

@@ -49,14 +49,16 @@ class NCMainTabBar: UITabBar {
         super.traitCollectionDidChange(previousTraitCollection)
         
         if #available(iOS 13.0, *) {
-            if CCUtility.getDarkModeDetect() {
-                if traitCollection.userInterfaceStyle == .dark {
-                    CCUtility.setDarkMode(true)
-                } else {
-                    CCUtility.setDarkMode(false)
-                }
+            
+            if traitCollection.userInterfaceStyle == .dark {
+                appDelegate.darkMode = true
+            } else {
+                appDelegate.darkMode = false
             }
-            NCBrandColor.shared.settingThemingColor(account: appDelegate.account)
+            
+            NCBrandColor.shared.settingThemingColor(account: appDelegate.account, darkMode: appDelegate.darkMode)
+        } else {
+            appDelegate.darkMode = false
         }
     }
     

+ 3 - 1
iOSClient/Main/Section Header Footer/NCSectionHeaderFooter.swift

@@ -35,6 +35,8 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
     @IBOutlet weak var textViewRichWorkspace: UITextView!
     @IBOutlet weak var separator: UIView!
     
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+
     var delegate: NCSectionHeaderMenuDelegate?
     
     private var markdownParser = MarkdownParser()
@@ -85,7 +87,7 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
             }
             textViewColor = NCBrandColor.shared.textView
             
-            if CCUtility.getDarkMode() {
+            if appDelegate.darkMode {
                 gradient.colors = [UIColor.init(white: 0, alpha: 0).cgColor, UIColor.black.cgColor]
             } else {
                 gradient.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]

+ 3 - 3
iOSClient/Networking/NCService.swift

@@ -146,7 +146,7 @@ class NCService: NSObject {
                     NCCommunicationCommon.shared.setup(dav: NCUtilityFileSystem.shared.getDAV())
                     
                     // Theming
-                    NCBrandColor.shared.settingThemingColor(account: account)
+                    NCBrandColor.shared.settingThemingColor(account: account, darkMode: self.appDelegate.darkMode)
                 
                     // File Sharing
                     let isFilesSharingEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
@@ -232,14 +232,14 @@ class NCService: NSObject {
                 
             } else if errorCode != 0 {
                 
-                NCBrandColor.shared.settingThemingColor(account: account)
+                NCBrandColor.shared.settingThemingColor(account: account, darkMode: self.appDelegate.darkMode)
                 
                 if errorCode == 401 || errorCode == 403 {
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account)
                 }
                 
             } else {
-                NCBrandColor.shared.settingThemingColor(account: account)
+                NCBrandColor.shared.settingThemingColor(account: account, darkMode: self.appDelegate.darkMode)
             }
         }
     }

+ 3 - 1
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -31,6 +31,8 @@ import MarkdownKit
     @IBOutlet weak var sortButton: UIButton!
     @objc @IBOutlet weak var textView: UITextView!
     
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+
     private var markdownParser = MarkdownParser()
     private var richWorkspaceText: String?
     private var textViewColor: UIColor?
@@ -61,7 +63,7 @@ import MarkdownKit
             }
             textViewColor = NCBrandColor.shared.textView
             
-            if CCUtility.getDarkMode() {
+            if appDelegate.darkMode {
                 gradient.colors = [UIColor.init(white: 0, alpha: 0).cgColor, UIColor.black.cgColor]
             } else {
                 gradient.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]

+ 0 - 57
iOSClient/Settings/NCSettings.m

@@ -99,30 +99,6 @@
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_screen_", nil)];
     [form addFormSection:section];
     
-    // Dark Mode
-    if (@available(iOS 13.0, *)) {
-        
-        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkModeDetect" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_dark_mode_detect_", nil)];
-        row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
-        [row.cellConfig setObject:[[UIImage imageNamed:@"themeLightDark"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
-        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-        [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
-        if ([CCUtility getDarkModeDetect]) row.value = @1;
-        else row.value = @0;
-        [section addFormRow:row];
-        
-    } else {
-        
-        row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkMode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_dark_mode_", nil)];
-        row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.cellSettings;
-        [row.cellConfig setObject:[[UIImage imageNamed:@"themeLightDark"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
-        [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
-        [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
-        if ([CCUtility getDarkMode]) row.value = @1;
-        else row.value = @0;
-        [section addFormRow:row];
-    }
-    
     // Section : E2EEncryption --------------------------------------------------------------
         
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
@@ -262,8 +238,6 @@
     XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
     XLFormRowDescriptor *rowNotPasscodeAtStart = [self.form formRowWithTag:@"notPasscodeAtStart"];
     XLFormRowDescriptor *rowEnableTouchDaceID = [self.form formRowWithTag:@"enableTouchDaceID"];
-    XLFormRowDescriptor *rowDarkModeDetect = [self.form formRowWithTag:@"darkModeDetect"];
-    XLFormRowDescriptor *rowDarkMode = [self.form formRowWithTag:@"darkMode"];
 
     // ------------------------------------------------------------------
     
@@ -277,8 +251,6 @@
     
     if ([CCUtility getEnableTouchFaceID]) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0];
     if ([CCUtility getNotPasscodeAtStart]) [rowNotPasscodeAtStart setValue:@1]; else [rowNotPasscodeAtStart setValue:@0];
-    if ([CCUtility getDarkModeDetect]) [rowDarkModeDetect setValue:@1]; else [rowDarkModeDetect setValue:@0];
-    if ([CCUtility getDarkMode]) [rowDarkMode setValue:@1]; else [rowDarkMode setValue:@0];
 
     // -----------------------------------------------------------------
     
@@ -308,35 +280,6 @@
             [CCUtility setEnableTouchFaceID:false];
         }
     }
-    
-    if ([rowDescriptor.tag isEqualToString:@"darkMode"]) {
-        
-        if ([[rowDescriptor.value valueData] boolValue] == YES) {
-            [CCUtility setDarkMode:true];
-        } else {
-            [CCUtility setDarkMode:false];
-        }
-        
-        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCGlobal.shared.notificationCenterChangeTheming object:nil];
-    }
-    
-    if ([rowDescriptor.tag isEqualToString:@"darkModeDetect"]) {
-        
-        if ([[rowDescriptor.value valueData] boolValue] == YES) {
-            [CCUtility setDarkModeDetect:true];
-            // detect Dark Mode
-            if (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
-                [CCUtility setDarkMode:YES];
-            } else {
-                [CCUtility setDarkMode:NO];
-            }
-        } else {
-            [CCUtility setDarkModeDetect:false];
-            [CCUtility setDarkMode:false];
-        }
-        
-        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCGlobal.shared.notificationCenterChangeTheming object:nil];
-    }
 }
 
 #pragma mark -

+ 0 - 6
iOSClient/Utility/CCUtility.h

@@ -147,12 +147,6 @@
 + (BOOL)getDisableLocalCacheAfterUpload;
 + (void)setDisableLocalCacheAfterUpload:(BOOL)disable;
 
-+ (BOOL)getDarkMode;
-+ (void)setDarkMode:(BOOL)disable;
-
-+ (BOOL)getDarkModeDetect;
-+ (void)setDarkModeDetect:(BOOL)disable;
-
 + (BOOL)getLivePhoto;
 + (void)setLivePhoto:(BOOL)set;
 

+ 0 - 44
iOSClient/Utility/CCUtility.m

@@ -574,50 +574,6 @@
     [UICKeyChainStore setString:sDisable forKey:@"disableLocalCacheAfterUpload" service:NCGlobal.shared.serviceShareKeyChain];
 }
 
-+ (BOOL)getDarkMode
-{
-    NSString *sDisable = [UICKeyChainStore stringForKey:@"darkMode" service:NCGlobal.shared.serviceShareKeyChain];
-    if(!sDisable){
-        if (@available(iOS 13.0, *)) {
-            if ([CCUtility getDarkModeDetect]) {
-                if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
-                    sDisable = @"YES";
-                    [CCUtility setDarkMode:YES];
-                } else {
-                    sDisable = @"NO";
-                    [CCUtility setDarkMode:NO];
-                }
-            }
-        }
-    }
-    return [sDisable boolValue];
-}
-
-+ (void)setDarkMode:(BOOL)disable
-{
-    NSString *sDisable = (disable) ? @"true" : @"false";
-    [UICKeyChainStore setString:sDisable forKey:@"darkMode" service:NCGlobal.shared.serviceShareKeyChain];
-}
-
-+ (BOOL)getDarkModeDetect
-{
-    NSString *valueString = [UICKeyChainStore stringForKey:@"darkModeDetect" service:NCGlobal.shared.serviceShareKeyChain];
-    
-    // Default TRUE
-    if (valueString == nil) {
-        [self setDarkModeDetect:YES];
-        return true;
-    }
-    
-    return [valueString boolValue];
-}
-
-+ (void)setDarkModeDetect:(BOOL)disable
-{
-    NSString *sDisable = (disable) ? @"true" : @"false";
-    [UICKeyChainStore setString:sDisable forKey:@"darkModeDetect" service:NCGlobal.shared.serviceShareKeyChain];
-}
-
 + (BOOL)getLivePhoto
 {
     NSString *valueString = [UICKeyChainStore stringForKey:@"livePhoto" service:NCGlobal.shared.serviceShareKeyChain];