Преглед на файлове

fix image view

Signed-off-by: marinofaggiana <marino@marinofaggiana.com>
marinofaggiana преди 3 години
родител
ревизия
1f1a177cf9
променени са 2 файла, в които са добавени 31 реда и са изтрити 67 реда
  1. 0 46
      iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift
  2. 31 21
      iOSClient/Viewer/NCViewerMedia/NCViewerMediaZoom.swift

+ 0 - 46
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -101,11 +101,8 @@ class NCViewerMedia: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
 
         NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object:nil)
         
-        NotificationCenter.default.addObserver(self, selector: #selector(downloadedThumbnail(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedThumbnail), object: nil)
-        
         NotificationCenter.default.addObserver(self, selector: #selector(hidePlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(showPlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
         
@@ -132,11 +129,8 @@ class NCViewerMedia: UIViewController {
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
 
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
         
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedThumbnail), object: nil)
-        
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
         
@@ -219,46 +213,6 @@ class NCViewerMedia: UIViewController {
     @objc func downloadedFile(_ notification: NSNotification) {
         
         progressView.progress = 0
-
-        if let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId), let errorCode = userInfo["errorCode"] as? Int {
-          
-            if errorCode == 0, let viewControllers = self.pageViewController.viewControllers, let image = getImageMetadata(metadata) {
-                for viewController in viewControllers {
-                    let viewerMediaZoom = viewController as! NCViewerMediaZoom
-                    if viewerMediaZoom.metadata.ocId == ocId {
-                        viewerMediaZoom.reload(image: image)
-                        break
-                    }
-                }
-            }
-        }
-    }
-    
-    @objc func downloadedThumbnail(_ notification: NSNotification) {
-        
-        if let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-            
-            if let viewControllers = self.pageViewController.viewControllers, let image = getImageMetadata(metadata) {
-                for viewController in viewControllers {
-                    let viewerMediaZoom = viewController as! NCViewerMediaZoom
-                    if viewerMediaZoom.metadata.ocId == ocId {
-                        viewerMediaZoom.reload(image: image)
-                        break
-                    }
-                }
-            }
-        }
-    }
-    
-    @objc func uploadedFile(_ notification: NSNotification) {
-        
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId), let errorCode = userInfo["errorCode"] as? Int {
-                if errorCode == 0  && metadata.ocId == currentViewController.metadata.ocId {
-                    //self.reloadCurrentPage()
-                }
-            }
-        }
     }
     
     @objc func triggerProgressTask(_ notification: NSNotification) {

+ 31 - 21
iOSClient/Viewer/NCViewerMedia/NCViewerMediaZoom.swift

@@ -173,7 +173,8 @@ class NCViewerMediaZoom: UIViewController {
         } else if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
             
             if let image = viewerMedia?.getImageMetadata(metadata) {
-                reload(image: image)
+                self.image = image
+                self.imageVideoContainer.image = image
             }
             viewerMedia?.clearCommandCenter()
         }
@@ -200,12 +201,6 @@ class NCViewerMediaZoom: UIViewController {
         }) { (_) in }
     }
     
-    func reload(image: UIImage) {
-        
-        self.image = image
-        imageVideoContainer.image = image
-    }
-        
     //MARK: - Gesture
 
     @objc func didDoubleTapWith(gestureRecognizer: UITapGestureRecognizer) {
@@ -365,27 +360,42 @@ extension NCViewerMediaZoom {
         
         let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
         let ext = CCUtility.getExtension(metadata.fileNameView)
+        var etagResource: String?
         
-        if !NCOperationQueue.shared.downloadExists(metadata: metadata) {
-            viewerMedia?.progressView.progress = 0
+        // DOWNLOAD preview for image
+        if !CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) && metadata.hasPreview && metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
+            
+            let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, account: metadata.account)!
+            let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
+            let fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
+            if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) {
+                etagResource = metadata.etagResource
+            }
+            
+            NCCommunication.shared.downloadPreview(fileNamePathOrFileId: fileNamePath, fileNamePreviewLocalPath: fileNamePreviewLocalPath , widthPreview: NCGlobal.shared.sizePreview, heightPreview: NCGlobal.shared.sizePreview, fileNameIconLocalPath: fileNameIconLocalPath, sizeIcon: NCGlobal.shared.sizeIcon, etag: etagResource, queue: NCCommunicationCommon.shared.backgroundQueue) { (account, imagePreview, imageIcon, imageOriginal, etag, errorCode, errorDescription) in
+                
+                if errorCode == 0, let image = self.viewerMedia?.getImageMetadata(self.metadata) {
+                    DispatchQueue.main.async {
+                        self.image = image
+                        self.imageVideoContainer.image = image
+                    }
+                }
+            }
         }
         
         // DOWNLOAD FILE
         if ((metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && CCUtility.getAutomaticDownloadImage()) || (metadata.contentType == "image/heic" &&  metadata.hasPreview == false) || ext == "GIF" || ext == "SVG" || isFolderEncrypted) && metadata.session == "" && !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            NCOperationQueue.shared.download(metadata: metadata, selector: "")
-        }
-        
-        // DOWNLOAD FILE LIVE PHOTO
-        if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
-            if CCUtility.getAutomaticDownloadImage() && !CCUtility.fileProviderStorageExists(metadataLivePhoto.ocId, fileNameView: metadataLivePhoto.fileNameView) {
-                NCOperationQueue.shared.download(metadata: metadataLivePhoto, selector: "")
+            
+            NCNetworking.shared.download(metadata: metadata, selector: "") { (errorCode) in
+                
+                if errorCode == 0, let image = self.viewerMedia?.getImageMetadata(self.metadata) {
+                    DispatchQueue.main.async {
+                        self.image = image
+                        self.imageVideoContainer.image = image
+                    }
+                }
             }
         }
-        
-        // DOWNLOAD preview for image
-        if !CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) && metadata.hasPreview && metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
-            NCOperationQueue.shared.downloadThumbnail(metadata: metadata, placeholder: false, cell: nil, view: nil)
-        }
     }
 }