From bc5e40f9240c90b01ddc2b2277db9cd8e5da9e10 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 20 Feb 2021 20:57:24 +0400 Subject: [PATCH] Fix selection layout on grouped voice messages --- .../ChatMessageInteractiveFileNode.swift | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift index fece20c022..9816116f58 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift @@ -708,7 +708,15 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { selectionNode.frame = selectionFrame selectionNode.updateSelected(selection, animated: isAnimated) } else { - let selectionNode = FileMessageSelectionNode(theme: presentationData.theme.theme, incoming: incoming, noPreview: file.isMusic || file.previewRepresentations.isEmpty, toggle: { [weak self] value in + let type: FileMessageSelectionNode.NodeType + if file.isVoice { + type = .voice + } else if file.isMusic || file.previewRepresentations.isEmpty { + type = .file + } else { + type = .media + } + let selectionNode = FileMessageSelectionNode(theme: presentationData.theme.theme, incoming: incoming, type: type, toggle: { [weak self] value in self?.toggleSelection(value) }) strongSelf.selectionNode = selectionNode @@ -999,7 +1007,10 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { } } - let cutoutFrame = streamingCacheStatusFrame.insetBy(dx: -(1.0 + UIScreenPixel), dy: -(1.0 + UIScreenPixel)).offsetBy(dx: progressFrame.minX - 6.0, dy: progressFrame.minY) + var cutoutFrame = streamingCacheStatusFrame.insetBy(dx: -(1.0 + UIScreenPixel), dy: -(1.0 + UIScreenPixel)).offsetBy(dx: progressFrame.minX - 6.0, dy: progressFrame.minY) + if file.isVoice { + cutoutFrame.origin.y += 6.0 + } if streamingState == .none && self.selectionNode == nil { self.statusNode?.setCutout(nil, animated: animated) @@ -1119,16 +1130,21 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { final class FileMessageSelectionNode: ASDisplayNode { + enum NodeType { + case media + case file + case voice + } private let toggle: (Bool) -> Void private var selected = false private let checkNode: CheckNode - private let noPreview: Bool + private let type: NodeType - public init(theme: PresentationTheme, incoming: Bool, noPreview: Bool, toggle: @escaping (Bool) -> Void) { - self.noPreview = noPreview + public init(theme: PresentationTheme, incoming: Bool, type: NodeType, toggle: @escaping (Bool) -> Void) { + self.type = type self.toggle = toggle - self.checkNode = CheckNode(theme: noPreview ? CheckNodeTheme(backgroundColor: theme.list.itemCheckColors.fillColor, strokeColor: theme.list.itemCheckColors.foregroundColor, borderColor: incoming ? theme.chat.message.incoming.mediaPlaceholderColor : theme.chat.message.outgoing.mediaPlaceholderColor, overlayBorder: false, hasInset: false, hasShadow: false) : CheckNodeTheme(theme: theme, style: .overlay)) + self.checkNode = CheckNode(theme: type != .media ? CheckNodeTheme(backgroundColor: theme.list.itemCheckColors.fillColor, strokeColor: theme.list.itemCheckColors.foregroundColor, borderColor: incoming ? theme.chat.message.incoming.mediaPlaceholderColor : theme.chat.message.outgoing.mediaPlaceholderColor, overlayBorder: false, hasInset: false, hasShadow: false) : CheckNodeTheme(theme: theme, style: .overlay)) self.checkNode.isUserInteractionEnabled = false super.init() @@ -1172,12 +1188,16 @@ final class FileMessageSelectionNode: ASDisplayNode { let checkSize: CGSize let checkOrigin: CGPoint - if self.noPreview { - checkSize = CGSize(width: 20.0, height: 20.0) - checkOrigin = CGPoint(x: 29.0, y: 26.0) - } else { - checkSize = CGSize(width: 28.0, height: 28.0) - checkOrigin = CGPoint(x: 41.0, y: -3.0) + switch self.type { + case .media: + checkSize = CGSize(width: 28.0, height: 28.0) + checkOrigin = CGPoint(x: 41.0, y: -3.0) + case .file: + checkSize = CGSize(width: 20.0, height: 20.0) + checkOrigin = CGPoint(x: 29.0, y: 26.0) + case .voice: + checkSize = CGSize(width: 20.0, height: 20.0) + checkOrigin = CGPoint(x: 29.0, y: 23.0) } self.checkNode.frame = CGRect(origin: checkOrigin, size: checkSize) }