diff --git a/TelegramUI/AutodownloadDataUsagePickerItem.swift b/TelegramUI/AutodownloadDataUsagePickerItem.swift index 52193ec0f3..960567f33e 100644 --- a/TelegramUI/AutodownloadDataUsagePickerItem.swift +++ b/TelegramUI/AutodownloadDataUsagePickerItem.swift @@ -152,6 +152,10 @@ class AutodownloadDataUsagePickerItemNode: ListViewItemNode { } sliderView.value = CGFloat(value) + + sliderView.isUserInteractionEnabled = item.enabled + sliderView.alpha = item.enabled ? 1.0 : 0.4 + sliderView.layer.allowsGroupOpacity = !item.enabled } } @@ -194,6 +198,8 @@ class AutodownloadDataUsagePickerItemNode: ListViewItemNode { self.view.addSubview(sliderView) sliderView.addTarget(self, action: #selector(self.sliderValueChanged), for: .valueChanged) self.sliderView = sliderView + + self.updateSliderView() } func asyncLayout() -> (_ item: AutodownloadDataUsagePickerItem, _ params: ListViewItemLayoutParams, _ neighbors: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) { @@ -299,10 +305,6 @@ class AutodownloadDataUsagePickerItemNode: ListViewItemNode { sliderView.knobImage = generateKnobImage() } - sliderView.isUserInteractionEnabled = item.enabled - sliderView.alpha = item.enabled ? 1.0 : 0.4 - sliderView.layer.allowsGroupOpacity = !item.enabled - sliderView.frame = CGRect(origin: CGPoint(x: params.leftInset + 15.0, y: 37.0), size: CGSize(width: params.width - params.leftInset - params.rightInset - 15.0 * 2.0, height: 44.0)) sliderView.hitTestEdgeInsets = UIEdgeInsetsMake(-sliderView.frame.minX, 0.0, 0.0, -sliderView.frame.minX) diff --git a/TelegramUI/ChatMessageAttachedContentNode.swift b/TelegramUI/ChatMessageAttachedContentNode.swift index 53b35bbd06..6aea017e84 100644 --- a/TelegramUI/ChatMessageAttachedContentNode.swift +++ b/TelegramUI/ChatMessageAttachedContentNode.swift @@ -447,7 +447,7 @@ final class ChatMessageAttachedContentNode: ASDisplayNode { initialWidth = initialImageWidth + horizontalInsets.left + horizontalInsets.right refineContentImageLayout = refineLayout } else if let wallpaper = media as? WallpaperPreviewMedia { - let (_, initialImageWidth, refineLayout) = contentImageLayout(context, presentationData.theme.theme, presentationData.strings, message, wallpaper, .full, associatedData.automaticDownloadPeerType, automaticDownloadSettings.autoplayGifs, .constrained(CGSize(width: constrainedSize.width - horizontalInsets.left - horizontalInsets.right, height: constrainedSize.height)), layoutConstants, contentMode) + let (_, initialImageWidth, refineLayout) = contentImageLayout(context, presentationData.theme.theme, presentationData.strings, message, wallpaper, .full, associatedData.automaticDownloadPeerType, false, .constrained(CGSize(width: constrainedSize.width - horizontalInsets.left - horizontalInsets.right, height: constrainedSize.height)), layoutConstants, contentMode) initialWidth = initialImageWidth + horizontalInsets.left + horizontalInsets.right refineContentImageLayout = refineLayout } diff --git a/TelegramUI/ChatMessageBubbleItemNode.swift b/TelegramUI/ChatMessageBubbleItemNode.swift index a9ca55817a..09a0ecdb02 100644 --- a/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/TelegramUI/ChatMessageBubbleItemNode.swift @@ -375,13 +375,6 @@ class ChatMessageBubbleItemNode: ChatMessageItemView { } } - var isInlinePlayableVideo = false - for media in item.content.firstMessage.media { - if let file = media as? TelegramMediaFile, file.isVideo, !file.isAnimated, isMediaStreamable(message: item.content.firstMessage, media: file) { - isInlinePlayableVideo = true - } - } - if hasAvatar { avatarInset = layoutConstants.avatarDiameter } else { diff --git a/TelegramUI/ChatMessageInteractiveMediaNode.swift b/TelegramUI/ChatMessageInteractiveMediaNode.swift index b851a64e58..590e17fb13 100644 --- a/TelegramUI/ChatMessageInteractiveMediaNode.swift +++ b/TelegramUI/ChatMessageInteractiveMediaNode.swift @@ -581,7 +581,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { } if let videoNode = strongSelf.videoNode { - if replaceVideoNode == nil, let decoration = videoNode.decoration as? ChatBubbleVideoDecoration, decoration.corners != corners { + if !(replaceVideoNode ?? false), let decoration = videoNode.decoration as? ChatBubbleVideoDecoration, decoration.corners != corners { decoration.updateCorners(corners) } @@ -904,16 +904,16 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { } } else { if isMediaStreamable(message: message, media: file), let _ = file.size { + if automaticPlayback && !message.flags.contains(.Unsent), let duration = file.duration { + let durationString = stringForDuration(playerDuration > 0 ? playerDuration : duration, position: playerPosition) + badgeContent = .text(inset: 0.0, backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, shape: .round, text: NSAttributedString(string: durationString)) + } else { + let progressString = String(format: "%d%%", Int(progress * 100.0)) + badgeContent = .text(inset: message.flags.contains(.Unsent) ? 0.0 : 12.0, backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, shape: .round, text: NSAttributedString(string: progressString)) + } + if !message.flags.contains(.Unsent) { - if automaticPlayback, let duration = file.duration { - let durationString = stringForDuration(playerDuration > 0 ? playerDuration : duration, position: playerPosition) - badgeContent = .text(inset: 0.0, backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, shape: .round, text: NSAttributedString(string: durationString)) - } else { - let progressString = String(format: "%d%%", Int(progress * 100.0)) - badgeContent = .text(inset: 12.0, backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, shape: .round, text: NSAttributedString(string: progressString)) - } mediaDownloadState = automaticPlayback ? .none : .compactFetching(progress: progress) - state = automaticPlayback ? .none : .play(bubbleTheme.mediaOverlayControlForegroundColor) } } else { diff --git a/TelegramUI/ChatMessageMediaBubbleContentNode.swift b/TelegramUI/ChatMessageMediaBubbleContentNode.swift index baa8bc9fe2..1f6c66b132 100644 --- a/TelegramUI/ChatMessageMediaBubbleContentNode.swift +++ b/TelegramUI/ChatMessageMediaBubbleContentNode.swift @@ -80,18 +80,16 @@ class ChatMessageMediaBubbleContentNode: ChatMessageBubbleContentNode { if telegramFile.isAnimated { automaticPlayback = item.controllerInteraction.automaticMediaDownloadSettings.autoplayGifs contentMode = .aspectFill - } else { - if item.controllerInteraction.automaticMediaDownloadSettings.autoplayVideos { - var willDownloadOrLocal = false - if case .full = automaticDownload { - willDownloadOrLocal = true - } else { - willDownloadOrLocal = item.context.account.postbox.mediaBox.completedResourcePath(telegramFile.resource) != nil - } - if willDownloadOrLocal { - automaticPlayback = true - contentMode = .aspectFill - } + } else if telegramFile.isVideo && item.controllerInteraction.automaticMediaDownloadSettings.autoplayVideos, case .linear = preparePosition { + var willDownloadOrLocal = false + if case .full = automaticDownload { + willDownloadOrLocal = true + } else { + willDownloadOrLocal = item.context.account.postbox.mediaBox.completedResourcePath(telegramFile.resource) != nil + } + if willDownloadOrLocal { + automaticPlayback = true + contentMode = .aspectFill } } }