From ddfb4abd54f12707b1d6048e4b9d95b1e8269a3a Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 11 Sep 2017 00:05:31 +0300 Subject: [PATCH] no message --- LegacyComponents/LegacyComponents.h | 1 + .../PGCameraVolumeButtonHandler.m | 4 +- LegacyComponents/TGEmbedPlayerControls.m | 19 ++-- .../TGModernConversationInputMicButton.h | 13 ++- .../TGModernConversationInputMicButton.m | 101 ++++++++++++------ LegacyComponents/TGPhotoEditorUtils.m | 7 +- .../TGVideoMessageCaptureController.h | 3 +- .../TGVideoMessageCaptureController.m | 17 ++- 8 files changed, 115 insertions(+), 50 deletions(-) diff --git a/LegacyComponents/LegacyComponents.h b/LegacyComponents/LegacyComponents.h index 03685d512d..3cb10d82a4 100644 --- a/LegacyComponents/LegacyComponents.h +++ b/LegacyComponents/LegacyComponents.h @@ -294,3 +294,4 @@ FOUNDATION_EXPORT const unsigned char LegacyComponentsVersionString[]; #import #import #import +#import diff --git a/LegacyComponents/PGCameraVolumeButtonHandler.m b/LegacyComponents/PGCameraVolumeButtonHandler.m index 116b7cbddf..f6c60f6039 100644 --- a/LegacyComponents/PGCameraVolumeButtonHandler.m +++ b/LegacyComponents/PGCameraVolumeButtonHandler.m @@ -105,7 +105,9 @@ static void PGButtonHandlerEnableMonitoring(bool enable) - (void)setEnabled:(bool)enabled { _enabled = enabled; - PGButtonHandlerEnableMonitoring(enabled); + TGDispatchOnMainThread(^{ + PGButtonHandlerEnableMonitoring(enabled); + }); } - (void)enableIn:(NSTimeInterval)timeInterval diff --git a/LegacyComponents/TGEmbedPlayerControls.m b/LegacyComponents/TGEmbedPlayerControls.m index 8e84ed8828..52dcf186d2 100644 --- a/LegacyComponents/TGEmbedPlayerControls.m +++ b/LegacyComponents/TGEmbedPlayerControls.m @@ -22,6 +22,7 @@ const CGFloat TGEmbedPlayerControlsPanelHeight = 32.0f; UIButton *_screenAreaButton; UIView *_backgroundView; + UIView *_backgroundContentView; TGModernButton *_playButton; TGModernButton *_pauseButton; @@ -71,21 +72,23 @@ const CGFloat TGEmbedPlayerControlsPanelHeight = 32.0f; [_screenAreaButton addTarget:self action:@selector(screenAreaPressed) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:_screenAreaButton]; - if (TGEmbedPlayerControlsTypeFull) + if (type == TGEmbedPlayerControlsTypeFull) { if (iosMajorVersion() >= 8) { UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]]; _backgroundView = effectView; + _backgroundContentView = effectView.contentView; UIView *whiteView = [[UIView alloc] initWithFrame:effectView.bounds]; whiteView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; whiteView.backgroundColor = UIColorRGBA(0xffffff, 0.3f); - [_backgroundView addSubview:whiteView]; + [effectView.contentView addSubview:whiteView]; } else { _backgroundView = [[UIView alloc] initWithFrame:CGRectZero]; + _backgroundContentView = _backgroundView; } [self addSubview:_backgroundView]; @@ -93,13 +96,13 @@ const CGFloat TGEmbedPlayerControlsPanelHeight = 32.0f; _pauseButton.exclusiveTouch = true; [_pauseButton setImage:TGComponentsImageNamed(@"EmbedVideoPauseIcon") forState:UIControlStateNormal]; [_pauseButton addTarget:self action:@selector(pauseButtonPressed) forControlEvents:UIControlEventTouchUpInside]; - [_backgroundView addSubview:_pauseButton]; + [_backgroundContentView addSubview:_pauseButton]; _playButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0, 0, 38, TGEmbedPlayerControlsPanelHeight)]; _playButton.exclusiveTouch = true; [_playButton setImage:TGComponentsImageNamed(@"EmbedVideoPlayIcon") forState:UIControlStateNormal]; [_playButton addTarget:self action:@selector(playButtonPressed) forControlEvents:UIControlEventTouchUpInside]; - [_backgroundView addSubview:_playButton]; + [_backgroundContentView addSubview:_playButton]; _positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(24.0f, 0, 56.0f, TGEmbedPlayerControlsPanelHeight)]; _positionLabel.backgroundColor = [UIColor clearColor]; @@ -108,7 +111,7 @@ const CGFloat TGEmbedPlayerControlsPanelHeight = 32.0f; _positionLabel.textAlignment = NSTextAlignmentCenter; _positionLabel.textColor = UIColorRGB(0x302e2e); _positionLabel.userInteractionEnabled = false; - [_backgroundView addSubview:_positionLabel]; + [_backgroundContentView addSubview:_positionLabel]; _remainingLabel = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width - 56.0f, 0, 56, TGEmbedPlayerControlsPanelHeight)]; _remainingLabel.backgroundColor = [UIColor clearColor]; @@ -117,13 +120,13 @@ const CGFloat TGEmbedPlayerControlsPanelHeight = 32.0f; _remainingLabel.textAlignment = NSTextAlignmentCenter; _remainingLabel.textColor = UIColorRGB(0x302e2e); _remainingLabel.userInteractionEnabled = false; - [_backgroundView addSubview:_remainingLabel]; + [_backgroundContentView addSubview:_remainingLabel]; _pictureInPictureButton = [[TGModernButton alloc] initWithFrame:CGRectMake(frame.size.width - 45.0f, 0, 45.0f, TGEmbedPlayerControlsPanelHeight)]; _pictureInPictureButton.exclusiveTouch = true; [_pictureInPictureButton setImage:TGComponentsImageNamed(@"EmbedVideoPIPIcon") forState:UIControlStateNormal]; [_pictureInPictureButton addTarget:self action:@selector(pictureInPictureButtonPressed) forControlEvents:UIControlEventTouchUpInside]; - [_backgroundView addSubview:_pictureInPictureButton]; + [_backgroundContentView addSubview:_pictureInPictureButton]; __weak TGEmbedPlayerControls *weakSelf = self; _scrubber = [[TGEmbedPlayerScrubber alloc] initWithFrame:CGRectZero]; @@ -166,7 +169,7 @@ const CGFloat TGEmbedPlayerControlsPanelHeight = 32.0f; } }; [_scrubber setTintColor:UIColorRGB(0x2f2e2e)]; - [_backgroundView addSubview:_scrubber]; + [_backgroundContentView addSubview:_scrubber]; } if (type == TGEmbedPlayerControlsTypeSimple) diff --git a/LegacyComponents/TGModernConversationInputMicButton.h b/LegacyComponents/TGModernConversationInputMicButton.h index 3de4f24371..01d330738e 100644 --- a/LegacyComponents/TGModernConversationInputMicButton.h +++ b/LegacyComponents/TGModernConversationInputMicButton.h @@ -2,6 +2,15 @@ @class TGModernConversationInputMicButton; +@protocol TGModernConversationInputMicButtonPresentation + +- (UIView *)view; +- (void)setUserInteractionEnabled:(bool)enabled; +- (void)present; +- (void)dismiss; + +@end + @protocol TGModernConversationInputMicButtonDelegate @optional @@ -16,18 +25,20 @@ - (bool)micButtonShouldLock; +- (id)micButtonPresenter; + @end @interface TGModernConversationInputMicButton : UIButton @property (nonatomic, weak) id delegate; +@property (nonatomic) CGPoint centerOffset; @property (nonatomic, strong) UIImage *icon; @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, assign) bool blocking; @property (nonatomic, readonly) bool locked; @property (nonatomic) bool fadeDisabled; -@property (nonatomic) bool overlayDisabled; - (void)animateIn; - (void)animateOut; diff --git a/LegacyComponents/TGModernConversationInputMicButton.m b/LegacyComponents/TGModernConversationInputMicButton.m index 3c5445c14c..ece9441806 100644 --- a/LegacyComponents/TGModernConversationInputMicButton.m +++ b/LegacyComponents/TGModernConversationInputMicButton.m @@ -59,6 +59,43 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius @end +@interface TGModernConversationInputMicButtonWindowPresentation : NSObject { + @public + TGModernConversationInputMicWindow *_overlayWindow; +} + +@end + +@implementation TGModernConversationInputMicButtonWindowPresentation + +- (instancetype)init { + self = [super init]; + if (self != nil) { + _overlayWindow = [[TGModernConversationInputMicWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; + _overlayWindow.windowLevel = 1000000000.0f; + _overlayWindow.rootViewController = [[TGModernConversationInputMicButtonOverlayController alloc] init]; + } + return self; +} + +- (UIView *)view { + return _overlayWindow.rootViewController.view; +} + +- (void)setUserInteractionEnabled:(bool)enabled { + _overlayWindow.userInteractionEnabled = enabled; +} + +- (void)present { + _overlayWindow.hidden = false; +} + +- (void)dismiss { + _overlayWindow.hidden = true; +} + +@end + @interface TGModernConversationInputMicButton () { CGPoint _touchLocation; @@ -70,8 +107,6 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius CFAbsoluteTime _lastTouchTime; bool _acceptTouchDownAsTouchUp; - UIWindow *_overlayWindow; - UIImageView *_innerCircleView; UIImageView *_outerCircleView; @@ -97,6 +132,8 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius bool _animatedIn; UIImage *_icon; + + id _presentation; } @end @@ -193,17 +230,14 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius - (void)updateOverlay { - UIView *parentView = nil; - if (_overlayWindow == nil) { - if (!_overlayDisabled) { - parentView = self.superview; - } + if (_presentation == nil) { return; - } else { - parentView = _overlayWindow.rootViewController.view; } + UIView *parentView = [_presentation view]; CGPoint centerPoint = [self.superview convertPoint:self.center toView:parentView]; + centerPoint.x += _centerOffset.x; + centerPoint.y += _centerOffset.y; _innerCircleView.center = centerPoint; _outerCircleView.center = centerPoint; _innerIconWrapperView.center = centerPoint; @@ -220,22 +254,24 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius _animatedIn = true; _animationStartTime = CACurrentMediaTime(); - if (_lockPanelWrapperView == nil) { - _overlayWindow = [[TGModernConversationInputMicWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; - _overlayWindow.windowLevel = 1000000000.0f; - _overlayWindow.rootViewController = [[TGModernConversationInputMicButtonOverlayController alloc] init]; - - __weak TGModernConversationInputMicButton *weakSelf = self; - ((TGModernConversationInputMicWindow *)_overlayWindow).requestedLockedAction = ^ - { - __strong TGModernConversationInputMicButton *strongSelf = weakSelf; - if (strongSelf == nil) - return; + if (_presentation == nil) { + if ([_delegate respondsToSelector:@selector(micButtonPresenter)]) { + _presentation = [_delegate micButtonPresenter]; + } else { + _presentation = [[TGModernConversationInputMicButtonWindowPresentation alloc] init]; + __weak TGModernConversationInputMicButton *weakSelf = self; - id delegate = strongSelf.delegate; - if ([delegate respondsToSelector:@selector(micButtonInteractionRequestedLockedAction)]) - [delegate micButtonInteractionRequestedLockedAction]; - }; + (((TGModernConversationInputMicButtonWindowPresentation *)_presentation)->_overlayWindow).requestedLockedAction = ^ + { + __strong TGModernConversationInputMicButton *strongSelf = weakSelf; + if (strongSelf == nil) + return; + + id delegate = strongSelf.delegate; + if ([delegate respondsToSelector:@selector(micButtonInteractionRequestedLockedAction)]) + [delegate micButtonInteractionRequestedLockedAction]; + }; + } static dispatch_once_t onceToken; static UIImage *panelBackgroundView; @@ -271,7 +307,7 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius _lockPanelWrapperView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 38.0f, 77.0f)]; _lockPanelWrapperView.userInteractionEnabled = false; - [_overlayWindow.rootViewController.view addSubview:_lockPanelWrapperView]; + [[_presentation view] addSubview:_lockPanelWrapperView]; _lockPanelView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 38.0f, 77.0f)]; _lockPanelView.image = panelBackgroundView; @@ -287,11 +323,11 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius _innerCircleView = [[UIImageView alloc] initWithImage:[self innerCircleImage]]; _innerCircleView.alpha = 0.0f; - [_overlayWindow.rootViewController.view addSubview:_innerCircleView]; + [[_presentation view] addSubview:_innerCircleView]; _outerCircleView = [[UIImageView alloc] initWithImage:[self outerCircleImage]]; _outerCircleView.alpha = 0.0f; - [_overlayWindow.rootViewController.view addSubview:_outerCircleView]; + [[_presentation view] addSubview:_outerCircleView]; _innerIconView = [[UIImageView alloc] initWithImage:_icon]; @@ -300,7 +336,7 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius _innerIconWrapperView.userInteractionEnabled = false; [_innerIconWrapperView addSubview:_innerIconView]; - [_overlayWindow.rootViewController.view addSubview:_innerIconWrapperView]; + [[_presentation view] addSubview:_innerIconWrapperView]; _stopButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 38.0f, 38.0f)]; _stopButton.adjustsImageWhenHighlighted = false; @@ -345,11 +381,11 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius _stopButton.userInteractionEnabled = false; _stopButton.alpha = 0.0f; [_stopButton addTarget:self action:@selector(stopPressed) forControlEvents:UIControlEventTouchUpInside]; - [_overlayWindow.rootViewController.view addSubview:_stopButton]; + [[_presentation view] addSubview:_stopButton]; } - _overlayWindow.userInteractionEnabled = _blocking; - _overlayWindow.hidden = false; + [_presentation setUserInteractionEnabled:_blocking]; + [_presentation present]; _stopButton.userInteractionEnabled = false; @@ -423,7 +459,8 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius _stopButton.alpha = 0.0f; } completion:^(BOOL finished) { if (finished || [[[LegacyComponentsGlobals provider] applicationInstance] applicationState] == UIApplicationStateBackground) { - _overlayWindow.hidden = true; + [_presentation dismiss]; + _presentation = nil; } if (_previousIcon != nil) diff --git a/LegacyComponents/TGPhotoEditorUtils.m b/LegacyComponents/TGPhotoEditorUtils.m index 8f0ad36d9f..e0005d879e 100644 --- a/LegacyComponents/TGPhotoEditorUtils.m +++ b/LegacyComponents/TGPhotoEditorUtils.m @@ -467,10 +467,13 @@ UIImageOrientation TGVideoOrientationForAsset(AVAsset *asset, bool *mirrored) if (mirrored != NULL) { - UIView *tempView = [[UIView alloc] init]; + CGFloat scaleX = sqrt(t.a * t.a + t.c * t.c); + CGFloat scaleY = sqrt(t.b * t.b + t.d * t.d); + /*UIView *tempView = [[UIView alloc] init]; tempView.transform = t; CGSize scale = CGSizeMake([[tempView.layer valueForKeyPath: @"transform.scale.x"] floatValue], - [[tempView.layer valueForKeyPath: @"transform.scale.y"] floatValue]); + [[tempView.layer valueForKeyPath: @"transform.scale.y"] floatValue]);*/ + CGSize scale = CGSizeMake(scaleX, scaleY); *mirrored = (scale.width < 0); } diff --git a/LegacyComponents/TGVideoMessageCaptureController.h b/LegacyComponents/TGVideoMessageCaptureController.h index 2cbcc012d6..204e1adf8e 100644 --- a/LegacyComponents/TGVideoMessageCaptureController.h +++ b/LegacyComponents/TGVideoMessageCaptureController.h @@ -20,6 +20,7 @@ @property (nonatomic, copy) void(^onDismiss)(bool isAuto); @property (nonatomic, copy) void(^onStop)(void); @property (nonatomic, copy) void(^onCancel)(void); +@property (nonatomic, copy) void(^didDismiss)(void); - (instancetype)initWithContext:(id)context assets:(TGVideoMessageCaptureControllerAssets *)assets transitionInView:(UIView *(^)())transitionInView parentController:(TGViewController *)parentController controlsFrame:(CGRect)controlsFrame isAlreadyLocked:(bool (^)(void))isAlreadyLocked liveUploadInterface:(id)liveUploadInterface; - (void)buttonInteractionUpdate:(CGPoint)value; @@ -27,7 +28,7 @@ - (void)complete; - (void)dismiss; -- (void)stop; +- (bool)stop; + (void)clearStartImage; diff --git a/LegacyComponents/TGVideoMessageCaptureController.m b/LegacyComponents/TGVideoMessageCaptureController.m index c0151dd82a..07f55fc6a0 100644 --- a/LegacyComponents/TGVideoMessageCaptureController.m +++ b/LegacyComponents/TGVideoMessageCaptureController.m @@ -503,6 +503,10 @@ typedef enum if (_autorotationWasEnabled) [TGViewController enableAutorotation]; + + if (_didDismiss) { + _didDismiss(); + } } - (void)dismiss @@ -557,14 +561,16 @@ typedef enum - (void)setLocked { - ((TGVideoMessageCaptureControllerWindow *)self.view.window).locked = true; + if ([self.view.window isKindOfClass:[TGVideoMessageCaptureControllerWindow class]]) { + ((TGVideoMessageCaptureControllerWindow *)self.view.window).locked = true; + } [_controlsView setLocked]; } -- (void)stop +- (bool)stop { if (!_capturePipeline.isRecording) - return; + return false; if ([self.view.window isKindOfClass:[TGVideoMessageCaptureControllerWindow class]]) { ((TGVideoMessageCaptureControllerWindow *)self.view.window).locked = false; @@ -575,14 +581,15 @@ typedef enum [_activityDisposable dispose]; [self stopRecording]; + return true; } - (void)sendPressed { + [self finishWithURL:_url dimensions:CGSizeMake(240.0f, 240.0f) duration:_duration liveUploadData:_liveUploadData thumbnailImage:_thumbnailImage]; + _automaticDismiss = true; [self dismiss:false]; - - [self finishWithURL:_url dimensions:CGSizeMake(240.0f, 240.0f) duration:_duration liveUploadData:_liveUploadData thumbnailImage:_thumbnailImage]; } - (void)unmutePressed