diff --git a/MEGAUnitTests/Utils/Shared Views/Shared Controls/SetVideoPlayerItemMetadataCommandTests.swift b/MEGAUnitTests/Utils/Shared Views/Shared Controls/SetVideoPlayerItemMetadataCommandTests.swift index a6c413ea01..4016914137 100644 --- a/MEGAUnitTests/Utils/Shared Views/Shared Controls/SetVideoPlayerItemMetadataCommandTests.swift +++ b/MEGAUnitTests/Utils/Shared Views/Shared Controls/SetVideoPlayerItemMetadataCommandTests.swift @@ -12,7 +12,7 @@ final class SetVideoPlayerItemMetadataCommandTests: XCTestCase { node: MockNode(handle: 1), fileManager: FileManager(), sdk: MockSdk(), - nodeAssetManager: NodeAssetsManager() + nodeAssetManager: NodeAssetsManager(sdk: MockSdk()) ) await sut.execute() diff --git a/iMEGA/Cloud drive/Cells/NodeCollectionViewCell+Additions.swift b/iMEGA/Cloud drive/Cells/NodeCollectionViewCell+Additions.swift index 3792c0675d..305d095323 100644 --- a/iMEGA/Cloud drive/Cells/NodeCollectionViewCell+Additions.swift +++ b/iMEGA/Cloud drive/Cells/NodeCollectionViewCell+Additions.swift @@ -1,5 +1,6 @@ import MEGADesignToken import MEGADomain +import MEGASdk import MEGASDKRepo import UIKit @@ -17,7 +18,7 @@ extension NodeCollectionViewCell { .forEach { $0?.alpha = 1 } } - @objc func createViewModel(node: MEGANode?, isFromSharedItem: Bool) -> NodeCollectionViewCellViewModel { + @objc func createViewModel(node: MEGANode?, isFromSharedItem: Bool, sdk: MEGASdk) -> NodeCollectionViewCellViewModel { NodeCollectionViewCellViewModel( node: node?.toNodeEntity(), isFromSharedItem: isFromSharedItem, @@ -25,8 +26,11 @@ extension NodeCollectionViewCell { nodeDataRepository: NodeDataRepository.newRepo, nodeValidationRepository: NodeValidationRepository.newRepo, nodeRepository: NodeRepository.newRepo), - thumbnailUseCase: ThumbnailUseCase(repository: ThumbnailRepository.newRepo), - nodeIconUseCase: NodeIconUseCase(nodeIconRepo: NodeAssetsManager.shared)) + thumbnailUseCase: ThumbnailUseCase(repository: ThumbnailRepository( + sdk: sdk, + fileManager: .default, + nodeProvider: DefaultMEGANodeProvider(sdk: sdk))), + nodeIconUseCase: NodeIconUseCase(nodeIconRepo: NodeAssetsManager(sdk: sdk))) } @objc func bind(viewModel: NodeCollectionViewCellViewModel) { diff --git a/iMEGA/Cloud drive/Cells/NodeCollectionViewCell.m b/iMEGA/Cloud drive/Cells/NodeCollectionViewCell.m index 32799c8dda..6b7e0c217e 100644 --- a/iMEGA/Cloud drive/Cells/NodeCollectionViewCell.m +++ b/iMEGA/Cloud drive/Cells/NodeCollectionViewCell.m @@ -47,7 +47,7 @@ - (void)configureCellForNode:(MEGANode *)node allowedMultipleSelection:(BOOL)mul self.node = node; self.delegate = delegate; - [self bindWithViewModel:[self createViewModelWithNode:node isFromSharedItem:isFromSharedItem]]; + [self bindWithViewModel:[self createViewModelWithNode:node isFromSharedItem:isFromSharedItem sdk:sdk]]; if (node.isTakenDown) { self.nameLabel.attributedText = [node attributedTakenDownName]; @@ -102,7 +102,7 @@ - (void)configureCellForNode:(MEGANode *)node allowedMultipleSelection:(BOOL)mul - (void)configureCellForOfflineItem:(NSDictionary *)item itemPath:(NSString *)pathForItem allowedMultipleSelection:(BOOL)multipleSelection sdk:(nonnull MEGASdk *)sdk delegate:(id _Nullable)delegate { - [self bindWithViewModel:[self createViewModelWithNode:nil isFromSharedItem:NO]]; + [self bindWithViewModel:[self createViewModelWithNode:nil isFromSharedItem:NO sdk: sdk]]; self.favouriteView.hidden = self.linkView.hidden = self.versionedView.hidden = self.topNodeIconsView.hidden = YES; self.labelView.hidden = self.downloadedImageView.hidden = self.downloadedView.hidden = YES; @@ -182,7 +182,7 @@ - (void)configureCellForOfflineItem:(NSDictionary *)item itemPath:(NSString *)pa } - (void)configureCellForFolderLinkNode:(MEGANode *)node allowedMultipleSelection:(BOOL)multipleSelection sdk:(nonnull MEGASdk *)sdk delegate:(id _Nullable)delegate { - [self configureCellForNode:node allowedMultipleSelection:multipleSelection isFromSharedItem:NO sdk:sdk delegate:delegate]; + [self configureCellForNode:node allowedMultipleSelection:multipleSelection isFromSharedItem:YES sdk:sdk delegate:delegate]; if (self.downloadedImageView != nil) { if ([node isFile] && [MEGAStore.shareInstance offlineNodeWithNode:node] != nil) { diff --git a/iMEGA/Utils/NodeAssetsManager.swift b/iMEGA/Utils/NodeAssetsManager.swift index 4a9e49b269..9e44d1eccb 100644 --- a/iMEGA/Utils/NodeAssetsManager.swift +++ b/iMEGA/Utils/NodeAssetsManager.swift @@ -3,7 +3,13 @@ import MEGARepo import MEGASDKRepo @objc final class NodeAssetsManager: NSObject { - @objc static var shared = NodeAssetsManager() + @objc static var shared = NodeAssetsManager(sdk: .shared) + + private let sdk: MEGASdk + + init(sdk: MEGASdk) { + self.sdk = sdk + } @objc func icon(for node: MEGANode) -> UIImage { switch node.type { @@ -81,9 +87,10 @@ enum FileExtensionType: String { extension NodeAssetsManager: NodeIconRepositoryProtocol { func iconData(for node: MEGADomain.NodeEntity) -> Data { - let sdk = MEGASdk.shared - guard let megaNode = node.toMEGANode(in: sdk) else { return Data() } - - return icon(for: megaNode).pngData() ?? Data() + guard let megaNode = node.toMEGANode(in: sdk), + let icon = icon(for: megaNode).pngData() else { + return Data() + } + return icon } }