Video avatar fixes

This commit is contained in:
Ilya Laktyushin 2020-06-26 06:41:44 +03:00
parent 019946f600
commit 33538b46b9
13 changed files with 99 additions and 34 deletions

View File

@ -5555,8 +5555,8 @@ Any member of this group will be able to see messages in the channel.";
"ProfilePhoto.MainPhoto" = "Main Photo"; "ProfilePhoto.MainPhoto" = "Main Photo";
"ProfilePhoto.SetMainPhoto" = "Set as Main Photo"; "ProfilePhoto.SetMainPhoto" = "Set as Main Photo";
"ProfilePhoto.MainVideo" = "Main Photo"; "ProfilePhoto.MainVideo" = "Main Video";
"ProfilePhoto.SetMainVideo" = "Set as Main Photo"; "ProfilePhoto.SetMainVideo" = "Set as Main Video";
"Stats.GroupOverview" = "OVERVIEW"; "Stats.GroupOverview" = "OVERVIEW";
"Stats.GroupMembers" = "Members"; "Stats.GroupMembers" = "Members";

View File

@ -830,7 +830,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500;
{ {
for (TGAttachmentAssetCell *cell in [_collectionView visibleCells]) for (TGAttachmentAssetCell *cell in [_collectionView visibleCells])
{ {
if ([cell.asset isEqual:asset]) if ([cell.asset.uniqueIdentifier isEqual:asset.uniqueIdentifier])
return cell; return cell;
} }
@ -1073,7 +1073,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500;
- (void)updateHiddenCellAnimated:(bool)animated - (void)updateHiddenCellAnimated:(bool)animated
{ {
for (TGAttachmentAssetCell *cell in [_collectionView visibleCells]) 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 - #pragma mark -

View File

@ -15,6 +15,7 @@
CGSize _cachedSize; CGSize _cachedSize;
NSTimeInterval _cachedDuration; NSTimeInterval _cachedDuration;
SVariable *_avAssetVariable;
AVURLAsset *_cachedAVAsset; AVURLAsset *_cachedAVAsset;
bool _livePhoto; bool _livePhoto;
} }
@ -90,8 +91,14 @@
_cachedAVAsset = [AVURLAsset assetWithURL:videoUrl]; _cachedAVAsset = [AVURLAsset assetWithURL:videoUrl];
return [SSignal single:_cachedAVAsset]; return [SSignal single:_cachedAVAsset];
} else { } else {
if (_avAssetVariable != nil) {
return [_avAssetVariable signal];
}
_avAssetVariable = [[SVariable alloc] init];
if (_originalAsset.type == TGMediaAssetGifType) { 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; NSData *data = assetData.imageData;
const char *gif87Header = "GIF87"; const char *gif87Header = "GIF87";
@ -110,14 +117,16 @@
} }
}] onNext:^(id next) { }] onNext:^(id next) {
_cachedAVAsset = next; _cachedAVAsset = next;
}]]; }]]];
} else { } 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]; return [SSignal single:asset];
}] onNext:^(id next) { }] onNext:^(id next) {
_cachedAVAsset = next; _cachedAVAsset = next;
}]; }]];
} }
return [_avAssetVariable signal];
} }
} }
} else { } else {
@ -161,6 +170,7 @@
if (_cachedAVAsset != nil) { if (_cachedAVAsset != nil) {
_cachedDuration = CMTimeGetSeconds(_cachedAVAsset.duration); _cachedDuration = CMTimeGetSeconds(_cachedAVAsset.duration);
} }
return _cachedDuration; return _cachedDuration;
} }

View File

@ -285,8 +285,11 @@
for (TGMediaPickerCell *cell in [strongSelf->_collectionView visibleCells]) 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; return cell;
} else if ([cell.item isEqual:item.asset.uniqueIdentifier]) {
return cell;
}
} }
return nil; return nil;

View File

