ソースを参照

cleaning

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 年間 前
コミット
a6c9c20af0

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

@@ -1208,8 +1208,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                         (cell as? NCCellProtocol)?.filePreviewImageView?.image = UIImage(named: metadata.iconName)
                     }
                     if metadata.hasPreview && metadata.status == NCGlobal.shared.metadataStatusNormal && (!CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag)) {
-                        for case let operation as NCCollecionViewCommonDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
-                        appDelegate.downloadThumbnailQueue.addOperation(NCCollecionViewCommonDownloadThumbnail(metadata: metadata, cell: (cell as? NCCellProtocol), view: view, forItemAt: indexPath))
+                        for case let operation as NCCollectionViewDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
+                        appDelegate.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, cell: (cell as? NCCellProtocol), view: view))
                     }
                 }
             } else {
@@ -1257,7 +1257,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
         if !collectionView.indexPathsForVisibleItems.contains(indexPath) {
             guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
-            for case let operation as NCCollecionViewCommonDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
+            for case let operation as NCCollectionViewDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
                 operation.cancel()
             }
         }
@@ -1706,7 +1706,7 @@ extension NCCollectionViewCommon: EasyTipViewDelegate {
     }
 }
 
-class NCCollecionViewCommonDownloadThumbnail: ConcurrentOperation {
+class NCCollectionViewDownloadThumbnail: ConcurrentOperation {
 
     var metadata: tableMetadata
         var cell: NCCellProtocol?
@@ -1715,7 +1715,7 @@ class NCCollecionViewCommonDownloadThumbnail: ConcurrentOperation {
         var fileNamePreviewLocalPath: String
         var fileNameIconLocalPath: String
 
-    init(metadata: tableMetadata, cell: NCCellProtocol?, view: UIView?, forItemAt indexPath: IndexPath) {
+    init(metadata: tableMetadata, cell: NCCellProtocol?, view: UIView?) {
         self.metadata = tableMetadata.init(value: metadata)
         self.cell = cell
         self.view = view

+ 61 - 3
iOSClient/Media/NCMedia.swift

@@ -24,6 +24,7 @@
 import UIKit
 import NextcloudKit
 import JGProgressHUD
+import Queuer
 
 class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
 
@@ -381,8 +382,8 @@ extension NCMedia: UICollectionViewDataSource {
             }
         } else {
             if metadata.hasPreview && metadata.status == NCGlobal.shared.metadataStatusNormal && (!CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag)) {
-                for case let operation as NCOperationDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
-                appDelegate.downloadThumbnailQueue.addOperation(NCOperationDownloadThumbnail(metadata: metadata, cell: cell, view: view))
+                for case let operation as NCMediaDownloadThumbnaill in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
+                appDelegate.downloadThumbnailQueue.addOperation(NCMediaDownloadThumbnaill(metadata: metadata, cell: cell, view: view))
             }
         }
     }
@@ -390,7 +391,7 @@ extension NCMedia: UICollectionViewDataSource {
     func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
         if !collectionView.indexPathsForVisibleItems.contains(indexPath) && indexPath.row < metadatas.count {
             let metadata = metadatas[indexPath.row]
-            for case let operation as NCOperationDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
+            for case let operation as NCMediaDownloadThumbnaill in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
                 operation.cancel()
             }
         }
@@ -853,3 +854,60 @@ class NCGridMediaLayout: UICollectionViewFlowLayout {
         return proposedContentOffset
     }
 }
+
+// MARK: -
+
+class NCMediaDownloadThumbnaill: ConcurrentOperation {
+
+    var metadata: tableMetadata
+    var cell: NCCellProtocol?
+    var view: UIView?
+    var fileNamePath: String
+    var fileNamePreviewLocalPath: String
+    var fileNameIconLocalPath: String
+
+    init(metadata: tableMetadata, cell: NCCellProtocol?, view: UIView?) {
+        self.metadata = tableMetadata.init(value: metadata)
+        self.cell = cell
+        self.view = view
+        self.fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId, account: metadata.account)!
+        self.fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
+        self.fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
+    }
+
+    override func start() {
+
+        guard !isCancelled else { return self.finish() }
+
+        var etagResource: String?
+        if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) {
+            etagResource = metadata.etagResource
+        }
+
+        NextcloudKit.shared.downloadPreview(
+            fileNamePathOrFileId: fileNamePath,
+            fileNamePreviewLocalPath: fileNamePreviewLocalPath,
+            widthPreview: NCGlobal.shared.sizePreview,
+            heightPreview: NCGlobal.shared.sizePreview,
+            fileNameIconLocalPath: fileNameIconLocalPath,
+            sizeIcon: NCGlobal.shared.sizeIcon,
+            etag: etagResource,
+            options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, etag, error in
+
+            if error == .success, let image = imagePreview {
+                NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag)
+                DispatchQueue.main.async {
+                    if self.metadata.ocId == self.cell?.fileObjectId, let filePreviewImageView = self.cell?.filePreviewImageView {
+                        UIView.transition(with: filePreviewImageView,
+                                          duration: 0.75,
+                                          options: .transitionCrossDissolve,
+                                          animations: { filePreviewImageView.image = image },
+                                          completion: nil)
+                    }
+                }
+                NCMediaCache.shared.setImage(ocId: self.metadata.ocId, image: image)
+            }
+            self.finish()
+        }
+    }
+}

