From 13b718d77bb4a218636988a1384328198d09a2d6 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 22 Jun 2018 20:11:19 +0300 Subject: [PATCH] no message --- .../TGAttachmentCarouselItemView.h | 1 + .../TGAttachmentCarouselItemView.m | 5 +- LegacyComponents/TGCache.m | 7 +- LegacyComponents/TGCameraCapturedPhoto.h | 1 + LegacyComponents/TGCameraCapturedPhoto.m | 128 ++++++++++++------ LegacyComponents/TGCameraController.h | 4 + LegacyComponents/TGCameraController.m | 3 + LegacyComponents/TGEmbedCoubPlayerView.m | 3 + LegacyComponents/TGEmbedPlayerView.h | 2 + LegacyComponents/TGEmbedPlayerView.m | 11 -- LegacyComponents/TGEmbedVinePlayerView.m | 3 + LegacyComponents/TGEmbedYoutubePlayerView.m | 6 +- LegacyComponents/TGMediaAssetsController.h | 2 + LegacyComponents/TGMediaAssetsController.m | 8 +- .../TGMediaAssetsMomentsController.m | 2 +- .../TGMediaAssetsPickerController.m | 4 +- LegacyComponents/TGMediaPickerController.h | 1 + .../TGMediaPickerGalleryInterfaceView.h | 1 + .../TGMediaPickerGalleryInterfaceView.m | 2 +- LegacyComponents/TGMediaPickerGalleryModel.h | 2 + LegacyComponents/TGMediaPickerGalleryModel.m | 1 + .../TGMediaPickerGalleryVideoItemView.m | 2 +- .../TGMediaPickerModernGalleryMixin.h | 4 +- .../TGMediaPickerModernGalleryMixin.m | 11 +- LegacyComponents/TGMediaVideoConverter.m | 3 + LegacyComponents/TGMessage.h | 1 + LegacyComponents/TGModernGalleryController.m | 39 +++--- LegacyComponents/TGModernGalleryView.h | 1 + LegacyComponents/TGModernGalleryView.m | 45 +++++- LegacyComponents/TGPhotoVideoEditor.h | 2 +- LegacyComponents/TGPhotoVideoEditor.m | 36 +---- LegacyComponents/UIScrollView+TGHacks.m | 11 +- 32 files changed, 221 insertions(+), 131 deletions(-) diff --git a/LegacyComponents/TGAttachmentCarouselItemView.h b/LegacyComponents/TGAttachmentCarouselItemView.h index 2d69d21794..e7d1f4cbba 100644 --- a/LegacyComponents/TGAttachmentCarouselItemView.h +++ b/LegacyComponents/TGAttachmentCarouselItemView.h @@ -26,6 +26,7 @@ @property (nonatomic) bool hasTimer; @property (nonatomic) bool onlyCrop; @property (nonatomic) bool asFile; +@property (nonatomic) bool inhibitMute; @property (nonatomic, strong) NSArray *underlyingViews; @property (nonatomic, assign) bool openEditor; diff --git a/LegacyComponents/TGAttachmentCarouselItemView.m b/LegacyComponents/TGAttachmentCarouselItemView.m index f6d6d664c2..40f3d16ec9 100644 --- a/LegacyComponents/TGAttachmentCarouselItemView.m +++ b/LegacyComponents/TGAttachmentCarouselItemView.m @@ -768,7 +768,8 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; __strong TGAttachmentCarouselItemView *strongSelf = weakSelf; if (strongSelf != nil && strongSelf.sendPressed != nil) { - [[NSUserDefaults standardUserDefaults] setObject:@(!strongSelf->_selectionContext.grouping) forKey:@"TG_mediaGroupingDisabled_v0"]; + if (strongSelf->_selectionContext.allowGrouping) + [[NSUserDefaults standardUserDefaults] setObject:@(!strongSelf->_selectionContext.grouping) forKey:@"TG_mediaGroupingDisabled_v0"]; strongSelf.sendPressed(item.asset, strongSelf.asFile); } }; @@ -789,7 +790,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; if ([cell isKindOfClass:[TGAttachmentAssetCell class]]) thumbnailImage = cell.imageView.image; - TGMediaPickerModernGalleryMixin *mixin = [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:asset fetchResult:_fetchResult parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:(_allowCaptions && !_forProfilePhoto) allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:_inhibitDocumentCaptions asFile:self.asFile itemsLimit:TGAttachmentDisplayedAssetLimit recipientName:self.recipientName]; + TGMediaPickerModernGalleryMixin *mixin = [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:asset fetchResult:_fetchResult parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:(_allowCaptions && !_forProfilePhoto) allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:_inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:self.asFile itemsLimit:TGAttachmentDisplayedAssetLimit recipientName:self.recipientName]; __weak TGAttachmentCarouselItemView *weakSelf = self; mixin.thumbnailSignalForItem = ^SSignal *(id item) diff --git a/LegacyComponents/TGCache.m b/LegacyComponents/TGCache.m index 0b6d74fa29..9f0ede87a9 100644 --- a/LegacyComponents/TGCache.m +++ b/LegacyComponents/TGCache.m @@ -737,7 +737,12 @@ static NSFileManager *cacheFileManager = nil; dispatch_async([TGCache diskCacheQueue], ^ { NSError *error = nil; - [cacheFileManager moveItemAtPath:fileUrl toPath:[_diskCachePath stringByAppendingPathComponent:md5String(cacheUrl)] error:&error]; + + NSString *targetPath = [_diskCachePath stringByAppendingPathComponent:md5String(cacheUrl)]; + if ([[NSFileManager defaultManager] fileExistsAtPath:targetPath]) + [[NSFileManager defaultManager] removeItemAtPath:targetPath error:NULL]; + + [cacheFileManager moveItemAtPath:fileUrl toPath:targetPath error:&error]; if (error != nil) TGLegacyLog(@"Failed to move: %@", error); }); diff --git a/LegacyComponents/TGCameraCapturedPhoto.h b/LegacyComponents/TGCameraCapturedPhoto.h index 1a7017c56f..251ff85651 100644 --- a/LegacyComponents/TGCameraCapturedPhoto.h +++ b/LegacyComponents/TGCameraCapturedPhoto.h @@ -10,6 +10,7 @@ @property (nonatomic, readonly) PGCameraShotMetadata *metadata; - (instancetype)initWithImage:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata; +- (instancetype)initWithExistingImage:(UIImage *)image; - (void)_cleanUp; diff --git a/LegacyComponents/TGCameraCapturedPhoto.m b/LegacyComponents/TGCameraCapturedPhoto.m index 07a827cd50..229c272740 100644 --- a/LegacyComponents/TGCameraCapturedPhoto.m +++ b/LegacyComponents/TGCameraCapturedPhoto.m @@ -9,6 +9,7 @@ NSString *_identifier; CGSize _dimensions; + UIImage *_existingImage; SVariable *_thumbnail; UIImage *_thumbImage; } @@ -31,6 +32,33 @@ return self; } +- (instancetype)initWithExistingImage:(UIImage *)image +{ + self = [super init]; + if (self != nil) + { + _identifier = [NSString stringWithFormat:@"%ld", lrand48()]; + _dimensions = CGSizeMake(image.size.width, image.size.height); + _thumbnail = [[SVariable alloc] init]; + + _existingImage = image; + SSignal *thumbnailSignal = [[[SSignal alloc] initWithGenerator:^id(SSubscriber *subscriber) + { + CGFloat thumbnailImageSide = TGPhotoThumbnailSizeForCurrentScreen().width * TGScreenScaling(); + CGSize thumbnailSize = TGScaleToSize(image.size, CGSizeMake(thumbnailImageSide, thumbnailImageSide)); + UIImage *thumbnailImage = TGScaleImageToPixelSize(image, thumbnailSize); + + [subscriber putNext:thumbnailImage]; + [subscriber putCompletion]; + + return nil; + }] startOn:[SQueue concurrentDefaultQueue]]; + + [_thumbnail set:thumbnailSignal]; + } + return self; +} + - (void)_cleanUp { [[NSFileManager defaultManager] removeItemAtPath:[self filePath] error:nil]; @@ -108,59 +136,73 @@ - (SSignal *)screenImageSignal:(NSTimeInterval)__unused position { - return [[SSignal alloc] initWithGenerator:^id(SSubscriber *subscriber) + if (_existingImage != nil) { - CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[self filePath]], NULL); - if (imageSource == NULL) + return [SSignal single:_existingImage]; + } + else + { + return [[SSignal alloc] initWithGenerator:^id(SSubscriber *subscriber) { - [subscriber putError:nil]; + CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[self filePath]], NULL); + if (imageSource == NULL) + { + [subscriber putError:nil]; + return nil; + } + + CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef)@ + { + (id)kCGImageSourceShouldAllowFloat : (id)kCFBooleanTrue, + (id)kCGImageSourceCreateThumbnailWithTransform : (id)kCFBooleanFalse, + (id)kCGImageSourceCreateThumbnailFromImageIfAbsent : (id)kCFBooleanTrue, + (id)kCGImageSourceThumbnailMaxPixelSize : @(1600) + }); + if (imageRef == NULL) + imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, nil); + + UIImage *image = [UIImage imageWithCGImage:imageRef]; + CGImageRelease(imageRef); + CFRelease(imageSource); + + [subscriber putNext:image]; + [subscriber putCompletion]; + return nil; - } - - CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef)@ - { - (id)kCGImageSourceShouldAllowFloat : (id)kCFBooleanTrue, - (id)kCGImageSourceCreateThumbnailWithTransform : (id)kCFBooleanFalse, - (id)kCGImageSourceCreateThumbnailFromImageIfAbsent : (id)kCFBooleanTrue, - (id)kCGImageSourceThumbnailMaxPixelSize : @(1600) - }); - if (imageRef == NULL) - imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, nil); - - UIImage *image = [UIImage imageWithCGImage:imageRef]; - CGImageRelease(imageRef); - CFRelease(imageSource); - - [subscriber putNext:image]; - [subscriber putCompletion]; - - return nil; - }]; + }]; + } } - (SSignal *)originalImageSignal:(NSTimeInterval)__unused position { - return [[SSignal alloc] initWithGenerator:^id(SSubscriber *subscriber) + if (_existingImage != nil) { - NSData *data = [[NSData alloc] initWithContentsOfFile:[self filePath] options:NSDataReadingMappedIfSafe error:NULL]; - if (data.length == 0) + return [SSignal single:_existingImage]; + } + else + { + return [[SSignal alloc] initWithGenerator:^id(SSubscriber *subscriber) { - [subscriber putError:nil]; + NSData *data = [[NSData alloc] initWithContentsOfFile:[self filePath] options:NSDataReadingMappedIfSafe error:NULL]; + if (data.length == 0) + { + [subscriber putError:nil]; + return nil; + } + + UIImage *image = [[UIImage alloc] initWithData:data]; + if (image == nil) + { + [subscriber putError:nil]; + return nil; + } + + [subscriber putNext:image]; + [subscriber putCompletion]; + return nil; - } - - UIImage *image = [[UIImage alloc] initWithData:data]; - if (image == nil) - { - [subscriber putError:nil]; - return nil; - } - - [subscriber putNext:image]; - [subscriber putCompletion]; - - return nil; - }]; + }]; + } } @end diff --git a/LegacyComponents/TGCameraController.h b/LegacyComponents/TGCameraController.h index 587ea251bb..00d065553e 100644 --- a/LegacyComponents/TGCameraController.h +++ b/LegacyComponents/TGCameraController.h @@ -32,10 +32,14 @@ typedef enum { @property (nonatomic, assign) bool allowGrouping; @property (nonatomic, assign) bool inhibitDocumentCaptions; @property (nonatomic, assign) bool inhibitMultipleCapture; +@property (nonatomic, assign) bool inhibitMute; @property (nonatomic, assign) bool hasTimer; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; @property (nonatomic, assign) bool shortcut; +@property (nonatomic, strong) NSString *forcedCaption; +@property (nonatomic, strong) NSArray *forcedEntities; + @property (nonatomic, strong) NSString *recipientName; @property (nonatomic, copy) void(^finishedWithResults)(TGOverlayController *controller, TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem); diff --git a/LegacyComponents/TGCameraController.m b/LegacyComponents/TGCameraController.m index 6ecda774c0..69fb3bbe51 100644 --- a/LegacyComponents/TGCameraController.m +++ b/LegacyComponents/TGCameraController.m @@ -1144,6 +1144,8 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus if (editingContext == nil) { editingContext = [[TGMediaEditingContext alloc] init]; + if (self.forcedCaption != nil) + [editingContext setForcedCaption:self.forcedCaption entities:self.forcedEntities]; _editingContext = editingContext; _interfaceView.editingContext = editingContext; } @@ -1229,6 +1231,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus bool hasCamera = !self.inhibitMultipleCapture && ((_intent == TGCameraControllerGenericIntent && !_shortcut) || (_intent == TGCameraControllerPassportMultipleIntent)); TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:galleryItems focusItem:focusItem selectionContext:_items.count > 1 ? selectionContext : nil editingContext:editingContext hasCaptions:self.allowCaptions allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:_intent == TGCameraControllerPassportIntent || _intent == TGCameraControllerPassportIdIntent || _intent == TGCameraControllerPassportMultipleIntent inhibitDocumentCaptions:self.inhibitDocumentCaptions hasSelectionPanel:true hasCamera:hasCamera recipientName:self.recipientName]; + model.inhibitMute = self.inhibitMute; model.controller = galleryController; model.suggestionContext = self.suggestionContext; diff --git a/LegacyComponents/TGEmbedCoubPlayerView.m b/LegacyComponents/TGEmbedCoubPlayerView.m index 875d8748f4..7020a48ce6 100644 --- a/LegacyComponents/TGEmbedCoubPlayerView.m +++ b/LegacyComponents/TGEmbedCoubPlayerView.m @@ -144,6 +144,9 @@ { [super _watermarkAction]; + if (self.onWatermarkAction != nil) + self.onWatermarkAction(); + NSString *permalink = _permalink; NSString *coubId = nil; if ([_asset isKindOfClass:[CBCoubNew class]]) diff --git a/LegacyComponents/TGEmbedPlayerView.h b/LegacyComponents/TGEmbedPlayerView.h index 9fb8ec1ac6..2178838cf5 100644 --- a/LegacyComponents/TGEmbedPlayerView.h +++ b/LegacyComponents/TGEmbedPlayerView.h @@ -40,6 +40,8 @@ @property (nonatomic, assign) CGRect initialFrame; +@property (nonatomic, copy) void (^onWatermarkAction)(void); + @property (nonatomic, copy) void (^requestFullscreen)(NSTimeInterval duration); @property (nonatomic, copy) void (^onMetadataLoaded)(NSString *title, NSString *subtitle); diff --git a/LegacyComponents/TGEmbedPlayerView.m b/LegacyComponents/TGEmbedPlayerView.m index c2462cd293..9d4430164b 100644 --- a/LegacyComponents/TGEmbedPlayerView.m +++ b/LegacyComponents/TGEmbedPlayerView.m @@ -199,7 +199,6 @@ [_jsQueue dispatchSync:^ { wkWebView.navigationDelegate = nil; - [wkWebView removeObserver:self forKeyPath:@"estimatedProgress"]; }]; _uiWebView.delegate = nil; @@ -466,15 +465,6 @@ else [_wkWebView loadHTMLString:embedHTML baseURL:[self _baseURL]]; }]; - - [_wkWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:NULL]; -} - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"estimatedProgress"] && object == _wkWebView) - return; - else - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } - (void)webView:(WKWebView *)__unused webView didStartProvisionalNavigation:(WKNavigation *)__unused navigation @@ -848,7 +838,6 @@ - (void)_cleanWebView { _wkWebView.navigationDelegate = nil; - [_wkWebView removeObserver:self forKeyPath:@"estimatedProgress"]; [_wkWebView removeFromSuperview]; _wkWebView = nil; diff --git a/LegacyComponents/TGEmbedVinePlayerView.m b/LegacyComponents/TGEmbedVinePlayerView.m index 00035877e9..f112034af8 100644 --- a/LegacyComponents/TGEmbedVinePlayerView.m +++ b/LegacyComponents/TGEmbedVinePlayerView.m @@ -45,6 +45,9 @@ NSString *const TGVinePlayerCallbackOnPlayback = @"onPlayback"; { [super _watermarkAction]; + if (self.onWatermarkAction != nil) + self.onWatermarkAction(); + NSString *videoId = _videoId; NSURL *appUrl = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"vine://post/%@", videoId]]; diff --git a/LegacyComponents/TGEmbedYoutubePlayerView.m b/LegacyComponents/TGEmbedYoutubePlayerView.m index 0bf1a95f67..7d90c0d567 100644 --- a/LegacyComponents/TGEmbedYoutubePlayerView.m +++ b/LegacyComponents/TGEmbedYoutubePlayerView.m @@ -65,10 +65,12 @@ const NSInteger TGYTPlayerStateBufferingCode = 3; { [super _watermarkAction]; + if (self.onWatermarkAction != nil) + self.onWatermarkAction(); + NSString *videoId = _playerParams[@"videoId"]; - NSURL *appUrl = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"youtube-x-callback://watch?v=%@&x-success=telegram://1&x-source=Telegram", videoId]]; - + NSURL *appUrl = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"youtube://watch?v=%@", videoId]]; if ([[LegacyComponentsGlobals provider] canOpenURL:appUrl]) { [[LegacyComponentsGlobals provider] openURL:appUrl]; diff --git a/LegacyComponents/TGMediaAssetsController.h b/LegacyComponents/TGMediaAssetsController.h index 09f8423d4c..add82e9c0a 100644 --- a/LegacyComponents/TGMediaAssetsController.h +++ b/LegacyComponents/TGMediaAssetsController.h @@ -43,6 +43,7 @@ typedef enum @property (nonatomic, strong) TGMediaAssetsPallete *pallete; +@property (nonatomic, readonly) TGMediaEditingContext *editingContext; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; @property (nonatomic, assign) bool localMediaCacheEnabled; @property (nonatomic, assign) bool captionsEnabled; @@ -51,6 +52,7 @@ typedef enum @property (nonatomic, assign) bool shouldStoreAssets; @property (nonatomic, assign) bool hasTimer; @property (nonatomic, assign) bool onlyCrop; +@property (nonatomic, assign) bool inhibitMute; @property (nonatomic, assign) bool liveVideoUploadEnabled; @property (nonatomic, assign) bool shouldShowFileTipIfNeeded; diff --git a/LegacyComponents/TGMediaAssetsController.m b/LegacyComponents/TGMediaAssetsController.m index 506579aee7..0c19a623a0 100644 --- a/LegacyComponents/TGMediaAssetsController.m +++ b/LegacyComponents/TGMediaAssetsController.m @@ -34,7 +34,6 @@ TGMediaPickerToolbarView *_toolbarView; TGMediaSelectionContext *_selectionContext; - TGMediaEditingContext *_editingContext; SMetaDisposable *_groupingChangedDisposable; SMetaDisposable *_selectionChangedDisposable; @@ -117,6 +116,7 @@ pickerController.captionsEnabled = strongController.captionsEnabled; pickerController.allowCaptionEntities = strongController.allowCaptionEntities; pickerController.inhibitDocumentCaptions = strongController.inhibitDocumentCaptions; + pickerController.inhibitMute = strongController.inhibitMute; pickerController.liveVideoUploadEnabled = strongController.liveVideoUploadEnabled; pickerController.catchToolbarView = catchToolbarView; pickerController.recipientName = recipientName; @@ -165,6 +165,12 @@ self.pickerController.inhibitDocumentCaptions = inhibitDocumentCaptions; } +- (void)setInhibitMute:(bool)inhibitMute +{ + _inhibitMute = inhibitMute; + self.pickerController.inhibitMute = inhibitMute; +} + - (void)setLiveVideoUploadEnabled:(bool)liveVideoUploadEnabled { _liveVideoUploadEnabled = liveVideoUploadEnabled; diff --git a/LegacyComponents/TGMediaAssetsMomentsController.m b/LegacyComponents/TGMediaAssetsMomentsController.m index 63af7a59ef..7af2d8dd49 100644 --- a/LegacyComponents/TGMediaAssetsMomentsController.m +++ b/LegacyComponents/TGMediaAssetsMomentsController.m @@ -124,7 +124,7 @@ - (TGMediaPickerModernGalleryMixin *)_galleryMixinForItem:(id)item thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaption allowCaptionEntities:(bool)allowCaptionEntities asFile:(bool)asFile { - return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:item momentList:_momentList parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaption allowCaptionEntities:allowCaptionEntities hasTimer:false onlyCrop:false inhibitDocumentCaptions:false asFile:asFile itemsLimit:0]; + return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:item momentList:_momentList parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaption allowCaptionEntities:allowCaptionEntities hasTimer:false onlyCrop:false inhibitDocumentCaptions:false inhibitMute:false asFile:asFile itemsLimit:0]; } - (id)_itemAtIndexPath:(NSIndexPath *)indexPath diff --git a/LegacyComponents/TGMediaAssetsPickerController.m b/LegacyComponents/TGMediaAssetsPickerController.m index a6b1d3e18d..7c8645c232 100644 --- a/LegacyComponents/TGMediaAssetsPickerController.m +++ b/LegacyComponents/TGMediaAssetsPickerController.m @@ -258,7 +258,7 @@ return TGMediaAssetsVideoCellKind; case TGMediaAssetGifType: - if (_intent == TGMediaAssetsControllerSetProfilePhotoIntent || _intent == TGMediaAssetsControllerPassportIntent || TGMediaAssetsControllerPassportMultipleIntent) + if (_intent == TGMediaAssetsControllerSetProfilePhotoIntent || _intent == TGMediaAssetsControllerPassportIntent || _intent == TGMediaAssetsControllerPassportMultipleIntent) return TGMediaAssetsPhotoCellKind; else return TGMediaAssetsGifCellKind; @@ -321,7 +321,7 @@ - (TGMediaPickerModernGalleryMixin *)_galleryMixinForContext:(id)context item:(id)item thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile { - return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:context item:item fetchResult:_fetchResult parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions asFile:asFile itemsLimit:0 recipientName:self.recipientName]; + return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:context item:item fetchResult:_fetchResult parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:asFile itemsLimit:0 recipientName:self.recipientName]; } - (TGMediaPickerModernGalleryMixin *)galleryMixinForIndexPath:(NSIndexPath *)indexPath previewMode:(bool)previewMode outAsset:(TGMediaAsset **)outAsset diff --git a/LegacyComponents/TGMediaPickerController.h b/LegacyComponents/TGMediaPickerController.h index 535ad2b7be..ae94634486 100644 --- a/LegacyComponents/TGMediaPickerController.h +++ b/LegacyComponents/TGMediaPickerController.h @@ -25,6 +25,7 @@ @property (nonatomic, assign) bool shouldStoreAssets; @property (nonatomic, assign) bool hasTimer; @property (nonatomic, assign) bool onlyCrop; +@property (nonatomic, assign) bool inhibitMute; @property (nonatomic, strong) NSString *recipientName; @property (nonatomic, strong) TGMediaAssetsPallete *pallete; diff --git a/LegacyComponents/TGMediaPickerGalleryInterfaceView.h b/LegacyComponents/TGMediaPickerGalleryInterfaceView.h index 58ebb565aa..b5ddb60a80 100644 --- a/LegacyComponents/TGMediaPickerGalleryInterfaceView.h +++ b/LegacyComponents/TGMediaPickerGalleryInterfaceView.h @@ -27,6 +27,7 @@ @property (nonatomic, assign) bool usesSimpleLayout; @property (nonatomic, assign) bool hasSwipeGesture; @property (nonatomic, assign) bool usesFadeOutForDismissal; +@property (nonatomic, assign) bool inhibitMute; @property (nonatomic, assign) bool capturing; diff --git a/LegacyComponents/TGMediaPickerGalleryInterfaceView.m b/LegacyComponents/TGMediaPickerGalleryInterfaceView.m index 9ee9ac82f1..09aac3f5fc 100644 --- a/LegacyComponents/TGMediaPickerGalleryInterfaceView.m +++ b/LegacyComponents/TGMediaPickerGalleryInterfaceView.m @@ -557,7 +557,7 @@ [strongSelf->_portraitToolbarView setEditButtonsEnabled:available animated:true]; [strongSelf->_landscapeToolbarView setEditButtonsEnabled:available animated:true]; - bool sendableAsGif = [strongItemView isKindOfClass:[TGMediaPickerGalleryVideoItemView class]]; + bool sendableAsGif = !strongSelf->_inhibitMute && [strongItemView isKindOfClass:[TGMediaPickerGalleryVideoItemView class]]; strongSelf->_muteButton.hidden = !sendableAsGif; } }]]; diff --git a/LegacyComponents/TGMediaPickerGalleryModel.h b/LegacyComponents/TGMediaPickerGalleryModel.h index 27eb8596c9..e6bc5c8cb4 100644 --- a/LegacyComponents/TGMediaPickerGalleryModel.h +++ b/LegacyComponents/TGMediaPickerGalleryModel.h @@ -34,6 +34,8 @@ @property (nonatomic, assign) bool useGalleryImageAsEditableItemImage; @property (nonatomic, weak) TGModernGalleryController *controller; +@property (nonatomic, assign) bool inhibitMute; + @property (nonatomic, readonly, strong) TGMediaPickerGalleryInterfaceView *interfaceView; @property (nonatomic, readonly, strong) TGMediaPickerGallerySelectedItemsModel *selectedItemsModel; diff --git a/LegacyComponents/TGMediaPickerGalleryModel.m b/LegacyComponents/TGMediaPickerGalleryModel.m index 09cff732b2..30da4ced5a 100644 --- a/LegacyComponents/TGMediaPickerGalleryModel.m +++ b/LegacyComponents/TGMediaPickerGalleryModel.m @@ -189,6 +189,7 @@ _interfaceView.hasTimer = _hasTimer; _interfaceView.onlyCrop = _onlyCrop; _interfaceView.inhibitDocumentCaptions = _inhibitDocumentCaptions; + _interfaceView.inhibitMute = _inhibitMute; [_interfaceView setEditorTabPressed:^(TGPhotoEditorTab tab) { __strong TGMediaPickerGalleryModel *strongSelf = weakSelf; diff --git a/LegacyComponents/TGMediaPickerGalleryVideoItemView.m b/LegacyComponents/TGMediaPickerGalleryVideoItemView.m index 0f0ef49945..08035e03dc 100644 --- a/LegacyComponents/TGMediaPickerGalleryVideoItemView.m +++ b/LegacyComponents/TGMediaPickerGalleryVideoItemView.m @@ -533,7 +533,7 @@ }; if (_scrubberView.frame.size.width < FLT_EPSILON) - TGDispatchAfter(0.01, dispatch_get_main_queue(), block); + TGDispatchAfter(0.05, dispatch_get_main_queue(), block); else block(); } diff --git a/LegacyComponents/TGMediaPickerModernGalleryMixin.h b/LegacyComponents/TGMediaPickerModernGalleryMixin.h index 86355e3fd3..8fdcba0740 100644 --- a/LegacyComponents/TGMediaPickerModernGalleryMixin.h +++ b/LegacyComponents/TGMediaPickerModernGalleryMixin.h @@ -27,9 +27,9 @@ @property (nonatomic, copy) void (^editorOpened)(void); @property (nonatomic, copy) void (^editorClosed)(void); -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName; -- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit; +- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit; - (void)present; - (void)updateWithFetchResult:(TGMediaAssetFetchResult *)fetchResult; diff --git a/LegacyComponents/TGMediaPickerModernGalleryMixin.m b/LegacyComponents/TGMediaPickerModernGalleryMixin.m index 471d1b51a2..6787388a05 100644 --- a/LegacyComponents/TGMediaPickerModernGalleryMixin.m +++ b/LegacyComponents/TGMediaPickerModernGalleryMixin.m @@ -37,17 +37,17 @@ @implementation TGMediaPickerModernGalleryMixin -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName { - return [self initWithContext:context item:item fetchResult:fetchResult momentList:nil parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions asFile:asFile itemsLimit:itemsLimit recipientName:recipientName]; + return [self initWithContext:context item:item fetchResult:fetchResult momentList:nil parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:recipientName]; } -- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit +- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit { - return [self initWithContext:context item:item fetchResult:nil momentList:momentList parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions asFile:asFile itemsLimit:itemsLimit recipientName:nil]; + return [self initWithContext:context item:item fetchResult:nil momentList:momentList parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:nil]; } -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName { self = [super init]; if (self != nil) @@ -81,6 +81,7 @@ TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:[_windowManager context] items:galleryItems focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions hasSelectionPanel:true hasCamera:false recipientName:recipientName]; _galleryModel = model; + model.inhibitMute = inhibitMute; model.controller = modernGallery; model.suggestionContext = suggestionContext; model.willFinishEditingItem = ^(id editableItem, id adjustments, id representation, bool hasChanges) diff --git a/LegacyComponents/TGMediaVideoConverter.m b/LegacyComponents/TGMediaVideoConverter.m index bce62cfcb7..a202c11ced 100644 --- a/LegacyComponents/TGMediaVideoConverter.m +++ b/LegacyComponents/TGMediaVideoConverter.m @@ -250,6 +250,9 @@ if (CMTimeCompare(videoComposition.frameDuration, kCMTimeZero) != 1) videoComposition.frameDuration = CMTimeMake(1, 30); + if (!CMTIME_IS_VALID(videoComposition.frameDuration)) + videoComposition.frameDuration = CMTimeMake(1, 30); + videoComposition.renderSize = [self _renderSizeWithCropSize:cropRect.size rotateSideward:TGOrientationIsSideward(adjustments.cropOrientation, NULL)]; AVMutableCompositionTrack *trimVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; diff --git a/LegacyComponents/TGMessage.h b/LegacyComponents/TGMessage.h index 537028620d..c8a144bf86 100644 --- a/LegacyComponents/TGMessage.h +++ b/LegacyComponents/TGMessage.h @@ -39,6 +39,7 @@ typedef enum { } TGMessageDeliveryState; #define TGMessageLocalMidBaseline 800000000 +#define TGMessageLocalMidEditBaseline 900000000 typedef struct { uint8_t key[8 + 1 + 4 + 4]; diff --git a/LegacyComponents/TGModernGalleryController.m b/LegacyComponents/TGModernGalleryController.m index 83a5d81542..5769a9c3b7 100644 --- a/LegacyComponents/TGModernGalleryController.m +++ b/LegacyComponents/TGModernGalleryController.m @@ -642,28 +642,35 @@ } else if (!_previewMode) { - if (_finishedTransitionIn && _model.focusItem != nil) - { - TGModernGalleryItemView *itemView = nil; - if (self.finishedTransitionIn && self.model.focusItem != nil) + if (_startedTransitionIn) { + _startedTransitionIn(); + } + + [_view simpleTransitionInWithCompletion: + ^{ + if (_finishedTransitionIn && _model.focusItem != nil) { - for (TGModernGalleryItemView *visibleItemView in self->_visibleItemViews) + TGModernGalleryItemView *itemView = nil; + if (self.finishedTransitionIn && self.model.focusItem != nil) { - if ([visibleItemView.item isEqual:self.model.focusItem]) + for (TGModernGalleryItemView *visibleItemView in self->_visibleItemViews) { - itemView = visibleItemView; - - break; + if ([visibleItemView.item isEqual:self.model.focusItem]) + { + itemView = visibleItemView; + + break; + } } } + + _finishedTransitionIn(_model.focusItem, itemView); + + [_model _transitionCompleted]; } - - _finishedTransitionIn(_model.focusItem, itemView); - - [_model _transitionCompleted]; - } - else - [_model _transitionCompleted]; + else + [_model _transitionCompleted]; + }]; [_view transitionInWithDuration:0.15]; diff --git a/LegacyComponents/TGModernGalleryView.h b/LegacyComponents/TGModernGalleryView.h index 923ae55d35..f4047a7591 100644 --- a/LegacyComponents/TGModernGalleryView.h +++ b/LegacyComponents/TGModernGalleryView.h @@ -30,6 +30,7 @@ - (void)addItemFooterView:(UIView *)itemFooterView; - (void)removeItemFooterView:(UIView *)itemFooterView; +- (void)simpleTransitionInWithCompletion:(void (^)())completion; - (void)simpleTransitionOutWithVelocity:(CGFloat)velocity completion:(void (^)())completion; - (void)transitionInWithDuration:(NSTimeInterval)duration; - (void)transitionOutWithDuration:(NSTimeInterval)duration; diff --git a/LegacyComponents/TGModernGalleryView.m b/LegacyComponents/TGModernGalleryView.m index 8368297395..b9ccd8f6f8 100644 --- a/LegacyComponents/TGModernGalleryView.m +++ b/LegacyComponents/TGModernGalleryView.m @@ -329,25 +329,60 @@ static const CGFloat swipeDistanceThreshold = 128.0f; self.transitionProgress(transitionProgress, manual); } +- (void)simpleTransitionInWithCompletion:(void (^)())completion +{ + CGFloat velocity = 2000.0f; + CGFloat distance = (velocity < FLT_EPSILON ? -1.0f : 1.0f) * self.frame.size.height; + + CGRect targetFrame = _scrollView.frame; + CGRect targetInterfaceFrame = _interfaceView.frame; + CGRect interfaceViewFrame = (CGRect){{_interfaceView.frame.origin.x, distance}, _interfaceView.frame.size}; + CGRect scrollViewFrame = (CGRect){{_scrollView.frame.origin.x, distance}, _scrollView.frame.size}; + _interfaceView.frame = interfaceViewFrame; + _scrollView.frame = scrollViewFrame; + _overlayContainerView.alpha = 0.0f; + self.backgroundColor = UIColorRGBA(0x000000, 0.0f); + + [UIView animateWithDuration:ABS(distance / velocity) delay:0.0 options:7 << 16 animations:^{ + _scrollView.frame = targetFrame; + _interfaceView.frame = targetInterfaceFrame; + } completion:^(__unused BOOL finished) + { + if (completion) + completion(); + }]; + + [UIView animateWithDuration:ABS(distance / velocity) animations:^ + { + _overlayContainerView.alpha = 1.0f; + self.backgroundColor = UIColorRGBA(0x000000, 1.0f); + } completion:nil]; +} + - (void)simpleTransitionOutWithVelocity:(CGFloat)velocity completion:(void (^)())completion { const CGFloat minVelocity = 2000.0f; if (ABS(velocity) < minVelocity) velocity = (velocity < 0.0f ? -1.0f : 1.0f) * minVelocity; CGFloat distance = (velocity < FLT_EPSILON ? -1.0f : 1.0f) * self.frame.size.height; + CGRect interfaceViewFrame = (CGRect){{_interfaceView.frame.origin.x, distance}, _interfaceView.frame.size}; CGRect scrollViewFrame = (CGRect){{_scrollView.frame.origin.x, distance}, _scrollView.frame.size}; - [UIView animateWithDuration:ABS(distance / velocity) animations:^ - { + [UIView animateWithDuration:ABS(distance / velocity) delay:0.0 options:7 << 16 animations:^{ _scrollView.frame = scrollViewFrame; - _interfaceView.alpha = 0.0f; - _overlayContainerView.alpha = 0.0f; - self.backgroundColor = UIColorRGBA(0x000000, 0.0f); + _interfaceView.frame = interfaceViewFrame; } completion:^(__unused BOOL finished) { if (completion) completion(); }]; + + [UIView animateWithDuration:ABS(distance / velocity) animations:^ + { + _interfaceView.alpha = 0.0f; + _overlayContainerView.alpha = 0.0f; + self.backgroundColor = UIColorRGBA(0x000000, 0.0f); + } completion:nil]; } - (void)transitionInWithDuration:(NSTimeInterval)duration diff --git a/LegacyComponents/TGPhotoVideoEditor.h b/LegacyComponents/TGPhotoVideoEditor.h index f66cfa6248..ff8cfd650c 100644 --- a/LegacyComponents/TGPhotoVideoEditor.h +++ b/LegacyComponents/TGPhotoVideoEditor.h @@ -2,6 +2,6 @@ @interface TGPhotoVideoEditor : NSObject -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion; ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion; @end diff --git a/LegacyComponents/TGPhotoVideoEditor.m b/LegacyComponents/TGPhotoVideoEditor.m index a31a5ada6d..47ce3aef36 100644 --- a/LegacyComponents/TGPhotoVideoEditor.m +++ b/LegacyComponents/TGPhotoVideoEditor.m @@ -10,12 +10,13 @@ @implementation TGPhotoVideoEditor -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion { id windowManager = [context makeOverlayWindowManager]; id windowContext = [windowManager context]; TGMediaEditingContext *editingContext = [[TGMediaEditingContext alloc] init]; + [editingContext setForcedCaption:caption entities:entities]; TGModernGalleryController *galleryController = [[TGModernGalleryController alloc] initWithContext:windowContext]; galleryController.adjustsStatusBarVisibility = true; @@ -28,7 +29,7 @@ galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:item]; galleryItem.editingContext = editingContext; - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:false allowCaptionEntities:false hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:true allowCaptionEntities:true hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName]; model.controller = galleryController; //model.suggestionContext = self.suggestionContext; @@ -87,48 +88,18 @@ }]; }; -// CGSize snapshotSize = TGScaleToFill(CGSizeMake(480, 640), CGSizeMake(self.view.frame.size.width, self.view.frame.size.width)); -// UIView *snapshotView = [_previewView snapshotViewAfterScreenUpdates:false]; -// snapshotView.contentMode = UIViewContentModeScaleAspectFill; -// snapshotView.frame = CGRectMake(_previewView.center.x - snapshotSize.width / 2, _previewView.center.y - snapshotSize.height / 2, snapshotSize.width, snapshotSize.height); -// snapshotView.hidden = true; -// [_previewView.superview insertSubview:snapshotView aboveSubview:_previewView]; - galleryController.beginTransitionIn = ^UIView *(__unused TGMediaPickerGalleryItem *item, __unused TGModernGalleryItemView *itemView) { - TGModernGalleryController *strongGalleryController = weakGalleryController; - strongGalleryController.view.alpha = 0.0f; - [UIView animateWithDuration:0.3f animations:^ - { - strongGalleryController.view.alpha = 1.0f; - }]; - //return snapshotView; return nil; }; galleryController.beginTransitionOut = ^UIView *(__unused TGMediaPickerGalleryItem *item, __unused TGModernGalleryItemView *itemView) { -// __strong TGCameraController *strongSelf = weakSelf; -// if (strongSelf != nil) -// { - TGMediaPickerGalleryModel *strongModel = weakModel; - if (strongModel == nil) - return nil; - -// [UIView animateWithDuration:0.3f delay:0.1f options:UIViewAnimationOptionCurveLinear animations:^ -// { -// strongSelf->_interfaceView.alpha = 1.0f; -// } completion:nil]; - -// return snapshotView; -// } return nil; }; galleryController.completedTransitionOut = ^ { - //[snapshotView removeFromSuperview]; - TGModernGalleryController *strongGalleryController = weakGalleryController; if (strongGalleryController != nil && strongGalleryController.overlayWindow == nil) { @@ -141,7 +112,6 @@ TGOverlayControllerWindow *controllerWindow = [[TGOverlayControllerWindow alloc] initWithManager:windowManager parentController:controller contentController:galleryController]; controllerWindow.hidden = false; - //controllerWindow.windowLevel = self.view.window.windowLevel + 0.0001f; galleryController.view.clipsToBounds = true; } diff --git a/LegacyComponents/UIScrollView+TGHacks.m b/LegacyComponents/UIScrollView+TGHacks.m index a5ea5eed0a..9e614a14d4 100644 --- a/LegacyComponents/UIScrollView+TGHacks.m +++ b/LegacyComponents/UIScrollView+TGHacks.m @@ -6,10 +6,13 @@ - (void)stopScrollingAnimation { - UIView *superview = self.superview; - NSUInteger index = [self.superview.subviews indexOfObject:self]; - [self removeFromSuperview]; - [superview insertSubview:self atIndex:index]; + CGPoint offset = self.contentOffset; + [self setContentOffset:offset animated:false]; + +// UIView *superview = self.superview; +// NSUInteger index = [self.superview.subviews indexOfObject:self]; +// [self removeFromSuperview]; +// [superview insertSubview:self atIndex:index]; } @end