marinofaggiana vor 4 Jahren
Ursprung
Commit
11bdde17b0

+ 1 - 1
Cartfile.resolved

@@ -20,7 +20,7 @@ github "marinofaggiana/AFNetworking" "2967678c3e0e98c9b8d7e06222ad12d1f49c26f2"
 github "marinofaggiana/KTVHTTPCache" "2.0.2"
 github "marinofaggiana/TOPasscodeViewController" "0.0.6"
 github "marinofaggiana/XLForm" "eb9381ad8129f60402bf412250fb31b95a628a08"
-github "nextcloud/ios-communication-library" "9005d3976c7695de9fc41443689d4c4ad62e9ab0"
+github "nextcloud/ios-communication-library" "ba2740bc85012f5f47b78f4a5ea1de5e6e14d7c6"
 github "realm/realm-cocoa" "v4.4.1"
 github "rechsteiner/Parchment" "v1.7.0"
 github "scenee/FloatingPanel" "v1.7.4"

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -132,6 +132,7 @@
 		F723B3DD22FC6D1D00301EFE /* NCShareCommentsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F723B3DC22FC6D1C00301EFE /* NCShareCommentsCell.xib */; };
 		F7267A82225DFCE100D6DB7D /* AFNetworking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7267A81225DFCE100D6DB7D /* AFNetworking.framework */; };
 		F726EEEC1FED1C820030B9C8 /* NCEndToEndInitialize.swift in Sources */ = {isa = PBXBuildFile; fileRef = F726EEEB1FED1C820030B9C8 /* NCEndToEndInitialize.swift */; };
+		F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */; };
 		F72D1007210B6882009C96B7 /* NCPushNotificationEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F72D1005210B6882009C96B7 /* NCPushNotificationEncryption.m */; };
 		F72D404923D2082500A97FD0 /* NCViewerNextcloudText.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72D404823D2082500A97FD0 /* NCViewerNextcloudText.swift */; };
 		F72E0B9D21AD60BC00898D7B /* WeScan.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F72E0B9C21AD60BC00898D7B /* WeScan.framework */; };
@@ -537,6 +538,7 @@
 		F728B2BB23E83AD200E12DA0 /* Notification_Service_Extension.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Notification_Service_Extension.plist; sourceTree = "<group>"; };
 		F728B2BC23E83AD200E12DA0 /* Notification_Service_Extension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Notification_Service_Extension.entitlements; sourceTree = "<group>"; };
 		F7296A661C8880ED001A7809 /* CCloadItemData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CCloadItemData.swift; sourceTree = "<group>"; };
+		F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCOperationQueue.swift; sourceTree = "<group>"; };
 		F72D1005210B6882009C96B7 /* NCPushNotificationEncryption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCPushNotificationEncryption.m; sourceTree = "<group>"; };
 		F72D1006210B6882009C96B7 /* NCPushNotificationEncryption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCPushNotificationEncryption.h; sourceTree = "<group>"; };
 		F72D404823D2082500A97FD0 /* NCViewerNextcloudText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerNextcloudText.swift; sourceTree = "<group>"; };
@@ -1163,6 +1165,7 @@
 			isa = PBXGroup;
 			children = (
 				F755BD9A20594AC7008C5FBB /* NCService.swift */,
+				F72A47EB2487B06B005AD489 /* NCOperationQueue.swift */,
 				F75A9EE523796C6F0044CFCE /* NCNetworking.swift */,
 				F7D96FCB246ED7E100536D73 /* NCNetworkingCheckRemoteUser.swift */,
 				F785EE9C246196DF00B3F945 /* NCNetworkingE2EE.swift */,
@@ -2260,6 +2263,7 @@
 				F77444F8222816D5000D5EB0 /* NCPhotosPickerViewController.swift in Sources */,
 				F711CCDE246AC99E0009B204 /* NCComments.m in Sources */,
 				F77B0E141D118A16002130FE /* CCError.m in Sources */,
+				F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
 				F7E09CE523E3088C00FB3E9E /* NCSplitViewController.swift in Sources */,
 				F710D1F724057C9400A6033D /* NCDetailNavigationController.swift in Sources */,
 				F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,

+ 1 - 1
iOSClient/Favorites/CCFavorites.m

@@ -647,7 +647,7 @@
                         [self shouldPerformSegue:self.metadata selector:selectorLoadFileView];
                     }
                     
-                    [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadFileViewFavorite setFavorite:false];
+                    [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadFileViewFavorite setFavorite:false completion:^(NSInteger errorCode) { }];
                 }
             }
         }

+ 5 - 5
iOSClient/Main/CCMain.m

@@ -535,7 +535,7 @@
                    
         if (!metadata.directory && favorite && [CCUtility getFavoriteOffline]) {
                    
-            [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorDownloadSynchronize setFavorite:true];
+            [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorDownloadSynchronize setFavorite:true completion:^(NSInteger errorCode) { }];
         }
     } else {
         [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
@@ -924,7 +924,7 @@
             
             if (metadata.directory == NO && ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])) {
                 
-                [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorSave setFavorite:false];
+                [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorSave setFavorite:false completion:^(NSInteger errorCode) { }];
             }
         }
         
@@ -1920,7 +1920,7 @@
         
     } else {
         
-        [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadCopy setFavorite:false];
+        [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadCopy setFavorite:false completion:^(NSInteger errorCode) { }];
     }
 }
 
@@ -1940,7 +1940,7 @@
             
         } else {
 
-            [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorLoadCopy setFavorite:false];
+            [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorLoadCopy setFavorite:false completion:^(NSInteger errorCode) { }];
         }
     }
     
