diff options
author | marinofaggiana <ios@nextcloud.com> | 2022-08-07 11:54:57 +0300 |
---|---|---|
committer | marinofaggiana <ios@nextcloud.com> | 2022-08-07 11:54:57 +0300 |
commit | f0943f87d17994e1803aeb9fde3ad9262d283ea9 (patch) | |
tree | f56ed0efb1b52182d4362f6aff67de85856a00a4 | |
parent | ad1a8c6d3005e60ebb7db7935a825863ffa47ddf (diff) |
refactoring update badge number
Signed-off-by: marinofaggiana <ios@nextcloud.com>
-rw-r--r-- | Nextcloud.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | iOSClient/AppDelegate.swift | 3 | ||||
-rw-r--r-- | iOSClient/Main/NCMainTabBar.swift | 25 | ||||
-rw-r--r-- | iOSClient/NCGlobal.swift | 2 | ||||
-rw-r--r-- | iOSClient/Networking/NCNetworkingProcessUpload.swift | 5 |
5 files changed, 16 insertions, 23 deletions
diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 009689bc0..973cccf6a 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -2997,7 +2997,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 15; + CURRENT_PROJECT_VERSION = 16; DEVELOPMENT_TEAM = 6JLRKY9ZV7; ENABLE_BITCODE = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -3060,7 +3060,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 15; + CURRENT_PROJECT_VERSION = 16; DEVELOPMENT_TEAM = 6JLRKY9ZV7; ENABLE_BITCODE = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift index 95409596b..81961b928 100644 --- a/iOSClient/AppDelegate.swift +++ b/iOSClient/AppDelegate.swift @@ -380,7 +380,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD NCAutoUpload.shared.initAutoUpload(viewController: nil) { _ in DispatchQueue.main.asyncAfter(deadline: .now() + 5) { - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber) NCCommunicationCommon.shared.writeLog("Completition handler refresh task with [Auto upload]") task.setTaskCompleted(success: true) } @@ -404,7 +403,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD NCService.shared.synchronizeOffline(account: account) DispatchQueue.main.asyncAfter(deadline: .now() + 25) { - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber) NCCommunicationCommon.shared.writeLog("Completition handler processing task [Synchronize Favorite & Offline]") task.setTaskCompleted(success: true) } @@ -422,7 +420,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD NCCommunicationCommon.shared.writeLog("Start perform Fetch [Auto upload]") NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateBadgeNumber) NCCommunicationCommon.shared.writeLog("Completition perform Fetch with \(items) uploads [Auto upload]") if items == 0 { completionHandler(UIBackgroundFetchResult.noData) diff --git a/iOSClient/Main/NCMainTabBar.swift b/iOSClient/Main/NCMainTabBar.swift index ce3d0dd6c..ef65b4361 100644 --- a/iOSClient/Main/NCMainTabBar.swift +++ b/iOSClient/Main/NCMainTabBar.swift @@ -47,14 +47,7 @@ class NCMainTabBar: UITabBar { 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) - + NotificationCenter.default.addObserver(self, selector: #selector(updateBadgeNumber(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUpdateBadgeNumber), object: nil) barTintColor = NCBrandColor.shared.secondarySystemBackground backgroundColor = NCBrandColor.shared.secondarySystemBackground @@ -214,16 +207,16 @@ class NCMainTabBar: UITabBar { self.addSubview(centerButton) } - @objc func updateBadgeNumber() { - guard !appDelegate.account.isEmpty else { return } - - 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 + @objc func updateBadgeNumber(_ notification: NSNotification) { - UIApplication.shared.applicationIconBadgeNumber = counterUpload + guard let userInfo = notification.userInfo as NSDictionary?, + let counter = userInfo["counter"] as? Int + else { return } - if let item = items?[0] { - if counterUpload > 0 { - item.badgeValue = String(counterUpload) + UIApplication.shared.applicationIconBadgeNumber = counter + if let item = self.items?[0] { + if counter > 0 { + item.badgeValue = String(counter) } else { item.badgeValue = nil } diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index e95fa4b20..d9f12fe88 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -328,7 +328,7 @@ class NCGlobal: NSObject { let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus" let notificationCenterReloadDataNCShare = "reloadDataNCShare" let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView" - let notificationCenterUpdateBadgeNumber = "updateBadgeNumber" + let notificationCenterUpdateBadgeNumber = "updateBadgeNumber" // userInfo: counter let notificationCenterReloadAvatar = "reloadAvatar" @objc let notificationCenterReloadDataSource = "reloadDataSource" // userInfo: serverUrl? diff --git a/iOSClient/Networking/NCNetworkingProcessUpload.swift b/iOSClient/Networking/NCNetworkingProcessUpload.swift index 07a757b68..7f4a9aed9 100644 --- a/iOSClient/Networking/NCNetworkingProcessUpload.swift +++ b/iOSClient/Networking/NCNetworkingProcessUpload.swift @@ -66,6 +66,10 @@ class NCNetworkingProcessUpload: NSObject { print("[LOG] PROCESS-UPLOAD \(counterUpload)") + // 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]) + NCNetworking.shared.getOcIdInBackgroundSession(queue: DispatchQueue.global(qos: .background), completion: { listOcId in for sessionSelector in sessionSelectors { @@ -75,7 +79,6 @@ 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 { |