diff --git a/iOSClient/Main/NCMainTabBar.swift b/iOSClient/Main/NCMainTabBar.swift index 16e7cfe3cd..09b7ae5b35 100644 --- a/iOSClient/Main/NCMainTabBar.swift +++ b/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 } } } diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index eba8fe5275..c4415ac721 100644 --- a/iOSClient/NCGlobal.swift +++ b/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" diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index b134571273..0ea981e266 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/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) diff --git a/iOSClient/Networking/NCNetworkingProcessUpload.swift b/iOSClient/Networking/NCNetworkingProcessUpload.swift index 0843f2475c..06d2b37869 100644 --- a/iOSClient/Networking/NCNetworkingProcessUpload.swift +++ b/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 diff --git a/iOSClient/Networking/NCOperationQueue.swift b/iOSClient/Networking/NCOperationQueue.swift index 4934200d09..9a9fec49af 100644 --- a/iOSClient/Networking/NCOperationQueue.swift +++ b/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)