diff --git a/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift b/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift index e991414ae5..c7906f79d1 100644 --- a/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift +++ b/submodules/MusicAlbumArtResources/Sources/ExternalMusicAlbumArtResources.swift @@ -59,7 +59,7 @@ public class ExternalMusicAlbumArtResource: Equatable { } public func fetchExternalMusicAlbumArtResource(engine: TelegramEngine, file: FileMediaReference?, resource: ExternalMusicAlbumArtResource) -> Signal { - return engine.resources.fetchAlbumCover(file: file, title: resource.title, performer: resource.performer) + return engine.resources.fetchAlbumCover(file: file, title: resource.title, performer: resource.performer, isThumbnail: resource.isThumbnail) /*return Signal { subscriber in if resource.performer.isEmpty || resource.performer.lowercased().trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) == "unknown artist" || resource.title.isEmpty { diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift index 9f561bb303..888afaad03 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewGridItem.swift @@ -175,7 +175,7 @@ final class StickerPackPreviewGridItemNode: GridItemNode { if self.currentState == nil || self.currentState!.0 !== account || self.currentState!.1 != stickerItem || self.isLocked != isLocked || self.isPremium != isPremium || self.isEmpty != isEmpty { self.isLocked = isLocked - if isLocked || isPremium { + if isLocked { let lockBackground: UIVisualEffectView let lockIconNode: ASImageNode if let currentBackground = self.lockBackground, let currentIcon = self.lockIconNode { diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CloudFileMediaResource.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CloudFileMediaResource.swift index 0e64807653..2c83744200 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CloudFileMediaResource.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CloudFileMediaResource.swift @@ -739,12 +739,14 @@ final class AlbumCoverResource: TelegramMediaResource, MediaResourceWithWebFileR let file: FileMediaReference? let title: String let performer: String + let isThumbnail: Bool - init(datacenterId: Int, file: FileMediaReference?, title: String, performer: String) { + init(datacenterId: Int, file: FileMediaReference?, title: String, performer: String, isThumbnail: Bool) { self.datacenterId = datacenterId self.file = file self.title = title self.performer = performer + self.isThumbnail = isThumbnail } init(decoder: PostboxDecoder) { @@ -761,17 +763,21 @@ final class AlbumCoverResource: TelegramMediaResource, MediaResourceWithWebFileR document = .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())) flags |= 1 << 0 } - if !self.title.isEmpty { + var requestTitle: String? + var requestPerformer: String? + if !self.title.isEmpty || !self.performer.isEmpty { + requestTitle = self.title + requestPerformer = self.performer flags |= 1 << 1 } - if !self.performer.isEmpty { - flags |= 1 << 1 + if self.isThumbnail { + flags |= 1 << 2 } return .inputWebFileAudioAlbumThumbLocation( flags: flags, document: document, - title: self.title.isEmpty ? nil : self.title, - performer: self.performer.isEmpty ? nil : self.performer + title: requestTitle, + performer: requestPerformer ) } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift b/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift index 67138b5e64..82e7fd11e1 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Resources/TelegramEngineResources.swift @@ -279,12 +279,12 @@ public extension TelegramEngine { } } - public func fetchAlbumCover(file: FileMediaReference?, title: String, performer: String) -> Signal { + public func fetchAlbumCover(file: FileMediaReference?, title: String, performer: String, isThumbnail: Bool) -> Signal { let signal = currentWebDocumentsHostDatacenterId(postbox: self.account.postbox, isTestingEnvironment: self.account.testingEnvironment) |> castError(EngineMediaResource.Fetch.Error.self) |> take(1) |> mapToSignal { datacenterId -> Signal in - let resource = AlbumCoverResource(datacenterId: Int(datacenterId), file: file, title: title, performer: performer) + let resource = AlbumCoverResource(datacenterId: Int(datacenterId), file: file, title: title, performer: performer, isThumbnail: isThumbnail) return multipartFetch(postbox: self.account.postbox, network: self.account.network, mediaReferenceRevalidationContext: self.account.mediaReferenceRevalidationContext, resource: resource, datacenterId: Int(datacenterId), size: nil, intervals: .single([(0 ..< Int64.max, .default)]), parameters: MediaResourceFetchParameters( tag: nil, diff --git a/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift b/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift index 5385b98998..a19783d16d 100755 --- a/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift +++ b/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift @@ -51,6 +51,9 @@ final class HorizontalStickerGridItemNode: GridItemNode { let imageNode: TransformImageNode private(set) var animationNode: AnimatedStickerNode? private(set) var placeholderNode: StickerShimmerEffectNode? + private var lockBackground: UIVisualEffectView? + private var lockTintView: UIView? + private var lockIconNode: ASImageNode? private let stickerFetchedDisposable = MetaDisposable() @@ -193,6 +196,47 @@ final class HorizontalStickerGridItemNode: GridItemNode { self.stickerFetchedDisposable.set(freeMediaFileResourceInteractiveFetched(account: account, fileReference: stickerPackFileReference(item.file), resource: chatMessageStickerResource(file: item.file, small: true)).start()) } + if item.file.isPremiumSticker { + let lockBackground: UIVisualEffectView + let lockIconNode: ASImageNode + if let currentBackground = self.lockBackground, let currentIcon = self.lockIconNode { + lockBackground = currentBackground + lockIconNode = currentIcon + } else { + let effect: UIBlurEffect + if #available(iOS 10.0, *) { + effect = UIBlurEffect(style: .regular) + } else { + effect = UIBlurEffect(style: .light) + } + lockBackground = UIVisualEffectView(effect: effect) + lockBackground.clipsToBounds = true + lockBackground.isUserInteractionEnabled = false + lockIconNode = ASImageNode() + lockIconNode.displaysAsynchronously = false + lockIconNode.image = generateTintedImage(image: UIImage(bundleImageName: "Chat List/PeerPremiumIcon"), color: .white) + lockIconNode.transform = CATransform3DMakeRotation(CGFloat.pi / 2.0, 0.0, 0.0, 1.0) + + let lockTintView = UIView() + lockTintView.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.15) + lockBackground.contentView.addSubview(lockTintView) + + self.lockBackground = lockBackground + self.lockTintView = lockTintView + self.lockIconNode = lockIconNode + + self.view.addSubview(lockBackground) + self.addSubnode(lockIconNode) + } + } else if let lockBackground = self.lockBackground, let lockTintView = self.lockTintView, let lockIconNode = self.lockIconNode { + self.lockBackground = nil + self.lockTintView = nil + self.lockIconNode = nil + lockBackground.removeFromSuperview() + lockTintView.removeFromSuperview() + lockIconNode.removeFromSupernode() + } + self.currentState = (account, item, dimensions.cgSize) self.setNeedsLayout() } @@ -228,6 +272,21 @@ final class HorizontalStickerGridItemNode: GridItemNode { animationNode.updateLayout(size: self.imageNode.bounds.size) } } + + if let lockBackground = self.lockBackground, let lockTintView = self.lockTintView, let lockIconNode = self.lockIconNode { + let lockSize = CGSize(width: 16.0, height: 16.0) + let lockBackgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: bounds.height - lockSize.height), size: lockSize) + lockBackground.frame = lockBackgroundFrame + lockBackground.layer.cornerRadius = lockSize.width / 2.0 + if #available(iOS 13.0, *) { + lockBackground.layer.cornerCurve = .circular + } + lockTintView.frame = CGRect(origin: CGPoint(), size: lockBackgroundFrame.size) + if let icon = lockIconNode.image { + let iconSize = CGSize(width: icon.size.width - 4.0, height: icon.size.height - 4.0) + lockIconNode.frame = CGRect(origin: CGPoint(x: lockBackgroundFrame.minX + floorToScreenPixels((lockBackgroundFrame.width - iconSize.width) / 2.0), y: lockBackgroundFrame.minY + floorToScreenPixels((lockBackgroundFrame.height - iconSize.height) / 2.0)), size: iconSize) + } + } } override func updateAbsoluteRect(_ absoluteRect: CGRect, within containerSize: CGSize) {