diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h index 435dd9db86..da34043911 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h @@ -31,6 +31,8 @@ @property (nonatomic, copy) void (^tabsChanged)(void); +@property (nonatomic, copy) void (^controlVideoPlayback)(bool); + @property (nonatomic, assign) TGPhotoEditorTab availableTabs; @property (nonatomic, assign) TGPhotoEditorTab switchingToTab; diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h index e227d71e44..4d57659d47 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h @@ -20,6 +20,9 @@ @protocol TGPhotoPaintStickersScreen +@property (nonatomic, copy) void(^screenDidAppear)(void); +@property (nonatomic, copy) void(^screenWillDisappear)(void); + - (void)restore; - (void)invalidate; diff --git a/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m b/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m index 74a87116ad..f58bda1b49 100644 --- a/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m +++ b/submodules/LegacyComponents/Sources/TGAttachmentCarouselItemView.m @@ -913,8 +913,14 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; controller.requestOriginalFullSizeImage = ^(id editableItem, NSTimeInterval position) { - if (editableItem.isVideo && [editableItem isKindOfClass:[TGMediaAsset class]]) { - return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + if (editableItem.isVideo) { + if ([editableItem isKindOfClass:[TGMediaAsset class]]) { + return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + } else if ([editableItem isKindOfClass:[TGCameraCapturedVideo class]]) { + return [SSignal single:((TGCameraCapturedVideo *)editableItem).avAsset]; + } else { + return [editableItem originalImageSignal:position]; + } } else { return [editableItem originalImageSignal:position]; } diff --git a/submodules/LegacyComponents/Sources/TGCameraController.m b/submodules/LegacyComponents/Sources/TGCameraController.m index f36ed768b7..2335bb5e64 100644 --- a/submodules/LegacyComponents/Sources/TGCameraController.m +++ b/submodules/LegacyComponents/Sources/TGCameraController.m @@ -1761,7 +1761,17 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus controller.requestOriginalFullSizeImage = ^(id editableItem, NSTimeInterval position) { - return [editableItem originalImageSignal:position]; + if (editableItem.isVideo) { + if ([editableItem isKindOfClass:[TGMediaAsset class]]) { + return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + } else if ([editableItem isKindOfClass:[TGCameraCapturedVideo class]]) { + return [SSignal single:((TGCameraCapturedVideo *)editableItem).avAsset]; + } else { + return [editableItem originalImageSignal:position]; + } + } else { + return [editableItem originalImageSignal:position]; + } }; overlayController = (TGOverlayController *)controller; diff --git a/submodules/LegacyComponents/Sources/TGCameraPhotoPreviewController.m b/submodules/LegacyComponents/Sources/TGCameraPhotoPreviewController.m index 1f88d4701b..3ad5230219 100644 --- a/submodules/LegacyComponents/Sources/TGCameraPhotoPreviewController.m +++ b/submodules/LegacyComponents/Sources/TGCameraPhotoPreviewController.m @@ -1022,7 +1022,17 @@ controller.requestOriginalFullSizeImage = ^(id editableItem, NSTimeInterval position) { - return [editableItem originalImageSignal:position]; + if (editableItem.isVideo) { + if ([editableItem isKindOfClass:[TGMediaAsset class]]) { + return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + } else if ([editableItem isKindOfClass:[TGCameraCapturedVideo class]]) { + return [SSignal single:((TGCameraCapturedVideo *)editableItem).avAsset]; + } else { + return [editableItem originalImageSignal:position]; + } + } else { + return [editableItem originalImageSignal:position]; + } }; [self addChildViewController:controller]; diff --git a/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m b/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m index ce2befac2b..016db19c0c 100644 --- a/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m +++ b/submodules/LegacyComponents/Sources/TGMediaAssetsPickerController.m @@ -430,8 +430,14 @@ controller.requestOriginalFullSizeImage = ^(id editableItem, NSTimeInterval position) { - if (editableItem.isVideo && [editableItem isKindOfClass:[TGMediaAsset class]]) { - return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + if (editableItem.isVideo) { + if ([editableItem isKindOfClass:[TGMediaAsset class]]) { + return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + } else if ([editableItem isKindOfClass:[TGCameraCapturedVideo class]]) { + return [SSignal single:((TGCameraCapturedVideo *)editableItem).avAsset]; + } else { + return [editableItem originalImageSignal:position]; + } } else { return [editableItem originalImageSignal:position]; } diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m index c6d4534d49..7bd0493772 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m @@ -911,12 +911,12 @@ - (bool)shouldDisplayTooltip { - return ![[[NSUserDefaults standardUserDefaults] objectForKey:@"TG_displayedMediaTimerTooltip_v1"] boolValue]; + return ![[[NSUserDefaults standardUserDefaults] objectForKey:@"TG_displayedMediaTimerTooltip_v2"] boolValue]; } - (void)setupTooltip:(CGRect)rect { - if (_tooltipContainerView != nil) + if (_tooltipContainerView != nil || !_hasTimer) return; _tooltipTimer = [TGTimerTarget scheduledMainThreadTimerWithTarget:self action:@selector(tooltipTimerTick) interval:2.5 repeat:false]; @@ -934,7 +934,7 @@ [_tooltipContainerView showMenuFromRect:rect animated:false]; - [[NSUserDefaults standardUserDefaults] setObject:@true forKey:@"TG_displayedMediaTimerTooltip_v1"]; + [[NSUserDefaults standardUserDefaults] setObject:@true forKey:@"TG_displayedMediaTimerTooltip_v2"]; } - (void)tooltipTimerTick diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m index 9942634dac..bd66ccee45 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m @@ -560,8 +560,14 @@ controller.requestOriginalFullSizeImage = ^SSignal *(id editableItem, NSTimeInterval position) { - if (editableItem.isVideo && [editableItem isKindOfClass:[TGMediaAsset class]]) { - return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + if (editableItem.isVideo) { + if ([editableItem isKindOfClass:[TGMediaAsset class]]) { + return [TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)editableItem]; + } else if ([editableItem isKindOfClass:[TGCameraCapturedVideo class]]) { + return [SSignal single:((TGCameraCapturedVideo *)editableItem).avAsset]; + } else { + return [editableItem originalImageSignal:position]; + } } else { return [editableItem originalImageSignal:position]; } diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 5dd2cc4986..72c3bd3dac 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -922,7 +922,16 @@ TGPhotoPaintController *paintController = [[TGPhotoPaintController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView]; paintController.stickersContext = _stickersContext; paintController.toolbarLandscapeSize = TGPhotoEditorToolbarSize; - + paintController.controlVideoPlayback = ^(bool play) { + __strong TGPhotoEditorController *strongSelf = weakSelf; + if (strongSelf == nil) + return; + if (play) { + [strongSelf->_player play]; + } else { + [strongSelf->_player pause]; + } + }; paintController.beginTransitionIn = ^UIView *(CGRect *referenceFrame, UIView **parentView, bool *noTransitionView) { __strong TGPhotoEditorController *strongSelf = weakSelf; diff --git a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m index 6fdb9f1db2..1c76a478c6 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m @@ -1012,10 +1012,21 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; _stickersScreen = _stickersContext.presentStickersController(^(id document, bool animated, UIView *view, CGRect rect) { __strong TGPhotoPaintController *strongSelf = weakSelf; if (strongSelf != nil) { -// UIView *snapshot = [view snapshotViewAfterScreenUpdates:false]; [strongSelf createNewStickerWithDocument:document animated:animated transitionPoint:CGPointZero snapshotView:nil]; } }); + _stickersScreen.screenDidAppear = ^{ + __strong TGPhotoPaintController *strongSelf = weakSelf; + if (strongSelf != nil) { + strongSelf.controlVideoPlayback(false); + } + }; + _stickersScreen.screenWillDisappear = ^{ + __strong TGPhotoPaintController *strongSelf = weakSelf; + if (strongSelf != nil) { + strongSelf.controlVideoPlayback(true); + } + }; } - (void)createNewStickerWithDocument:(id)document animated:(bool)animated transitionPoint:(CGPoint)transitionPoint snapshotView:(UIView *)snapshotView diff --git a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift index c8356aa5f8..fb3b226442 100644 --- a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift +++ b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift @@ -1265,6 +1265,9 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { } } + fileprivate var didAppear: (() -> Void)? + fileprivate var willDisappear: (() -> Void)? + func animateIn() { self.isUserInteractionEnabled = true self.isHidden = false @@ -1273,10 +1276,16 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { self.insertSubnode(hiddenPane, belowSubnode: self.collectionListContainer) } - self.layer.animatePosition(from: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), to: self.layer.position, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring) + self.layer.animatePosition(from: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), to: self.layer.position, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring, completion: { [weak self] _ in + if let strongSelf = self { + strongSelf.didAppear?() + } + }) } func animateOut() { + self.willDisappear?() + self.isUserInteractionEnabled = false self.layer.animatePosition(from: self.layer.position, to: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { [weak self] _ in if let strongSelf = self { @@ -1299,6 +1308,9 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { } final class DrawingStickersScreen: ViewController, TGPhotoPaintStickersScreen { + public var screenDidAppear: (() -> Void)? + public var screenWillDisappear: (() -> Void)? + private let context: AccountContext var selectSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)? @@ -1368,6 +1380,12 @@ final class DrawingStickersScreen: ViewController, TGPhotoPaintStickersScreen { (self.displayNode as! DrawingStickersScreenNode).dismiss = { [weak self] in self?.dismiss() } + (self.displayNode as! DrawingStickersScreenNode).didAppear = { [weak self] in + self?.screenDidAppear?() + } + (self.displayNode as! DrawingStickersScreenNode).willDisappear = { [weak self] in + self?.screenWillDisappear?() + } self._ready.set(self.controllerNode.ready.get()) super.displayNodeDidLoad()