Explorar o código

fix DarkMode detect

marinofaggiana %!s(int64=5) %!d(string=hai) anos
pai
achega
80109d1828

+ 0 - 4
iOSClient/AppDelegate.m

@@ -217,10 +217,6 @@
     if (self.activeDetail.richDocument) {
         [self.activeDetail.richDocument grabFocus];
     }
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"applicationWillEnterForeground" object:nil];
-    });
 }
 
 //

+ 10 - 2
iOSClient/Main/NCSplitViewController.swift

@@ -26,7 +26,8 @@ import UIKit
 class NCSplitViewController: UISplitViewController {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
-
+    var timer: Timer?
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         
@@ -47,10 +48,17 @@ class NCSplitViewController: UISplitViewController {
                 } else {
                     CCUtility.setDarkMode(false)
                 }
-                NotificationCenter.default.post(name: Notification.Name.init(rawValue: "changeTheming"), object: nil)
+                // Use a timer for fix the twice call of traitCollectionDidChange for detect the Dark mode
+                if !(timer?.isValid ?? false) {
+                    timer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(timerHandlerChangeTheming(_:)), userInfo: nil, repeats: false)
+                }
             }
         }
     }
+    
+    @objc func timerHandlerChangeTheming(_ timer: Timer) {
+        NotificationCenter.default.post(name: Notification.Name.init(rawValue: "changeTheming"), object: nil)
+    }
 }
 
 extension NCSplitViewController: UISplitViewControllerDelegate {

+ 8 - 6
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -31,23 +31,25 @@ import MarkdownKit
 
     var markdownParser = MarkdownParser()
     var richWorkspaceText: String?
-    //var textViewColor: UIColor?
+    var textViewColor: UIColor?
     //let gradientLayer: CAGradientLayer = CAGradientLayer()
 
     required init?(coder: NSCoder) {
         super.init(coder: coder)
         
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "applicationWillEnterForeground"), object: nil)
         changeTheming()
     }
 
     @objc func changeTheming() {
         
-        markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15), color: NCBrandColor.sharedInstance.textView)
-        markdownParser.header.font = UIFont.systemFont(ofSize: 25)
-        if let richWorkspaceText = richWorkspaceText {
-            textView.attributedText = markdownParser.parse(richWorkspaceText)
+        if textViewColor != NCBrandColor.sharedInstance.textView {
+            markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15), color: NCBrandColor.sharedInstance.textView)
+            markdownParser.header.font = UIFont.systemFont(ofSize: 25)
+            if let richWorkspaceText = richWorkspaceText {
+                textView.attributedText = markdownParser.parse(richWorkspaceText)
+            }
+            textViewColor = NCBrandColor.sharedInstance.textView
         }
     }
     

+ 14 - 10
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -32,6 +32,8 @@ import MarkdownKit
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private let richWorkspaceCommon = NCRichWorkspaceCommon()
     private var markdownParser = MarkdownParser()
+    private var textViewColor: UIColor?
+
     @objc public var richWorkspaceText: String = ""
     @objc public var serverUrl: String = ""
    
@@ -39,7 +41,6 @@ import MarkdownKit
         super.viewDidLoad()
         
         presentationController?.delegate = self
-        markdownParser.header.font = UIFont.systemFont(ofSize: 25)
         
         let closeItem = UIBarButtonItem(title: NSLocalizedString("_back_", comment: ""), style: .plain, target: self, action: #selector(closeItemTapped(_:)))
         self.navigationItem.leftBarButtonItem = closeItem
@@ -47,10 +48,7 @@ import MarkdownKit
         let editItem = UIBarButtonItem(image: UIImage(named: "actionSheetModify"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(editItemAction(_:)))
         self.navigationItem.rightBarButtonItem = editItem
 
-        textView.attributedText = markdownParser.parse(richWorkspaceText)
-        
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "applicationWillEnterForeground"), object: nil)
         changeTheming()
     }
     
@@ -64,9 +62,11 @@ import MarkdownKit
                 var metadataFolder = tableMetadata()
                 _ = NCNetworking.sharedInstance.convertFiles(files!, urlString: self.appDelegate.activeUrl, serverUrl: self.serverUrl, user: self.appDelegate.activeUser, metadataFolder: &metadataFolder)
                 NCManageDatabase.sharedInstance.setDirectory(ocId: metadataFolder.ocId, serverUrl: metadataFolder.serverUrl, richWorkspace: metadataFolder.richWorkspace, account: account)
-                self.richWorkspaceText = metadataFolder.richWorkspace
-                self.appDelegate.activeMain.richWorkspaceText = self.richWorkspaceText
-                self.textView.attributedText = self.markdownParser.parse(self.richWorkspaceText)
+                if self.richWorkspaceText != metadataFolder.richWorkspace {
+                    self.appDelegate.activeMain.richWorkspaceText = self.richWorkspaceText
+                    self.richWorkspaceText = metadataFolder.richWorkspace
+                    self.textView.attributedText = self.markdownParser.parse(metadataFolder.richWorkspace)
+                }
             }
         }
     }
@@ -82,10 +82,14 @@ import MarkdownKit
     }
     
     @objc func changeTheming() {
+        
         appDelegate.changeTheming(self, tableView: nil, collectionView: nil, form: false)
-        markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15), color: NCBrandColor.sharedInstance.textView)
-        markdownParser.header.font = UIFont.systemFont(ofSize: 25)
-        textView.attributedText = markdownParser.parse(richWorkspaceText)
+        if textViewColor != NCBrandColor.sharedInstance.textView {
+            markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 15), color: NCBrandColor.sharedInstance.textView)
+            markdownParser.header.font = UIFont.systemFont(ofSize: 25)
+            textView.attributedText = markdownParser.parse(richWorkspaceText)
+            textViewColor = NCBrandColor.sharedInstance.textView
+        }
     }
     
     @objc func closeItemTapped(_ sender: UIBarButtonItem) {