Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/ios.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarino Faggiana <ios@nextcloud.com>2022-08-04 12:58:14 +0300
committerGitHub <noreply@github.com>2022-08-04 12:58:14 +0300
commit2ff12a46b91d18ec45d9c8a4c4e4e815a8b89585 (patch)
treecb14a74cb54492eda5a8b8669cabc83677e802fa
parent339c69cc4761091f9e1e78271f55fdad40fec386 (diff)
parent462cad06f14936135845775a8353eecd7a6c08c8 (diff)
Merge pull request #2102 from nextcloud/fix/441
fix UpdateBadgeNumber
-rw-r--r--Nextcloud.xcodeproj/project.pbxproj10
-rw-r--r--iOSClient/AppDelegate.swift6
-rw-r--r--iOSClient/Data/NCDataSource.swift4
-rw-r--r--iOSClient/Data/NCManageDatabase+Metadata.swift2
-rw-r--r--iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift2
-rw-r--r--iOSClient/Main/NCMainTabBar.swift18
-rw-r--r--iOSClient/Networking/NCNetworking.swift11
-rw-r--r--iOSClient/Networking/NCNetworkingChunkedUpload.swift2
-rw-r--r--iOSClient/Networking/NCNetworkingE2EE.swift2
-rw-r--r--iOSClient/Networking/NCNetworkingProcessUpload.swift1
-rw-r--r--iOSClient/Utility/ThreadSafeDictionary.swift65
11 files changed, 102 insertions, 21 deletions
diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj
index 875d0a48e..168e029a8 100644
--- a/Nextcloud.xcodeproj/project.pbxproj
+++ b/Nextcloud.xcodeproj/project.pbxproj
@@ -149,6 +149,10 @@
F7239871253D86B600257F49 /* NCEmptyDataSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7239870253D86B600257F49 /* NCEmptyDataSet.swift */; };
F7239877253D86D300257F49 /* NCEmptyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7239876253D86D300257F49 /* NCEmptyView.xib */; };
F723B3DD22FC6D1D00301EFE /* NCShareCommentsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F723B3DC22FC6D1C00301EFE /* NCShareCommentsCell.xib */; };
+ F7245924289BB50C00474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
+ F7245925289BB59100474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
+ F7245926289BB59300474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
+ F7245927289BB59300474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; };
F72685E727C78E490019EF5E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F72685E927C78E490019EF5E /* InfoPlist.strings */; };
F726EEEC1FED1C820030B9C8 /* NCEndToEndInitialize.swift in Sources */ = {isa = PBXBuildFile; fileRef = F726EEEB1FED1C820030B9C8 /* NCEndToEndInitialize.swift */; };
F72928A0253B0937009CA4FD /* NCMainNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F729289F253B0937009CA4FD /* NCMainNavigationController.swift */; };
@@ -642,6 +646,7 @@
F7239870253D86B600257F49 /* NCEmptyDataSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEmptyDataSet.swift; sourceTree = "<group>"; };
F7239876253D86D300257F49 /* NCEmptyView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCEmptyView.xib; sourceTree = "<group>"; };
F723B3DC22FC6D1C00301EFE /* NCShareCommentsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareCommentsCell.xib; sourceTree = "<group>"; };
+ F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThreadSafeDictionary.swift; sourceTree = "<group>"; };
F7267A81225DFCE100D6DB7D /* AFNetworking.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AFNetworking.framework; path = Carthage/Build/iOS/AFNetworking.framework; sourceTree = "<group>"; };
F72685E827C78E490019EF5E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
F726EEEB1FED1C820030B9C8 /* NCEndToEndInitialize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCEndToEndInitialize.swift; sourceTree = "<group>"; };
@@ -1563,6 +1568,7 @@
AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */,
F74AF3A3247FB6AE00AC767B /* NCUtilityFileSystem.swift */,
AF36077027BFA4E8001A243D /* ParallelWorker.swift */,
+ F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */,
F702F2FC25EE5D2C008F8E80 /* NYMnemonic */,
);
path = Utility;
@@ -2390,6 +2396,7 @@
2C1D5D7523E2DE3300334ABB /* NCDatabase.swift in Sources */,
F7E98C1927E0D0FC001F9F19 /* NCManageDatabase+Video.swift in Sources */,
2C1D5D7623E2DE3300334ABB /* NCManageDatabase.swift in Sources */,
+ F7245927289BB59300474787 /* ThreadSafeDictionary.swift in Sources */,
2C33C48223E2C475005F963B /* NotificationService.swift in Sources */,
AF4BF617275629E20081CEEF /* NCManageDatabase+Account.swift in Sources */,
D575039F27146F93008DC9DC /* String+Extensions.swift in Sources */,
@@ -2420,6 +2427,7 @@
buildActionMask = 2147483647;
files = (
F746EC4E273906B80052598D /* NCViewCertificateDetails.swift in Sources */,
+ F7245925289BB59100474787 /* ThreadSafeDictionary.swift in Sources */,
F73D5E48246DE09200DF6467 /* NCElementsJSON.swift in Sources */,
F7EDE4E5262D7BBE00414FE6 /* NCSectionHeaderFooter.swift in Sources */,
F79EC78926316AC4004E59D6 /* NCPopupViewController.swift in Sources */,
@@ -2471,6 +2479,7 @@
buildActionMask = 2147483647;
files = (
F771E3F720E239B500AFB62D /* FileProviderExtension+Actions.swift in Sources */,
+ F7245926289BB59300474787 /* ThreadSafeDictionary.swift in Sources */,
F76673F022C90434007ED366 /* FileProviderUtility.swift in Sources */,
F7434B3420E23FD700417916 /* NCDatabase.swift in Sources */,
F702F2D125EE5B5C008F8E80 /* NCGlobal.swift in Sources */,
@@ -2523,6 +2532,7 @@
F769454022E9F077000A798A /* NCSharePaging.swift in Sources */,
F78ACD4221903CE00088454D /* NCListCell.swift in Sources */,
F76D3CF12428B40E005DFA87 /* NCViewerPDFSearch.swift in Sources */,
+ F7245924289BB50C00474787 /* ThreadSafeDictionary.swift in Sources */,
F73F537F1E929C8500F8678D /* NCMore.swift in Sources */,
F702F2CF25EE5B5C008F8E80 /* NCGlobal.swift in Sources */,
F72CD63A25C19EBF00F46F9A /* NCAutoUpload.swift in Sources */,
diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift
index fc1380fe7..95409596b 100644
--- a/iOSClient/AppDelegate.swift
+++ b/iOSClient/AppDelegate.swift
@@ -49,9 +49,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var mainTabBar: NCMainTabBar?
var activeMetadata: tableMetadata?
- var listFilesVC: [String: NCFiles] = [:]
- var listFavoriteVC: [String: NCFavorite] = [:]
- var listOfflineVC: [String: NCOffline] = [:]
+ let listFilesVC = ThreadSafeDictionary<String,NCFiles>()
+ let listFavoriteVC = ThreadSafeDictionary<String,NCFavorite>()
+ let listOfflineVC = ThreadSafeDictionary<String,NCOffline>()
var disableSharesView: Bool = false
var documentPickerViewController: NCDocumentPickerViewController?
diff --git a/iOSClient/Data/NCDataSource.swift b/iOSClient/Data/NCDataSource.swift
index a1eda42c8..6922093a3 100644
--- a/iOSClient/Data/NCDataSource.swift
+++ b/iOSClient/Data/NCDataSource.swift
@@ -125,7 +125,7 @@ class NCDataSource: NSObject {
// Unified search
if let providers = self.providers, !providers.isEmpty {
- var sectionsDictionary: [String:Int] = [:]
+ let sectionsDictionary = ThreadSafeDictionary<String,Int>()
for section in self.sectionsValue {
if let provider = providers.filter({ $0.name.lowercased() == section.lowercased()}).first {
sectionsDictionary[section] = provider.order
@@ -434,7 +434,7 @@ class NCMetadataForSection: NSObject {
public var numDirectory: Int = 0
public var numFile: Int = 0
public var totalSize: Int64 = 0
- public var metadataShare: [String: tableShare] = [:]
+ public let metadataShare = ThreadSafeDictionary<String,tableShare>()
public var metadataOffLine: [String] = []
public var directories: [tableDirectory]?
diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift
index 589fda7a2..3ec6cad5d 100644
--- a/iOSClient/Data/NCManageDatabase+Metadata.swift
+++ b/iOSClient/Data/NCManageDatabase+Metadata.swift
@@ -132,7 +132,7 @@ extension NCManageDatabase {
var counter: Int = 0
var isEncrypted: Bool = false
- var listServerUrl: [String: Bool] = [:]
+ let listServerUrl = ThreadSafeDictionary<String,Bool>()
var metadataFolder = tableMetadata()
var metadataFolders: [tableMetadata] = []
diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift
index 9f13cc255..67d42110f 100644
--- a/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift
+++ b/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift
@@ -60,7 +60,7 @@ extension NCCreateFormUploadConflictDelegate {
var metadatasConflictNewFiles: [String] = []
var metadatasConflictAlreadyExistingFiles: [String] = []
- var fileNamesPath: [String: String] = [:]
+ let fileNamesPath = ThreadSafeDictionary<String,String>()
var blurView: UIVisualEffectView!
// MARK: - View Life Cycle
diff --git a/iOSClient/Main/NCMainTabBar.swift b/iOSClient/Main/NCMainTabBar.swift
index 604f3f6b3..ce3d0dd6c 100644
--- a/iOSClient/Main/NCMainTabBar.swift
+++ b/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
}
diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift
index acc60d2c9..bb1394aa1 100644
--- a/iOSClient/Networking/NCNetworking.swift
+++ b/iOSClient/Networking/NCNetworking.swift
@@ -45,9 +45,9 @@ import Photos
var lastReachability: Bool = true
var networkReachability: NCCommunicationCommon.typeReachability?
- var downloadRequest: [String: DownloadRequest] = [:]
- var uploadRequest: [String: UploadRequest] = [:]
- var uploadMetadataInBackground: [String: tableMetadata] = [:]
+ let downloadRequest = ThreadSafeDictionary<String,DownloadRequest>()
+ let uploadRequest = ThreadSafeDictionary<String,UploadRequest>()
+ let uploadMetadataInBackground = ThreadSafeDictionary<String,tableMetadata>()
@objc public let sessionMaximumConnectionsPerHost = 5
@objc public let sessionIdentifierBackground: String = "com.nextcloud.session.upload.background"
@@ -327,6 +327,7 @@ import Photos
NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, queue: NCCommunicationCommon.shared.backgroundQueue, requestHandler: { request in
self.downloadRequest[fileNameLocalPath] = request
+ self.downloadRequest.removeValue(forKey: fileNameLocalPath)
NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusDownloading)
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadStartFile, userInfo: ["ocId":metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
@@ -448,7 +449,7 @@ import Photos
}) { _, ocId, etag, date, size, _, _, errorCode, errorDescription in
- self.uploadRequest[fileNameLocalPath] = nil
+ self.uploadRequest.removeValue(forKey: fileNameLocalPath)
if let uploadTask = uploadTask {
self.uploadComplete(fileName: metadata.fileName, serverUrl: metadata.serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: uploadTask, errorCode: errorCode, errorDescription: errorDescription)
}
@@ -556,7 +557,7 @@ import Photos
}
}
- self.uploadMetadataInBackground[fileName + serverUrl] = nil
+ 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, errorCode: errorCode, errorDescription: errorDescription)
}
}
diff --git a/iOSClient/Networking/NCNetworkingChunkedUpload.swift b/iOSClient/Networking/NCNetworkingChunkedUpload.swift
index c9a1fef3a..6aa4627ba 100644
--- a/iOSClient/Networking/NCNetworkingChunkedUpload.swift
+++ b/iOSClient/Networking/NCNetworkingChunkedUpload.swift
@@ -112,7 +112,7 @@ extension NCNetworking {
}) { _, _, _, _, _, _, _, errorCode, errorDescription in
- self.uploadRequest[fileNameLocalPath] = nil
+ self.uploadRequest.removeValue(forKey: fileNameLocalPath)
uploadErrorCode = errorCode
uploadErrorDescription = errorDescription
semaphore.continue()
diff --git a/iOSClient/Networking/NCNetworkingE2EE.swift b/iOSClient/Networking/NCNetworkingE2EE.swift
index b8e86351b..60fe91f37 100644
--- a/iOSClient/Networking/NCNetworkingE2EE.swift
+++ b/iOSClient/Networking/NCNetworkingE2EE.swift
@@ -287,7 +287,7 @@ import Alamofire
}) { account, ocId, etag, date, _, _, error, errorCode, errorDescription in
- NCNetworking.shared.uploadRequest[fileNameLocalPath] = nil
+ NCNetworking.shared.uploadRequest.removeValue(forKey: fileNameLocalPath)
if let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) {
if error?.isExplicitlyCancelledError ?? false {
diff --git a/iOSClient/Networking/NCNetworkingProcessUpload.swift b/iOSClient/Networking/NCNetworkingProcessUpload.swift
index bf96a477d..07a757b68 100644
--- a/iOSClient/Networking/NCNetworkingProcessUpload.swift
+++ b/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 {
diff --git a/iOSClient/Utility/ThreadSafeDictionary.swift b/iOSClient/Utility/ThreadSafeDictionary.swift
new file mode 100644
index 000000000..c06e0c476
--- /dev/null
+++ b/iOSClient/Utility/ThreadSafeDictionary.swift
@@ -0,0 +1,65 @@
+//
+// ThreadSafeDictionary.swift
+//
+// Created by Shashank on 29/10/20.
+//
+
+class ThreadSafeDictionary<V: Hashable, T>: Collection {
+
+ private var dictionary: [V: T]
+ private let concurrentQueue = DispatchQueue(label: "Dictionary Barrier Queue", attributes: .concurrent)
+
+ var startIndex: Dictionary<V, T>.Index {
+ self.concurrentQueue.sync {
+ return self.dictionary.startIndex
+ }
+ }
+
+ var endIndex: Dictionary<V, T>.Index {
+ self.concurrentQueue.sync {
+ return self.dictionary.endIndex
+ }
+ }
+
+ init(dict: [V: T] = [V: T]()) {
+ self.dictionary = dict
+ }
+
+ func index(after i: Dictionary<V, T>.Index) -> Dictionary<V, T>.Index {
+ self.concurrentQueue.sync {
+ return self.dictionary.index(after: i)
+ }
+ }
+
+ subscript(key: V) -> T? {
+ get {
+ self.concurrentQueue.sync {
+ return self.dictionary[key]
+ }
+ }
+ set(newValue) {
+ self.concurrentQueue.async(flags: .barrier) {[weak self] in
+ self?.dictionary[key] = newValue
+ }
+ }
+ }
+
+ subscript(index: Dictionary<V, T>.Index) -> Dictionary<V, T>.Element {
+ self.concurrentQueue.sync {
+ return self.dictionary[index]
+ }
+ }
+
+ func removeValue(forKey key: V) {
+ self.concurrentQueue.async(flags: .barrier) {[weak self] in
+ self?.dictionary.removeValue(forKey: key)
+ }
+ }
+
+ func removeAll() {
+ self.concurrentQueue.async(flags: .barrier) {[weak self] in
+ self?.dictionary.removeAll()
+ }
+ }
+
+}