Эх сурвалжийг харах

fix UpdateBadgeNumber

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 жил өмнө
parent
commit
e48be2833c

+ 11 - 7
iOSClient/Main/NCMainTabBar.swift

@@ -28,7 +28,6 @@ class NCMainTabBar: UITabBar {
     private var fillColor: UIColor!
     private var shapeLayer: CALayer?
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    private var timer: Timer?
 
     public var menuRect: CGRect {
         get {
@@ -45,10 +44,17 @@ class NCMainTabBar: UITabBar {
         super.init(coder: coder)
 
         appDelegate.mainTabBar = self
-        timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: (#selector(updateBadgeNumber)), userInfo: nil, repeats: true)
 
         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)
+        NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationWillEnterForeground), object: nil)
+
+        NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadCancelFile), object: nil)
+        
 
         barTintColor = NCBrandColor.shared.secondarySystemBackground
         backgroundColor = NCBrandColor.shared.secondarySystemBackground
@@ -211,15 +217,13 @@ class NCMainTabBar: UITabBar {
     @objc func updateBadgeNumber() {
         guard !appDelegate.account.isEmpty else { return }
 
-        let counterDownload = NCOperationQueue.shared.downloadQueueCount()
         let counterUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d OR status == %d", NCGlobal.shared.metadataStatusWaitUpload, NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading)).count
-        let total = counterDownload + counterUpload
 
-        UIApplication.shared.applicationIconBadgeNumber = total
+        UIApplication.shared.applicationIconBadgeNumber = counterUpload
 
         if let item = items?[0] {
-            if total > 0 {
-                item.badgeValue = String(total)
+            if counterUpload > 0 {
+                item.badgeValue = String(counterUpload)
             } else {
                 item.badgeValue = nil
             }

+ 1 - 0
iOSClient/Networking/NCNetworkingProcessUpload.swift

@@ -75,6 +75,7 @@ class NCNetworkingProcessUpload: NSObject {
                     let metadatas = NCManageDatabase.shared.getAdvancedMetadatas(predicate: NSPredicate(format: "sessionSelector == %@ AND status == %d", sessionSelector, NCGlobal.shared.metadataStatusWaitUpload), page: 1, limit: limit, sorted: "date", ascending: true)
                     if metadatas.count > 0 {
                         NCCommunicationCommon.shared.writeLog("PROCESS-UPLOAD find \(metadatas.count) items")
+                        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber)
                     }
 
                     for metadata in metadatas {