Browse Source

improvements

marinofaggiana 4 năm trước cách đây
mục cha
commit
99c09f4727

+ 1 - 1
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1053,7 +1053,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             if CCUtility.fileProviderStorageExists(metadataTouch.ocId, fileNameView: metadataTouch.fileNameView) {
                 NCViewer.shared.view(viewController: self, metadata: metadataTouch, metadatas: [metadataTouch])
             } else if NCCommunication.shared.isNetworkReachable() {
-                NCNetworking.shared.download(metadata: metadataTouch, selector: NCGlobal.shared.selectorLoadFileView) { (_) in }
+                NCNetworking.shared.download(metadata: metadataTouch, activityIndicator: false, selector: NCGlobal.shared.selectorLoadFileView) { (_) in }
             } else {
                 NCContentPresenter.shared.messageNotification("_info_", description: "_go_online_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.ErrorOffline, forced: true)
             }

+ 2 - 2
iOSClient/Main/NCFunctionCenter.swift

@@ -203,7 +203,7 @@ import NCCommunication
                                     
         } else {
             
-            NCNetworking.shared.download(metadata: metadata, selector: selector) { (_) in }
+            NCNetworking.shared.download(metadata: metadata, activityIndicator: true, selector: selector) { (_) in }
         }
     }
         
@@ -334,7 +334,7 @@ import NCCommunication
                     print("error")
                 }
             } else {
-                NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { (_) in }
+                NCNetworking.shared.download(metadata: metadata, activityIndicator: true, selector: NCGlobal.shared.selectorLoadCopy) { (_) in }
             }
         }
         

