Skip to content

Commit

Permalink
Improved badgeValue
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Oct 2, 2023
1 parent fbedc57 commit 50b210b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
24 changes: 18 additions & 6 deletions iOSClient/Main/NCMainTabBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion iOSClient/NCGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions iOSClient/Networking/NCNetworking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions iOSClient/Networking/NCNetworkingProcessUpload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion iOSClient/Networking/NCOperationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 50b210b

Please sign in to comment.