+ 0 - 62
iOSClient/Networking/NCOperationQueue.swift

@@ -119,68 +119,6 @@ class NCOperationDownload: ConcurrentOperation {
 
 // MARK: -
 
-class NCOperationDownloadThumbnail: ConcurrentOperation {
-
-    var metadata: tableMetadata
-    var cell: NCCellProtocol?
-    var view: UIView?
-    var fileNamePath: String
-    var fileNamePreviewLocalPath: String
-    var fileNameIconLocalPath: String
-
-    init(metadata: tableMetadata, cell: NCCellProtocol?, view: UIView?) {
-        self.metadata = tableMetadata.init(value: metadata)
-        self.cell = cell
-        self.view = view
-        self.fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId, account: metadata.account)!
-        self.fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
-        self.fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
-    }
-
-    override func start() {
-
-        guard !isCancelled else { return self.finish() }
-
-        var etagResource: String?
-        if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) {
-            etagResource = metadata.etagResource
-        }
-
-        NextcloudKit.shared.downloadPreview(
-            fileNamePathOrFileId: fileNamePath,
-            fileNamePreviewLocalPath: fileNamePreviewLocalPath,
-            widthPreview: NCGlobal.shared.sizePreview,
-            heightPreview: NCGlobal.shared.sizePreview,
-            fileNameIconLocalPath: fileNameIconLocalPath,
-            sizeIcon: NCGlobal.shared.sizeIcon,
-            etag: etagResource,
-            options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, etag, error in
-
-            if error == .success, let image = imagePreview  {
-                NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag)
-                DispatchQueue.main.async {
-                    if self.metadata.ocId == self.cell?.fileObjectId, let filePreviewImageView = self.cell?.filePreviewImageView {
-                        UIView.transition(with: filePreviewImageView,
-                                          duration: 0.75,
-                                          options: .transitionCrossDissolve,
-                                          animations: { filePreviewImageView.image = image },
-                                          completion: nil)
-                    } else {
-                        if self.view is UICollectionView {
-                            (self.view as? UICollectionView)?.reloadData()
-                        } else if self.view is UITableView {
-                            (self.view as? UITableView)?.reloadData()
-                        }
-                    }
-                }
-            }
-            self.finish()
-        }
-    }
-}
-
-// MARK: -
-
 class NCOperationDownloadThumbnailActivity: ConcurrentOperation {
 
     var cell: NCActivityCollectionViewCell?

+ 2 - 2
iOSClient/Select/NCSelect.swift

@@ -307,8 +307,8 @@ extension NCSelect: UICollectionViewDataSource {
                     (cell as? NCCellProtocol)?.filePreviewImageView?.image = UIImage(named: metadata.iconName)
                 }
                 if metadata.hasPreview && metadata.status == NCGlobal.shared.metadataStatusNormal && (!CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag)) {
-                    for case let operation as NCOperationDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
-                    appDelegate.downloadThumbnailQueue.addOperation(NCOperationDownloadThumbnail(metadata: metadata, cell: (cell as? NCCellProtocol), view: view))
+                    for case let operation as NCCollectionViewDownloadThumbnail in appDelegate.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
+                    appDelegate.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, cell: (cell as? NCCellProtocol), view: view))
                 }
             }
         }