@@ -2717,7 +2717,7 @@
                         [self shouldPerformSegue:self.metadata selector:selectorLoadFileView];
                     }
                    
-                    [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadFileView setFavorite:false];
+                    [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadFileView setFavorite:false completion:^(NSInteger errorCode) { }];
                 }
             }
         }

+ 2 - 2
iOSClient/Main/Menu/CCMain+Menu.swift

@@ -486,10 +486,10 @@ extension CCMain {
                         action: { menuAction in
                             if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
                                 
-                                NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline)
+                                NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline) { (_) in }
                                 
                                 if let metadataLivePhoto = NCUtility.sharedInstance.isLivePhoto(metadata: metadata) {
-                                    NCNetworking.shared.download(metadata: metadataLivePhoto, selector: selectorLoadOffline)
+                                    NCNetworking.shared.download(metadata: metadataLivePhoto, selector: selectorLoadOffline) { (_) in }
                                 }
                                 
                             } else {

+ 1 - 2
iOSClient/Main/Menu/NCDetailNavigationController+Menu.swift

@@ -144,8 +144,7 @@ extension NCDetailNavigationController {
                     action: { menuAction in
                         if ((localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) && metadata.session == "") {
                             
-                            NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline)
-                            
+                            NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline) { (_) in }
                         } else {
                             NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
                             NotificationCenter.default.post(name: Notification.Name.init(rawValue:

+ 2 - 2
iOSClient/Main/NCDetailViewController.swift

@@ -369,7 +369,7 @@ class NCDetailViewController: UIViewController {
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata {
 
-                NCNetworking.shared.download(metadata: metadata, selector: "")
+                NCNetworking.shared.download(metadata: metadata, selector: "") { (_) in }
 
                 if let index = metadatas.firstIndex(where: { $0.ocId == metadata.ocId }) {
                     metadatas[index] = self.metadata!
@@ -679,7 +679,7 @@ extension NCDetailViewController: NCViewerImageViewControllerDelegate, NCViewerI
             
             if NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@ AND session != ''", metadata.ocId)) == nil {
                 
-                NCNetworking.shared.download(metadata: metadata, selector: "")
+                NCNetworking.shared.download(metadata: metadata, selector: "") { (_) in }
             }
             
             completion(index, NCViewerImageCommon.shared.getImageOffOutline(frame: self.view.frame, type: metadata.typeFile), metadata, ZoomScale.default, nil)

+ 1 - 1
iOSClient/Main/NCMainCommon.swift

@@ -850,7 +850,7 @@ class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentI
                                     
         } else {
             
-            NCNetworking.shared.download(metadata: metadata, selector: selector)
+            NCNetworking.shared.download(metadata: metadata, selector: selector) { (_) in }
         }
     }
 

+ 4 - 1
iOSClient/Networking/NCNetworking.swift

@@ -40,6 +40,7 @@ import Alamofire
     }()
         
     var delegate: NCNetworkingDelegate?
+    
     var lastReachability: Bool = true
     var downloadRequest = [String:DownloadRequest]()
     var uploadRequest = [String:UploadRequest]()
@@ -207,7 +208,7 @@ import Alamofire
         }
     }
     
-    @objc func download(metadata: tableMetadata, selector: String, setFavorite: Bool = false) {
+    @objc func download(metadata: tableMetadata, selector: String, setFavorite: Bool = false, completion: @escaping (_ errorCode: Int)->()) {
         
         var metadata = metadata
         let serverUrl = metadata.serverUrl
@@ -286,6 +287,8 @@ import Alamofire
                 
                 NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_downloadedFile), object: nil, userInfo: ["metadata":metadata, "selector":selector, "errorCode":errorCode, "errorDescription":errorDescription])
             }
+            
+            completion(errorCode)
         }
     }
     

+ 58 - 0
iOSClient/Networking/NCOperationQueue.swift

@@ -0,0 +1,58 @@
+//
+//  NCOperationQueue.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 03/06/2020.
+//  Copyright © 2020 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+
+import Foundation
+import Queuer
+
+@objc class NCOperationQueue: ConcurrentOperation {
+    @objc public static let shared: NCOperationQueue = {
+        let instance = NCOperationQueue()
+        return instance
+    }()
+    
+    let transferQueue = Queuer(name: "transferQueue", maxConcurrentOperationCount: 5, qualityOfService: .default)
+
+    
+    @objc func download(metadata: tableMetadata, selector: String, setFavorite: Bool = false) {
+        let concurrentOperation = ConcurrentOperation { _ in
+            
+            NCNetworking.shared.download(metadata: metadata, selector: selector, setFavorite: setFavorite) { (errorCode) in
+                
+            }
+            
+            
+        }
+        concurrentOperation.addToQueue(transferQueue)
+    }
+    
+    override func execute() {
+        
+    }
+    
+    override func finish(success: Bool = true) {
+        
+    }
+    
+   
+}

+ 3 - 2
iOSClient/Synchronize/CCSynchronize.m

@@ -300,8 +300,9 @@
             [serverUrlToReload addObject:metadata.serverUrl];
             [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:metadata.serverUrl account:metadata.account];
         }
-        
-        [[NCNetworking shared] downloadWithMetadata:metadata selector:selectorDownloadSynchronize setFavorite:false];
+
+        [[NCOperationQueue shared] downloadWithMetadata:metadata selector:selectorDownloadSynchronize setFavorite:false];
+        //[[NCNetworking shared] downloadWithMetadata:metadata selector:selectorDownloadSynchronize setFavorite:false];
     }
         
     for (NSString *serverUrl in serverUrlToReload) {