@ -334,8 +334,13 @@
{ {
_hiddenItem = item; _hiddenItem = item;
for (TGMediaPickerCell *cell in [_collectionView visibleCells]) for (TGMediaPickerCell *cell in [_collectionView visibleCells]) {
[cell setHidden:([cell.item isEqual:_hiddenItem]) animated:animated]; 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 - (void)_setupSelectionGesture

View File

@ -38,8 +38,18 @@
if ([self.asset isKindOfClass:[TGMediaAsset class]]) if ([self.asset isKindOfClass:[TGMediaAsset class]])
return ((TGMediaAsset *)self.asset).actualVideoDuration; 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:@(self.asset.originalDuration)];
}
return [SSignal single:@0]; return [SSignal single:@0];
} }

View File

@ -127,6 +127,8 @@
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self != nil) if (self != nil)
{ {
_chaseTime = kCMTimeInvalid;
_currentAudioSession = [[SMetaDisposable alloc] init]; _currentAudioSession = [[SMetaDisposable alloc] init];
_playerItemDisposable = [[SMetaDisposable alloc] init]; _playerItemDisposable = [[SMetaDisposable alloc] init];
@ -1244,7 +1246,12 @@
- (void)playerItemDidPlayToEndTime:(NSNotification *)__unused notification - (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; self.isPlaying = false;
[_player pause]; [_player pause];
@ -1289,10 +1296,12 @@
CMTime currentChasingTime = _chaseTime; CMTime currentChasingTime = _chaseTime;
[self.player.currentItem seekToTime:currentChasingTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) { [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; _chasingTime = false;
else _chaseTime = kCMTimeInvalid;
} else {
[self chaseTime]; [self chaseTime];
}
}]; }];
} }

View File

@ -76,10 +76,11 @@
__block id<TGModernGalleryItem> focusItem = nil; __block id<TGModernGalleryItem> focusItem = nil;
void (^enumerationBlock)(TGMediaPickerGalleryItem *) = ^(TGMediaPickerGalleryItem *galleryItem) void (^enumerationBlock)(TGMediaPickerGalleryItem *) = ^(TGMediaPickerGalleryItem *galleryItem)
{ {
if (focusItem == nil && [galleryItem.asset isEqual:item]) if (focusItem == nil) {
{ if (([item isKindOfClass:[TGMediaAsset class]] && [galleryItem.asset.uniqueIdentifier isEqual:((TGMediaAsset *)item).uniqueIdentifier]) || [galleryItem.asset isEqual:item]) {
focusItem = galleryItem; focusItem = galleryItem;
galleryItem.immediateThumbnailImage = thumbnailImage; galleryItem.immediateThumbnailImage = thumbnailImage;
}
} }
}; };
@ -372,7 +373,6 @@
{ {
TGCameraCapturedVideo *convertedAsset = [[TGCameraCapturedVideo alloc] initWithAsset:asset livePhoto:false]; TGCameraCapturedVideo *convertedAsset = [[TGCameraCapturedVideo alloc] initWithAsset:asset livePhoto:false];
galleryItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:convertedAsset]; galleryItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:convertedAsset];
// galleryItem = [[TGMediaPickerGalleryGifItem alloc] initWithAsset:asset];
} }
break; break;

View File

@ -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; TGPhotoEditorPreviewView *previewView = self.previewView;
previewView.touchedUp = nil; previewView.touchedUp = nil;
previewView.touchedDown = nil; previewView.touchedDown = nil;

View File

@ -157,6 +157,8 @@
_thumbnailsDisposable = [[SMetaDisposable alloc] init]; _thumbnailsDisposable = [[SMetaDisposable alloc] init];
_chaseTime = kCMTimeInvalid;
self.customAppearanceMethodsForwarding = true; self.customAppearanceMethodsForwarding = true;
} }
return self; return self;
@ -596,10 +598,12 @@
CMTime currentChasingTime = _chaseTime; CMTime currentChasingTime = _chaseTime;
[_player.currentItem seekToTime:currentChasingTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) { [_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; _chasingTime = false;
else _chaseTime = kCMTimeInvalid;
} else {
[self chaseTime]; [self chaseTime];
}
}]; }];
} }

View File

