marinofaggiana 4 ani în urmă
părinte
comite
225f497154

+ 2 - 2
iOSClient/Favorites/NCFavorite.swift

@@ -82,7 +82,7 @@ class NCFavorite: NCCollectionViewCommon  {
                         if !metadata.directory && CCUtility.getFavoriteOffline() {
                             let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                             if localFile == nil || localFile?.etag != metadata.etag {
-                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false, forceDownload: true)
+                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
                             }
                         }
                     }
@@ -103,7 +103,7 @@ class NCFavorite: NCCollectionViewCommon  {
                         if !metadata.directory {
                             let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                             if (CCUtility.getFavoriteOffline() && localFile == nil) || (localFile != nil && localFile?.etag != metadata.etag) {
-                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false, forceDownload: true)
+                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
                             }
                         }
                     }

+ 1 - 1
iOSClient/FileViewInFolder/NCFileViewInFolder.swift

@@ -133,7 +133,7 @@ class NCFileViewInFolder: NCCollectionViewCommon  {
                     if !metadata.directory {
                         let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                         if (CCUtility.getFavoriteOffline() && localFile == nil) || (localFile != nil && localFile?.etag != metadata.etag) {
-                            NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false, forceDownload: true)
+                            NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
                         }
                     }
                 }

+ 1 - 1
iOSClient/Files/NCFiles.swift

@@ -101,7 +101,7 @@ class NCFiles: NCCollectionViewCommon  {
                     if !metadata.directory {
                         let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                         if (CCUtility.getFavoriteOffline() && localFile == nil) || (localFile != nil && localFile?.etag != metadata.etag) {
-                            NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false, forceDownload: true)
+                            NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
                         }
                     }
                 }

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

@@ -382,8 +382,8 @@ extension NCCollectionViewCommon {
                 action: { menuAction in
                     for ocId in selectOcId {
                         if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                            if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video {
-                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorSaveAlbum, setFavorite: false, forceDownload: false)
+                            if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video && !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorSaveAlbum, setFavorite: false)
                             }
                         }
                     }

+ 4 - 8
iOSClient/Networking/NCOperationQueue.swift

@@ -50,11 +50,7 @@ import NCCommunication
     
     // Download file
     
-    @objc func download(metadata: tableMetadata, selector: String, setFavorite: Bool, forceDownload: Bool) {
-        if !forceDownload && CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView) > 0 {
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["metadata":metadata, "selector":selector, "errorCode":0, "errorDescription":""])
-            return
-        }
+    @objc func download(metadata: tableMetadata, selector: String, setFavorite: Bool) {
         for operation in downloadQueue.operations as! [NCOperationDownload]  {
             if operation.metadata.ocId == metadata.ocId {
                 return
@@ -285,7 +281,7 @@ class NCOperationSynchronization: ConcurrentOperation {
                                     } else {
                                         let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                                         if localFile == nil || localFile?.etag != metadata.etag {
-                                            NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false, forceDownload: true)
+                                            NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
                                         }
                                     }
                                 }
@@ -301,7 +297,7 @@ class NCOperationSynchronization: ConcurrentOperation {
                                 }
                                 
                                 for metadata in metadatasChanged.metadatasLocalUpdate {
-                                    NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false, forceDownload: true)
+                                    NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
                                 }
                             }
                             // Update etag directory
@@ -317,7 +313,7 @@ class NCOperationSynchronization: ConcurrentOperation {
                 if self.download {
                     let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                     if localFile == nil || localFile?.etag != metadata.etag {
-                        NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false, forceDownload: true)
+                        NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
                     }
                 }
                 self.finish()

+ 1 - 1
iOSClient/Offline/NCOffline.swift

@@ -102,7 +102,7 @@ class NCOffline: NCCollectionViewCommon  {
                         if !metadata.directory {
                             let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                             if localFile == nil || localFile?.etag != metadata.etag {
-                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false, forceDownload: true)
+                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
                             }
                         }
                     }

