diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 2b03d33fbd..38a75f72ce 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -5555,8 +5555,8 @@ Any member of this group will be able to see messages in the channel."; "ProfilePhoto.MainPhoto" = "Main Photo"; "ProfilePhoto.SetMainPhoto" = "Set as Main Photo"; -"ProfilePhoto.MainVideo" = "Main Photo"; -"ProfilePhoto.SetMainVideo" = "Set as Main Photo"; +"ProfilePhoto.MainVideo" = "Main Video"; +"ProfilePhoto.SetMainVideo" = "Set as Main Video"; "Stats.GroupOverview" = "OVERVIEW"; "Stats.GroupMembers" = "Members"; diff --git a/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m b/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m index b8d5a85d2c..ec3d86da96 100644 --- a/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m +++ b/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m @@ -830,7 +830,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; { for (TGAttachmentAssetCell *cell in [_collectionView visibleCells]) { - if ([cell.asset isEqual:asset]) + if ([cell.asset.uniqueIdentifier isEqual:asset.uniqueIdentifier]) return cell; } @@ -1073,7 +1073,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; - (void)updateHiddenCellAnimated:(bool)animated { for (TGAttachmentAssetCell *cell in [_collectionView visibleCells]) - [cell setHidden:([cell.asset isEqual:_hiddenItem]) animated:animated]; + [cell setHidden:([cell.asset.uniqueIdentifier isEqual:_hiddenItem.uniqueIdentifier]) animated:animated]; } #pragma mark - diff --git a/submodules/LegacyComponents/Sources/TGCameraCapturedVideo.m b/submodules/LegacyComponents/Sources/TGCameraCapturedVideo.m index 91ab52dd70..c8aba55d23 100644 --- a/submodules/LegacyComponents/Sources/TGCameraCapturedVideo.m +++ b/submodules/LegacyComponents/Sources/TGCameraCapturedVideo.m @@ -14,7 +14,8 @@ { CGSize _cachedSize; NSTimeInterval _cachedDuration; - + + SVariable *_avAssetVariable; AVURLAsset *_cachedAVAsset; bool _livePhoto; } @@ -90,8 +91,14 @@ _cachedAVAsset = [AVURLAsset assetWithURL:videoUrl]; return [SSignal single:_cachedAVAsset]; } else { + if (_avAssetVariable != nil) { + return [_avAssetVariable signal]; + } + + _avAssetVariable = [[SVariable alloc] init]; + if (_originalAsset.type == TGMediaAssetGifType) { - return [[SSignal single:@0.0] then:[[[TGMediaAssetImageSignals imageDataForAsset:_originalAsset allowNetworkAccess:false] mapToSignal:^SSignal *(TGMediaAssetImageData *assetData) { + [_avAssetVariable set:[[SSignal single:@0.0] then:[[[TGMediaAssetImageSignals imageDataForAsset:_originalAsset allowNetworkAccess:false] mapToSignal:^SSignal *(TGMediaAssetImageData *assetData) { NSData *data = assetData.imageData; const char *gif87Header = "GIF87"; @@ -110,14 +117,16 @@ } }] onNext:^(id next) { _cachedAVAsset = next; - }]]; + }]]]; } else { - return [[[TGMediaAssetImageSignals avAssetForVideoAsset:_originalAsset allowNetworkAccess:false] mapToSignal:^SSignal *(AVURLAsset *asset) { + [_avAssetVariable set:[[[TGMediaAssetImageSignals avAssetForVideoAsset:_originalAsset allowNetworkAccess:false] mapToSignal:^SSignal *(AVURLAsset *asset) { return [SSignal single:asset]; }] onNext:^(id next) { _cachedAVAsset = next; - }]; + }]]; } + + return [_avAssetVariable signal]; } } } else { @@ -161,6 +170,7 @@ if (_cachedAVAsset != nil) { _cachedDuration = CMTimeGetSeconds(_cachedAVAsset.duration); } + return _cachedDuration; } diff --git a/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m b/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m index 13cac6e6c8..05feaf4a8c 100644 --- a/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m +++ b/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m @@ -285,8 +285,11 @@ for (TGMediaPickerCell *cell in [strongSelf->_collectionView visibleCells]) { - if ([cell.item isEqual:item.asset]) + if ([cell.item respondsToSelector:@selector(uniqueIdentifier)] && [[(id)cell.item uniqueIdentifier] isEqual:item.asset.uniqueIdentifier]) { return cell; + } else if ([cell.item isEqual:item.asset.uniqueIdentifier]) { + return cell; + } } return nil; diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerController.m b/submodules/LegacyComponents/Sources/TGMediaPickerController.m index de1ef07824..acd0d7af81 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerController.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerController.m @@ -334,8 +334,13 @@ { _hiddenItem = item; - for (TGMediaPickerCell *cell in [_collectionView visibleCells]) - [cell setHidden:([cell.item isEqual:_hiddenItem]) animated:animated]; + for (TGMediaPickerCell *cell in [_collectionView visibleCells]) { + if ([cell.item respondsToSelector:@selector(uniqueIdentifier)] && [_hiddenItem respondsToSelector:@selector(uniqueIdentifier)]) { + [cell setHidden:([[(id)cell.item uniqueIdentifier] isEqual:[_hiddenItem uniqueIdentifier]]) animated:animated]; + } else { + [cell setHidden:([cell.item isEqual:_hiddenItem]) animated:animated]; + } + } } - (void)_setupSelectionGesture diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m index ac47761f5e..2a288c3cfd 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItem.m @@ -38,8 +38,18 @@ if ([self.asset isKindOfClass:[TGMediaAsset class]]) return ((TGMediaAsset *)self.asset).actualVideoDuration; - if ([self.asset respondsToSelector:@selector(originalDuration)]) + if ([self.asset respondsToSelector:@selector(originalDuration)]) { + if ([self.asset isKindOfClass:[TGCameraCapturedVideo class]]) { + return [[(TGCameraCapturedVideo *)self.asset avAsset] mapToSignal:^SSignal *(id next) { + if ([next isKindOfClass:[AVAsset class]]) { + return [SSignal single:@(CMTimeGetSeconds(((AVAsset *)next).duration))]; + } else { + return [SSignal complete]; + } + }]; + } return [SSignal single:@(self.asset.originalDuration)]; + } return [SSignal single:@0]; } diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m index 12b59bd737..fce771234a 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryVideoItemView.m @@ -127,6 +127,8 @@ self = [super initWithFrame:frame]; if (self != nil) { + _chaseTime = kCMTimeInvalid; + _currentAudioSession = [[SMetaDisposable alloc] init]; _playerItemDisposable = [[SMetaDisposable alloc] init]; @@ -1244,7 +1246,12 @@ - (void)playerItemDidPlayToEndTime:(NSNotification *)__unused notification { - if (!_sendAsGif) + bool isGif = _sendAsGif; + if (!_sendAsGif && [self.item.asset isKindOfClass:[TGCameraCapturedVideo class]]) { + isGif = ((TGCameraCapturedVideo *)self.item.asset).originalAsset.type == TGMediaAssetGifType; + } + + if (!isGif) { self.isPlaying = false; [_player pause]; @@ -1289,10 +1296,12 @@ CMTime currentChasingTime = _chaseTime; [self.player.currentItem seekToTime:currentChasingTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) { - if (CMTIME_COMPARE_INLINE(currentChasingTime, ==, _chaseTime)) + if (CMTIME_COMPARE_INLINE(currentChasingTime, ==, _chaseTime)) { _chasingTime = false; - else + _chaseTime = kCMTimeInvalid; + } else { [self chaseTime]; + } }]; } diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m b/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m index eb5f9ca7a9..1c66ba5015 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerModernGalleryMixin.m @@ -76,10 +76,11 @@ __block id focusItem = nil; void (^enumerationBlock)(TGMediaPickerGalleryItem *) = ^(TGMediaPickerGalleryItem *galleryItem) { - if (focusItem == nil && [galleryItem.asset isEqual:item]) - { - focusItem = galleryItem; - galleryItem.immediateThumbnailImage = thumbnailImage; + if (focusItem == nil) { + if (([item isKindOfClass:[TGMediaAsset class]] && [galleryItem.asset.uniqueIdentifier isEqual:((TGMediaAsset *)item).uniqueIdentifier]) || [galleryItem.asset isEqual:item]) { + focusItem = galleryItem; + galleryItem.immediateThumbnailImage = thumbnailImage; + } } }; @@ -372,7 +373,6 @@ { TGCameraCapturedVideo *convertedAsset = [[TGCameraCapturedVideo alloc] initWithAsset:asset livePhoto:false]; galleryItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:convertedAsset]; -// galleryItem = [[TGMediaPickerGalleryGifItem alloc] initWithAsset:asset]; } break; diff --git a/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m b/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m index 3a9949794c..7a9f30ff1e 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m @@ -183,8 +183,12 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel } } -- (void)transitionOutSwitching:(bool)__unused switching completion:(void (^)(void))completion +- (void)transitionOutSwitching:(bool)switching completion:(void (^)(void))completion { + if (switching) { + _dismissing = true; + } + TGPhotoEditorPreviewView *previewView = self.previewView; previewView.touchedUp = nil; previewView.touchedDown = nil; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index a6e4001966..e6e8896e2d 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -157,6 +157,8 @@ _thumbnailsDisposable = [[SMetaDisposable alloc] init]; + _chaseTime = kCMTimeInvalid; + self.customAppearanceMethodsForwarding = true; } return self; @@ -596,10 +598,12 @@ CMTime currentChasingTime = _chaseTime; [_player.currentItem seekToTime:currentChasingTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) { - if (CMTIME_COMPARE_INLINE(currentChasingTime, ==, _chaseTime)) + if (CMTIME_COMPARE_INLINE(currentChasingTime, ==, _chaseTime)) { _chasingTime = false; - else + _chaseTime = kCMTimeInvalid; + } else { [self chaseTime]; + } }]; } diff --git a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m index 3c5e2d2709..6c09b904e5 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m @@ -216,7 +216,6 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; TGPhotoEditorPreviewView *previewView = _previewView; previewView.userInteractionEnabled = false; previewView.hidden = true; - [_containerView addSubview:_previewView]; __weak TGPhotoPaintController *weakSelf = self; _paintingWrapperView = [[TGPaintingWrapperView alloc] init]; @@ -2044,7 +2043,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; - (CGRect)transitionOutReferenceFrame { TGPhotoEditorPreviewView *previewView = _previewView; - return previewView.frame; + return [previewView convertRect:previewView.bounds toView:self.view]; } - (UIView *)transitionOutReferenceView diff --git a/submodules/LegacyComponents/Sources/TGVideoMessageScrubber.m b/submodules/LegacyComponents/Sources/TGVideoMessageScrubber.m index e3dc693a0f..fb0efcbba8 100644 --- a/submodules/LegacyComponents/Sources/TGVideoMessageScrubber.m +++ b/submodules/LegacyComponents/Sources/TGVideoMessageScrubber.m @@ -410,14 +410,11 @@ typedef enum else return; - if (!reset && _summaryThumbnailViews.count > 0 && _summaryThumbnailSnapshotView == nil) - { + if (!reset && _summaryThumbnailViews.count > 0 && _summaryThumbnailSnapshotView == nil) { _summaryThumbnailSnapshotView = [_summaryThumbnailWrapperView snapshotViewAfterScreenUpdates:false]; _summaryThumbnailSnapshotView.frame = _summaryThumbnailWrapperView.frame; [_summaryThumbnailWrapperView.superview insertSubview:_summaryThumbnailSnapshotView aboveSubview:_summaryThumbnailWrapperView]; - } - else if (reset) - { + } else if (reset) { [_summaryThumbnailSnapshotView removeFromSuperview]; _summaryThumbnailSnapshotView = nil; } diff --git a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift index 8ca5b378f2..000c78db5f 100644 --- a/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift +++ b/submodules/PeerAvatarGalleryUI/Sources/AvatarGalleryItemFooterContentNode.swift @@ -40,6 +40,9 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode { private var currentNameText: String? private var currentDateText: String? + private var currentTypeText: String? + + private var validLayout: (CGSize, LayoutMetrics, CGFloat, CGFloat, CGFloat, CGFloat)? var delete: (() -> Void)? { didSet { @@ -77,13 +80,11 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode { self.setMainButton = HighlightableButtonNode() self.setMainButton.isHidden = true - self.setMainButton.setAttributedTitle(NSAttributedString(string: self.strings.ProfilePhoto_SetMainPhoto, font: Font.regular(17.0), textColor: .white), for: .normal) self.mainNode = ASTextNode() self.mainNode.maximumNumberOfLines = 1 self.mainNode.isUserInteractionEnabled = false self.mainNode.displaysAsynchronously = false - self.mainNode.attributedText = NSAttributedString(string: self.strings.ProfilePhoto_MainPhoto, font: Font.regular(17.0), textColor: UIColor(rgb: 0x808080)) super.init() @@ -103,10 +104,20 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode { func setEntry(_ entry: AvatarGalleryEntry, content: AvatarGalleryItemFooterContent) { var nameText: String? var dateText: String? + var typeText: String? + var buttonText: String? switch entry { - case let .image(_, _, _, _, peer, date, _, _): + case let .image(_, _, _, videoRepresentations, peer, date, _, _): nameText = peer?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "" dateText = humanReadableStringForTimestamp(strings: self.strings, dateTimeFormat: self.dateTimeFormat, timestamp: date) + + if (!videoRepresentations.isEmpty) { + typeText = self.strings.ProfilePhoto_MainVideo + buttonText = self.strings.ProfilePhoto_SetMainVideo + } else { + typeText = self.strings.ProfilePhoto_MainPhoto + buttonText = self.strings.ProfilePhoto_SetMainPhoto + } default: break } @@ -128,6 +139,17 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode { } } + if self.currentTypeText != typeText { + self.currentTypeText = typeText + + self.mainNode.attributedText = NSAttributedString(string: typeText ?? "", font: Font.regular(17.0), textColor: UIColor(rgb: 0x808080)) + self.setMainButton.setAttributedTitle(NSAttributedString(string: buttonText ?? "", font: Font.regular(17.0), textColor: .white), for: .normal) + + if let validLayout = self.validLayout { + let _ = self.updateLayout(size: validLayout.0, metrics: validLayout.1, leftInset: validLayout.2, rightInset: validLayout.3, bottomInset: validLayout.4, contentInset: validLayout.5, transition: .immediate) + } + } + switch content { case .info: self.nameNode.isHidden = false @@ -143,6 +165,8 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode { } override func updateLayout(size: CGSize, metrics: LayoutMetrics, leftInset: CGFloat, rightInset: CGFloat, bottomInset: CGFloat, contentInset: CGFloat, transition: ContainedViewLayoutTransition) -> CGFloat { + self.validLayout = (size, metrics, leftInset, rightInset, bottomInset, contentInset) + let width = size.width var panelHeight: CGFloat = 44.0 + bottomInset panelHeight += contentInset