|
@@ -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()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|