+ 18 - 5
iOSClient/Viewer/NCViewerImage/NCViewerImagePageContainer.swift

@@ -129,8 +129,7 @@ class NCViewerImagePageContainer: UIViewController, UIGestureRecognizerDelegate
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
                 if metadata.ocId == currentViewerImageZoom?.metadata.ocId && errorCode == 0 {
-                    let image = getImageMetadata(metadata)
-                    currentViewerImageZoom?.updateImage(image)
+                    self.reloadCurrentPage()
                 }
                 if self.metadatas.first(where: { $0.ocId == metadata.ocId }) != nil {
                     progressView.progress = 0
@@ -402,8 +401,8 @@ class NCViewerImagePageContainer: UIViewController, UIGestureRecognizerDelegate
         let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
         let ext = CCUtility.getExtension(metadata.fileNameView)
         
-        if ((metadata.contentType == "image/heic" &&  metadata.hasPreview == false) || ext == "GIF" || ext == "SVG" || isFolderEncrypted) && metadata.session == "" {
-            NCOperationQueue.shared.download(metadata: metadata, selector: "", setFavorite: false, forceDownload: false)
+        if ((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: "", setFavorite: false)
         }
         
         if !CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) && metadata.hasPreview {
@@ -414,7 +413,7 @@ class NCViewerImagePageContainer: UIViewController, UIGestureRecognizerDelegate
             
             NCCommunication.shared.downloadPreview(fileNamePathOrFileId: fileNamePath, fileNamePreviewLocalPath: fileNamePreviewLocalPath, widthPreview: Int(k_sizePreview), heightPreview: Int(k_sizePreview), fileNameIconLocalPath: fileNameIconLocalPath, sizeIcon: Int(k_sizeIcon)) { (account, imagePreview, imageIcon,  errorCode, errorMessage) in
                 if errorCode == 0 {
-                    viewerImageZoom.updateImage(imagePreview)
+                    self.reloadCurrentPage()
                 }
             }
         }
@@ -603,6 +602,20 @@ extension NCViewerImagePageContainer: UIPageViewControllerDelegate, UIPageViewCo
         return true
     }
     
+    func reloadCurrentPage() {
+        
+        let viewerImageZoom = UIStoryboard(name: "NCViewerImage", bundle: nil).instantiateViewController(withIdentifier: "NCViewerImageZoom") as! NCViewerImageZoom
+        
+        viewerImageZoom.index = currentIndex
+        viewerImageZoom.image = getImageMetadata(metadatas[currentIndex])
+        viewerImageZoom.metadata = metadatas[currentIndex]
+        viewerImageZoom.delegate = self
+        
+        singleTapGestureRecognizer.require(toFail: viewerImageZoom.doubleTapGestureRecognizer)
+        
+        pageViewController.setViewControllers([viewerImageZoom], direction: .forward, animated: false, completion: nil)
+    }
+    
     func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
         if currentIndex == 0 { return nil }
         

+ 0 - 16
iOSClient/Viewer/NCViewerImage/NCViewerImageZoom.swift

@@ -147,22 +147,6 @@ class NCViewerImageZoom: UIViewController {
         let contentHeight = yOffset * 2 + imageView.frame.height
         scrollView.contentSize = CGSize(width: scrollView.contentSize.width, height: contentHeight)
     }
-    
-    func updateImage(_ image: UIImage?) {
-        guard let image = image else { return }
-        
-        self.image = image
-        imageView.image = image
-        
-        // horrible but works very good
-        if delegate?.navigationController?.navigationBar.isHidden ?? false {
-            delegate?.navigationController?.setNavigationBarHidden(false, animated: false)
-            delegate?.navigationController?.setNavigationBarHidden(true, animated: false)
-        } else {
-            delegate?.navigationController?.setNavigationBarHidden(true, animated: false)
-            delegate?.navigationController?.setNavigationBarHidden(false, animated: false)
-        }
-    }
 }
 
 extension NCViewerImageZoom: UIScrollViewDelegate {