+ 2 - 2
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -138,9 +138,9 @@ extension NCCollectionViewCommon {
                                 NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: self.appDelegate.account)
                                 NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorDownloadAllFile)
                             } else {
-                                NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
+                                NCNetworking.shared.download(metadata: metadata, activityIndicator: false, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
                                 if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
-                                    NCNetworking.shared.download(metadata: metadataLivePhoto, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
+                                    NCNetworking.shared.download(metadata: metadataLivePhoto, activityIndicator: false, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
                                 }
                             }
                         }

+ 2 - 2
iOSClient/Menu/NCViewer+Menu.swift

@@ -94,7 +94,7 @@ extension NCViewer {
                     action: { menuAction in
                         if ((localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) && metadata.session == "") {
                             
-                            NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
+                            NCNetworking.shared.download(metadata: metadata, activityIndicator: true, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
                         } else {
                             NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
                         }
@@ -259,7 +259,7 @@ extension NCViewer {
                         title: NSLocalizedString("_download_image_max_", comment: ""),
                         icon: NCUtility.shared.loadImage(named: "square.and.arrow.down"),
                         action: { menuAction in
-                            NCNetworking.shared.download(metadata: metadata, selector: "") { (_) in }
+                            NCNetworking.shared.download(metadata: metadata, activityIndicator: false, selector: "") { (_) in }
                         }
                     )
                 )

+ 10 - 2
iOSClient/Networking/NCNetworking.swift

@@ -267,7 +267,7 @@ import Queuer
         }
     }
     
-    @objc func download(metadata: tableMetadata, selector: String, completion: @escaping (_ errorCode: Int)->()) {
+    @objc func download(metadata: tableMetadata, activityIndicator: Bool, selector: String, completion: @escaping (_ errorCode: Int)->()) {
         
         let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
         let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)!
@@ -280,6 +280,10 @@ import Queuer
                 
         NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: NCCommunicationCommon.shared.sessionIdentifierDownload, sessionError: "", sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusInDownload)
                     
+        if activityIndicator {
+            NCUtility.shared.startActivityIndicator(view: nil)
+        }
+        
         NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { (request) in
             
             self.downloadRequest[fileNameLocalPath] = request
@@ -294,7 +298,11 @@ import Queuer
             NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterProgressTask, object: nil, userInfo: ["account":metadata.account, "ocId":metadata.ocId, "serverUrl":metadata.serverUrl, "status":NSNumber(value: NCGlobal.shared.metadataStatusInDownload), "progress":NSNumber(value: progress.fractionCompleted), "totalBytes":NSNumber(value: progress.totalUnitCount), "totalBytesExpected":NSNumber(value: progress.completedUnitCount)])
             
         }) { (account, etag, date, length, allHeaderFields, error, errorCode, errorDescription) in
-                       
+              
+            if activityIndicator {
+                NCUtility.shared.stopActivityIndicator()
+            }
+            
             if error?.isExplicitlyCancelledError ?? false {
                             
                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: "", sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusNormal)

+ 1 - 1
iOSClient/Networking/NCOperationQueue.swift

@@ -163,7 +163,7 @@ class NCOperationDownload: ConcurrentOperation {
         if isCancelled {
             self.finish()
         } else {
-            NCNetworking.shared.download(metadata: metadata, selector: self.selector) { (_) in
+            NCNetworking.shared.download(metadata: metadata, activityIndicator: false, selector: self.selector) { (_) in
                 self.finish()
             }
         }

+ 44 - 42
iOSClient/Utility/NCUtility.swift

@@ -194,48 +194,6 @@ class NCUtility: NSObject {
         }
     }
     
-    @objc func startActivityIndicator(view: UIView?, bottom: CGFloat = 0) {
-            
-        activityIndicator.color = NCBrandColor.shared.brand
-        activityIndicator.hidesWhenStopped = true
-        activityIndicator.translatesAutoresizingMaskIntoConstraints = false
-
-        if view == nil {
-            if let window = UIApplication.shared.keyWindow {
-                viewActivityIndicator?.removeFromSuperview()
-                viewActivityIndicator = NCViewActivityIndicator(frame: window.bounds)
-                window.addSubview(viewActivityIndicator!)
-                viewActivityIndicator?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
-            }
-        } else {
-            viewActivityIndicator = view
-        }
-        
-        guard let view = viewActivityIndicator else { return }
-        view.addSubview(activityIndicator)
-            
-        let horizontalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0)
-        view.addConstraint(horizontalConstraint)
-        
-        var verticalConstant: CGFloat = 0
-        if bottom > 0 {
-            verticalConstant = (view.frame.size.height / 2) - bottom
-        }
-        
-        let verticalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: verticalConstant)
-        view.addConstraint(verticalConstraint)
-
-        activityIndicator.startAnimating()
-    }
-    
-    @objc func stopActivityIndicator() {
-        activityIndicator.stopAnimating()
-        activityIndicator.removeFromSuperview()
-        if viewActivityIndicator is NCViewActivityIndicator {
-            viewActivityIndicator?.removeFromSuperview()
-        }
-    }
-    
     @objc func isSimulatorOrTestFlight() -> Bool {
         guard let path = Bundle.main.appStoreReceiptURL?.path else {
             return false
@@ -494,6 +452,50 @@ class NCUtility: NSObject {
         
         return  UIImage(named: "file")!.image(color: color, size: size)
     }
+    
+    // MARK: -
+
+    @objc func startActivityIndicator(view: UIView?, bottom: CGFloat = 0) {
+            
+        activityIndicator.color = NCBrandColor.shared.brand
+        activityIndicator.hidesWhenStopped = true
+        activityIndicator.translatesAutoresizingMaskIntoConstraints = false
+
+        if view == nil {
+            if let window = UIApplication.shared.keyWindow {
+                viewActivityIndicator?.removeFromSuperview()
+                viewActivityIndicator = NCViewActivityIndicator(frame: window.bounds)
+                window.addSubview(viewActivityIndicator!)
+                viewActivityIndicator?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+            }
+        } else {
+            viewActivityIndicator = view
+        }
+        
+        guard let view = viewActivityIndicator else { return }
+        view.addSubview(activityIndicator)
+            
+        let horizontalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0)
+        view.addConstraint(horizontalConstraint)
+        
+        var verticalConstant: CGFloat = 0
+        if bottom > 0 {
+            verticalConstant = (view.frame.size.height / 2) - bottom
+        }
+        
+        let verticalConstraint = NSLayoutConstraint(item: activityIndicator, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: verticalConstant)
+        view.addConstraint(verticalConstraint)
+
+        activityIndicator.startAnimating()
+    }
+    
+    @objc func stopActivityIndicator() {
+        activityIndicator.stopAnimating()
+        activityIndicator.removeFromSuperview()
+        if viewActivityIndicator is NCViewActivityIndicator {
+            viewActivityIndicator?.removeFromSuperview()
+        }
+    }
 }
 
 // MARK: -