Skip to content

Commit

Permalink
new preview api
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Jun 21, 2024
1 parent f9fa801 commit 84a55b7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5698,8 +5698,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/nextcloud/NextcloudKit";
requirement = {
kind = exactVersion;
version = 3.0.1;
branch = develop;
kind = branch;
};
};
F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {
Expand Down
4 changes: 2 additions & 2 deletions Widget/Files/FilesData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
if let result = utility.createFilePreviewImage(ocId: file.ocId, etag: file.etag, fileNameView: file.fileName, classFile: file.classFile, status: 0, createPreviewMedia: false) {
image = result
} else if file.hasPreview {
let fileNamePathOrFileId = utilityFileSystem.getFileNamePath(file.fileName, serverUrl: file.serverUrl, urlBase: file.urlBase, userId: file.userId)

let fileNamePreviewLocalPath = utilityFileSystem.getDirectoryProviderStoragePreviewOcId(file.ocId, etag: file.etag)
let fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(file.ocId, etag: file.etag)
let sizePreview = NCUtility().getSizePreview(width: Int(file.width), height: Int(file.height))
let (_, _, imageIcon, _, _, _) = await NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePathOrFileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, widthPreview: Int(sizePreview.width), heightPreview: Int(sizePreview.height), fileNameIconLocalPath: fileNameIconLocalPath, sizeIcon: NCGlobal.shared.sizeIcon, options: options)
let (_, _, imageIcon, _, _, _) = await NextcloudKit.shared.downloadPreview(fileId: file.fileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, fileNameIconLocalPath: fileNameIconLocalPath, widthPreview: Int(sizePreview.width), heightPreview: Int(sizePreview.height), sizeIcon: NCGlobal.shared.sizeIcon, options: options)
if let result = imageIcon {
image = result
}
Expand Down
14 changes: 3 additions & 11 deletions iOSClient/Activity/NCActivityTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ extension NCActivityTableViewCell: UICollectionViewDataSource {
cell.fileId = fileId
if !FileManager.default.fileExists(atPath: fileNamePath) {
if NCNetworking.shared.downloadThumbnailActivityQueue.operations.filter({ ($0 as? NCOperationDownloadThumbnailActivity)?.fileId == fileId }).isEmpty {
NCNetworking.shared.downloadThumbnailActivityQueue.addOperation(NCOperationDownloadThumbnailActivity(fileNamePathOrFileId: activityPreview.source, fileNamePreviewLocalPath: fileNamePath, fileId: fileId, cell: cell, collectionView: collectionView))
NCNetworking.shared.downloadThumbnailActivityQueue.addOperation(NCOperationDownloadThumbnailActivity(fileId: fileId, fileNamePreviewLocalPath: fileNamePath, cell: cell, collectionView: collectionView))
}
}
}
Expand Down Expand Up @@ -231,28 +231,20 @@ class NCOperationDownloadThumbnailActivity: ConcurrentOperation {

var cell: NCActivityCollectionViewCell?
var collectionView: UICollectionView?
var fileNamePathOrFileId: String
var fileNamePreviewLocalPath: String
var fileId: String

init(fileNamePathOrFileId: String, fileNamePreviewLocalPath: String, fileId: String, cell: NCActivityCollectionViewCell?, collectionView: UICollectionView?) {
self.fileNamePathOrFileId = fileNamePathOrFileId
init(fileId: String, fileNamePreviewLocalPath: String, cell: NCActivityCollectionViewCell?, collectionView: UICollectionView?) {
self.fileNamePreviewLocalPath = fileNamePreviewLocalPath
self.fileId = fileId
self.cell = cell
self.collectionView = collectionView
}

override func start() {

guard !isCancelled else { return self.finish() }

NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePathOrFileId,
NextcloudKit.shared.downloadPreview(fileId: fileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
widthPreview: 0,
heightPreview: 0,
etag: nil,
useInternalEndpoint: false,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, _, error in

if error == .success, let imagePreview = imagePreview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class NCCollectionViewDownloadThumbnail: ConcurrentOperation {
var metadata: tableMetadata
var cell: NCCellProtocol?
var collectionView: UICollectionView?
var fileNamePath: String
var fileNamePreviewLocalPath: String
var fileNameIconLocalPath: String
let utilityFileSystem = NCUtilityFileSystem()
Expand All @@ -41,7 +40,6 @@ class NCCollectionViewDownloadThumbnail: ConcurrentOperation {
self.metadata = tableMetadata.init(value: metadata)
self.cell = cell
self.collectionView = collectionView
self.fileNamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)
self.fileNamePreviewLocalPath = utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)
self.fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
}
Expand All @@ -56,11 +54,11 @@ class NCCollectionViewDownloadThumbnail: ConcurrentOperation {
etagResource = metadata.etagResource
}

NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePath,
NextcloudKit.shared.downloadPreview(fileId: metadata.fileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
fileNameIconLocalPath: fileNameIconLocalPath,
widthPreview: Int(sizePreview.width),
heightPreview: Int(sizePreview.height),
fileNameIconLocalPath: fileNameIconLocalPath,
sizeIcon: NCGlobal.shared.sizeIcon,
etag: etagResource,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, imageIcon, _, etag, error in
Expand Down
6 changes: 2 additions & 4 deletions iOSClient/Media/NCMediaDownloadThumbnaill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ class NCMediaDownloadThumbnaill: ConcurrentOperation {

var metadata: tableMetadata
var media: NCMedia
var fileNamePath: String
var fileNamePreviewLocalPath: String
var fileNameIconLocalPath: String
let utilityFileSystem = NCUtilityFileSystem()

init(metadata: tableMetadata, media: NCMedia) {
self.metadata = tableMetadata.init(value: metadata)
self.media = media
self.fileNamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)
self.fileNamePreviewLocalPath = utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)
self.fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
}
Expand All @@ -52,11 +50,11 @@ class NCMediaDownloadThumbnaill: ConcurrentOperation {
etagResource = metadata.etagResource
}

NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePath,
NextcloudKit.shared.downloadPreview(fileId: metadata.fileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
fileNameIconLocalPath: fileNameIconLocalPath,
widthPreview: Int(sizePreview.width),
heightPreview: Int(sizePreview.height),
fileNameIconLocalPath: fileNameIconLocalPath,
sizeIcon: NCGlobal.shared.sizeIcon,
etag: etagResource,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, etag, error in
Expand Down
16 changes: 7 additions & 9 deletions iOSClient/Trash/NCTrash+Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,13 @@ class NCOperationDownloadThumbnailTrash: ConcurrentOperation {
let fileNamePreviewLocalPath = NCUtilityFileSystem().getDirectoryProviderStoragePreviewOcId(tableTrash.fileId, etag: tableTrash.fileName)
let fileNameIconLocalPath = NCUtilityFileSystem().getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)

NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: tableTrash.fileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
widthPreview: NCGlobal.shared.sizePreview,
heightPreview: NCGlobal.shared.sizePreview,
fileNameIconLocalPath: fileNameIconLocalPath,
sizeIcon: NCGlobal.shared.sizeIcon,
etag: nil,
endpointTrashbin: true,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, _, error in
NextcloudKit.shared.downloadTrashPreview(fileId: tableTrash.fileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
fileNameIconLocalPath: fileNameIconLocalPath,
widthPreview: NCGlobal.shared.sizePreview,
heightPreview: NCGlobal.shared.sizePreview,
sizeIcon: NCGlobal.shared.sizeIcon,
options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, _, error in

if error == .success, let imagePreview = imagePreview {
DispatchQueue.main.async {
Expand Down
5 changes: 2 additions & 3 deletions iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,15 @@ class NCViewerMedia: UIViewController {
if utilityFileSystem.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) {
return completion(UIImage(contentsOfFile: utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)))
} else {
let fileNamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId)
let fileNamePreviewLocalPath = utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)
let fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)
let sizePreview = NCUtility().getSizePreview(width: metadata.width, height: metadata.height)

NextcloudKit.shared.downloadPreview(fileNamePathOrFileId: fileNamePath,
NextcloudKit.shared.downloadPreview(fileId: metadata.fileId,
fileNamePreviewLocalPath: fileNamePreviewLocalPath,
fileNameIconLocalPath: fileNameIconLocalPath,
widthPreview: Int(sizePreview.width),
heightPreview: Int(sizePreview.height),
fileNameIconLocalPath: fileNameIconLocalPath,
sizeIcon: NCGlobal.shared.sizeIcon,
options: NKRequestOptions(queue: .main)) { _, imagePreview, _, _, etag, error in

Expand Down

0 comments on commit 84a55b7

Please sign in to comment.