Browse Source

improved dark mode

marinofaggiana 3 years ago
parent
commit
e355af67c3

+ 3 - 17
iOSClient/AppDelegate.swift

@@ -63,20 +63,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     var shares: [tableShare] = []
     var timerErrorNetworking: Timer?
     
-    private var dark: Bool = false
-    var darkMode: Bool {
-        get {
-            return self.dark
-        }
-        set(value) {
-            if value != self.dark {
-                self.dark = value
-                NCBrandColor.shared.setDarkMode(value)
-                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
-            }
-        }
-    }
-
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
         
         let userAgent = CCUtility.getUserAgent() as String
@@ -685,9 +671,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         
         if passcodeViewController == nil {
             passcodeViewController = TOPasscodeViewController.init(style: .translucentLight, passcodeType: .sixDigits)
-            if darkMode {
-                passcodeViewController?.style = .translucentDark
-            }
+            //if traitCollection.userInterfaceStyle == .dark {
+            //    passcodeViewController?.style = .translucentDark
+            //}
             passcodeViewController?.delegate = self
             passcodeViewController?.keypadButtonShowLettering = false
             if CCUtility.getEnableTouchFaceID() && laContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {

+ 0 - 22
iOSClient/Brand/NCBrand.swift

@@ -163,15 +163,6 @@ class NCBrandColor: NSObject {
             }
         }
     }
-    @objc public var tertiarySystemBackground: UIColor {
-        get {
-            if #available(iOS 13, *) {
-                return .tertiarySystemBackground
-            } else {
-                return .white
-            }
-        }
-    }
     @objc public var systemGroupedBackground: UIColor {
         get {
             if #available(iOS 13, *) {
@@ -216,7 +207,6 @@ 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 = .lightGray
 
     override init() {
         self.brand = self.customer
@@ -254,18 +244,6 @@ class NCBrandColor: NSObject {
         cacheImages.buttonStop = UIImage(named: "stop")!.image(color: graySoft, size: 50)
     }
     
-    @objc public func setDarkMode(_ dark: Bool) {
-
-        if dark {
-                                    
-            select = UIColor.white.withAlphaComponent(0.2)
-            
-        } else {
-
-            select = self.brandElement.withAlphaComponent(0.1)
-        }
-    }
-    
 #if !EXTENSION
     public func settingThemingColor(account: String) {
         

+ 0 - 6
iOSClient/Main/NCMainNavigationController.swift

@@ -32,12 +32,6 @@ class NCMainNavigationController: UINavigationController {
         
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
         
-        if traitCollection.userInterfaceStyle == .dark {
-            appDelegate.darkMode = true
-        } else {
-            appDelegate.darkMode = false
-        }
-        
         changeTheming()
     }
 

+ 0 - 12
iOSClient/Main/NCMainTabBar.swift

@@ -42,12 +42,6 @@ class NCMainTabBar: UITabBar {
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUpdateBadgeNumber), object: nil)
 
-        if traitCollection.userInterfaceStyle == .dark {
-            appDelegate.darkMode = true
-        } else {
-            appDelegate.darkMode = false
-        }
-        
         barTintColor = NCBrandColor.shared.secondarySystemBackground
         backgroundColor = NCBrandColor.shared.secondarySystemBackground
         
@@ -56,12 +50,6 @@ class NCMainTabBar: UITabBar {
     
     override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
         super.traitCollectionDidChange(previousTraitCollection)
-        
-        if traitCollection.userInterfaceStyle == .dark {
-            appDelegate.darkMode = true
-        } else {
-            appDelegate.darkMode = false
-        }
     }
     
     @objc func changeTheming() {

+ 20 - 18
iOSClient/Main/Section Header Footer/NCSectionHeaderFooter.swift

@@ -45,6 +45,10 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
     override func awakeFromNib() {
         super.awakeFromNib()
         
+        backgroundColor = NCBrandColor.shared.systemBackground
+
+        separator.backgroundColor = NCBrandColor.shared.separator
+
         buttonSwitch.setImage(UIImage.init(named: "switchList")!.image(color: NCBrandColor.shared.icon, size: 25), for: .normal)
         
         buttonOrder.setTitle("", for: .normal)
@@ -60,11 +64,7 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
         tap.delegate = self
         viewRichWorkspace?.addGestureRecognizer(tap)
         
-        NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
-        
-        backgroundColor = NCBrandColor.shared.systemBackground
-        
-        changeTheming()
+        changeColor()
     }
     
     override func layoutSublayers(of layer: CALayer) {
@@ -72,21 +72,23 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate
         gradient.frame = viewRichWorkspace.bounds
     }
     
-    @objc func changeTheming() {
+    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        super.traitCollectionDidChange(previousTraitCollection)
         
-        separator.backgroundColor = NCBrandColor.shared.separator
+        changeColor()
+    }
+    
+    @objc func changeColor() {
         
-        if textViewColor != NCBrandColor.shared.label {
-            markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15), color: NCBrandColor.shared.label)
-            markdownParser.header.font = UIFont.systemFont(ofSize: 25)
-            if let richWorkspaceText = richWorkspaceText {
-                textViewRichWorkspace.attributedText = markdownParser.parse(richWorkspaceText)
-            }
-            textViewColor = NCBrandColor.shared.label
-            gradient.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]
-            if traitCollection.userInterfaceStyle == .dark {
-                gradient.colors = [UIColor.init(white: 0, alpha: 0).cgColor, UIColor.black.cgColor]
-            }
+        markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15), color: NCBrandColor.shared.label)
+        markdownParser.header.font = UIFont.systemFont(ofSize: 25)
+        if let richWorkspaceText = richWorkspaceText {
+            textViewRichWorkspace.attributedText = markdownParser.parse(richWorkspaceText)
+        }
+        textViewColor = NCBrandColor.shared.label
+        gradient.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]
+        if traitCollection.userInterfaceStyle == .dark {
+            gradient.colors = [UIColor.init(white: 0, alpha: 0).cgColor, UIColor.black.cgColor]
         }
     }
     

+ 0 - 2
iOSClient/More/NCMore.swift

@@ -316,8 +316,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
 
         // change color selection and disclosure indicator
         let selectionColor: UIView = UIView()
-        selectionColor.backgroundColor = NCBrandColor.shared.select
-
         if (indexPath.section == 0) {
             
             let cell = tableView.dequeueReusableCell(withIdentifier: "userCell", for: indexPath) as! NCMoreUserCell

+ 1 - 1
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -63,7 +63,7 @@ import MarkdownKit
             }
             textViewColor = NCBrandColor.shared.label
             
-            if appDelegate.darkMode {
+            if traitCollection.userInterfaceStyle == .dark {
                 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 - 6
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -73,12 +73,6 @@ import MarkdownKit
     
     override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
         super.traitCollectionDidChange(previousTraitCollection)
-        
-        if traitCollection.userInterfaceStyle == .dark {
-            appDelegate.darkMode = true
-        } else {
-            appDelegate.darkMode = false
-        }
     }
     
     public func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {