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

Improved badgeValue

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 жил өмнө
parent
commit
50b210b3e0

+ 18 - 6
iOSClient/Main/NCMainTabBar.swift

@@ -48,7 +48,6 @@ class NCMainTabBar: UITabBar {
         appDelegate.mainTabBar = self
 
         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)
 
         barTintColor = .secondarySystemBackground
@@ -212,15 +211,28 @@ class NCMainTabBar: UITabBar {
     @objc func updateBadgeNumber(_ notification: NSNotification) {
 
         guard let userInfo = notification.userInfo as NSDictionary?,
-              let counter = userInfo["counter"] as? Int
+              let counterDownload = userInfo["counterDownload"] as? Int,
+              let counterUpload = userInfo["counterUpload"] as? Int
         else { return }
 
-        UIApplication.shared.applicationIconBadgeNumber = counter
+        UIApplication.shared.applicationIconBadgeNumber = counterUpload
         if let item = self.items?[0] {
-            if counter > 0 {
-                item.badgeValue = String(counter)
-            } else {
+            if counterDownload == 0, counterUpload == 0 {
                 item.badgeValue = nil
+            } else if counterDownload > 0, counterUpload == 0 {
+                var badgeValue = String("↓ \(counterDownload)")
+                if counterDownload >= NCGlobal.shared.maxConcurrentOperationCountDownload {
+                    badgeValue = String("↓ 10+")
+                }
+                item.badgeValue = badgeValue
+            } else if counterDownload == 0, counterUpload > 0 {
+                item.badgeValue = String("↑ \(counterUpload)")
+            } else {
+                var badgeValue = String("↓ \(counterDownload) ↑ \(counterUpload)")
+                if counterDownload >= NCGlobal.shared.maxConcurrentOperationCountDownload {
+                    badgeValue = String("↓ 10+ ↑ \(counterUpload)")
+                }
+                item.badgeValue = badgeValue
             }
         }
     }

+ 4 - 1
iOSClient/NCGlobal.swift

@@ -326,6 +326,9 @@ class NCGlobal: NSObject {
     let metadataStatusUploading: Int                = 3
     let metadataStatusUploadError: Int              = 4
 
+    // Queue Concurrent Operation Download
+    let maxConcurrentOperationCountDownload: Int    = 10
+
     //  Hidden files included in the read
     //
     let includeHiddenFiles: [String] = [".LivePhoto"]
@@ -347,7 +350,7 @@ class NCGlobal: NSObject {
     let notificationCenterRichdocumentGrabFocus                 = "richdocumentGrabFocus"
     let notificationCenterReloadDataNCShare                     = "reloadDataNCShare"
     let notificationCenterCloseRichWorkspaceWebView             = "closeRichWorkspaceWebView"
-    let notificationCenterUpdateBadgeNumber                     = "updateBadgeNumber"               // userInfo: counter
+    let notificationCenterUpdateBadgeNumber                     = "updateBadgeNumber"               // userInfo: counterDownload, counterUpload
     let notificationCenterReloadAvatar                          = "reloadAvatar"
 
     @objc let notificationCenterReloadDataSource                = "reloadDataSource"

+ 3 - 2
iOSClient/Networking/NCNetworking.swift

@@ -664,8 +664,9 @@ class NCNetworking: NSObject, NKCommonDelegate {
         }
 
         // Update Badge
-        let counterBadge = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d OR status == %d", NCGlobal.shared.metadataStatusWaitUpload, NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading))
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber, userInfo: ["counter": counterBadge.count])
+        let counterBadgeDownload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status < 0"))
+        let counterBadgeUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status > 0"))
+        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber, userInfo: ["counterDownload": counterBadgeDownload.count, "counterUpload": counterBadgeUpload.count])
 
         self.uploadMetadataInBackground.removeValue(forKey: fileName + serverUrl)
         self.delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: task, error: error)

+ 3 - 2
iOSClient/Networking/NCNetworkingProcessUpload.swift

@@ -111,8 +111,9 @@ class NCNetworkingProcessUpload: NSObject {
             let sessionSelectors = [NCGlobal.shared.selectorUploadFileNODelete, NCGlobal.shared.selectorUploadFile, NCGlobal.shared.selectorUploadAutoUpload, NCGlobal.shared.selectorUploadAutoUploadAll]
 
             // Update Badge
-            let counterBadge = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND (status == %d OR status == %d OR status == %d)", self.appDelegate.account, NCGlobal.shared.metadataStatusWaitUpload, NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading))
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber, userInfo: ["counter": counterBadge.count])
+            let counterBadgeDownload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status < 0"))
+            let counterBadgeUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status > 0"))
+            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber, userInfo: ["counterDownload": counterBadgeDownload.count, "counterUpload": counterBadgeUpload.count])
 
             // ** TEST ONLY ONE **
             // E2EE

+ 1 - 1
iOSClient/Networking/NCOperationQueue.swift

@@ -31,7 +31,7 @@ import NextcloudKit
         return instance
     }()
 
-    private var downloadQueue = Queuer(name: "downloadQueue", maxConcurrentOperationCount: 5, qualityOfService: .default)
+    private var downloadQueue = Queuer(name: "downloadQueue", maxConcurrentOperationCount: NCGlobal.shared.maxConcurrentOperationCountDownload, qualityOfService: .default)
     private let downloadThumbnailQueue = Queuer(name: "downloadThumbnailQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)
     private let downloadThumbnailActivityQueue = Queuer(name: "downloadThumbnailActivityQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)
     private let downloadAvatarQueue = Queuer(name: "downloadAvatarQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)