@ -216,7 +216,6 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f;
TGPhotoEditorPreviewView *previewView = _previewView; TGPhotoEditorPreviewView *previewView = _previewView;
previewView.userInteractionEnabled = false; previewView.userInteractionEnabled = false;
previewView.hidden = true; previewView.hidden = true;
[_containerView addSubview:_previewView];
__weak TGPhotoPaintController *weakSelf = self; __weak TGPhotoPaintController *weakSelf = self;
_paintingWrapperView = [[TGPaintingWrapperView alloc] init]; _paintingWrapperView = [[TGPaintingWrapperView alloc] init];
@ -2044,7 +2043,7 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f;
- (CGRect)transitionOutReferenceFrame - (CGRect)transitionOutReferenceFrame
{ {
TGPhotoEditorPreviewView *previewView = _previewView; TGPhotoEditorPreviewView *previewView = _previewView;
return previewView.frame; return [previewView convertRect:previewView.bounds toView:self.view];
} }
- (UIView *)transitionOutReferenceView - (UIView *)transitionOutReferenceView

View File

@ -410,14 +410,11 @@ typedef enum
else else
return; return;
if (!reset && _summaryThumbnailViews.count > 0 && _summaryThumbnailSnapshotView == nil) if (!reset && _summaryThumbnailViews.count > 0 && _summaryThumbnailSnapshotView == nil) {
{
_summaryThumbnailSnapshotView = [_summaryThumbnailWrapperView snapshotViewAfterScreenUpdates:false]; _summaryThumbnailSnapshotView = [_summaryThumbnailWrapperView snapshotViewAfterScreenUpdates:false];
_summaryThumbnailSnapshotView.frame = _summaryThumbnailWrapperView.frame; _summaryThumbnailSnapshotView.frame = _summaryThumbnailWrapperView.frame;
[_summaryThumbnailWrapperView.superview insertSubview:_summaryThumbnailSnapshotView aboveSubview:_summaryThumbnailWrapperView]; [_summaryThumbnailWrapperView.superview insertSubview:_summaryThumbnailSnapshotView aboveSubview:_summaryThumbnailWrapperView];
} } else if (reset) {
else if (reset)
{
[_summaryThumbnailSnapshotView removeFromSuperview]; [_summaryThumbnailSnapshotView removeFromSuperview];
_summaryThumbnailSnapshotView = nil; _summaryThumbnailSnapshotView = nil;
} }

View File

@ -40,6 +40,9 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode {
private var currentNameText: String? private var currentNameText: String?
private var currentDateText: String? private var currentDateText: String?
private var currentTypeText: String?
private var validLayout: (CGSize, LayoutMetrics, CGFloat, CGFloat, CGFloat, CGFloat)?
var delete: (() -> Void)? { var delete: (() -> Void)? {
didSet { didSet {
@ -77,13 +80,11 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode {
self.setMainButton = HighlightableButtonNode() self.setMainButton = HighlightableButtonNode()
self.setMainButton.isHidden = true 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 = ASTextNode()
self.mainNode.maximumNumberOfLines = 1 self.mainNode.maximumNumberOfLines = 1
self.mainNode.isUserInteractionEnabled = false self.mainNode.isUserInteractionEnabled = false
self.mainNode.displaysAsynchronously = 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() super.init()
@ -103,10 +104,20 @@ final class AvatarGalleryItemFooterContentNode: GalleryFooterContentNode {
func setEntry(_ entry: AvatarGalleryEntry, content: AvatarGalleryItemFooterContent) { func setEntry(_ entry: AvatarGalleryEntry, content: AvatarGalleryItemFooterContent) {
var nameText: String? var nameText: String?
var dateText: String? var dateText: String?
var typeText: String?
var buttonText: String?
switch entry { switch entry {
case let .image(_, _, _, _, peer, date, _, _): case let .image(_, _, _, videoRepresentations, peer, date, _, _):
nameText = peer?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "" nameText = peer?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? ""
dateText = humanReadableStringForTimestamp(strings: self.strings, dateTimeFormat: self.dateTimeFormat, timestamp: date) 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: default:
break 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 { switch content {
case .info: case .info:
self.nameNode.isHidden = false 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 { 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 let width = size.width
var panelHeight: CGFloat = 44.0 + bottomInset var panelHeight: CGFloat = 44.0 + bottomInset
panelHeight += contentInset panelHeight += contentInset