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.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";

View File

@ -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 -

View File

@ -15,6 +15,7 @@
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;
}

View File

@ -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;

View File

@ -334,9 +334,14 @@
{
_hiddenItem = item;
for (TGMediaPickerCell *cell in [_collectionView visibleCells])
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
{

View File

@ -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];
}

View File

@ -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];
}
}];
}

View File

@ -76,11 +76,12 @@
__block id<TGModernGalleryItem> focusItem = nil;
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;
galleryItem.immediateThumbnailImage = thumbnailImage;
}
}
};
NSArray *galleryItems = [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:selectionContext editingContext:editingContext stickersContext:stickersContext asFile:asFile enumerationBlock:enumerationBlock];
@ -372,7 +373,6 @@
{
TGCameraCapturedVideo *convertedAsset = [[TGCameraCapturedVideo alloc] initWithAsset:asset livePhoto:false];
galleryItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:convertedAsset];
// galleryItem = [[TGMediaPickerGalleryGifItem alloc] initWithAsset:asset];
}
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;
previewView.touchedUp = nil;
previewView.touchedDown = nil;

View File

@ -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];
}
}];
}

View File

@ -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

View File

@ -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;
}

View File

@ -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