Video editor fixes

This commit is contained in:
Ilya Laktyushin 2020-05-26 18:11:52 +03:00
parent a2e713e3ff
commit 2d95e415ff
22 changed files with 3809 additions and 3710 deletions

View File

@ -5515,3 +5515,4 @@ Any member of this group will be able to see messages in the channel.";
"Paint.Framed" = "Framed";
"Media.SendingOptionsTooltip" = "Hold this button to send your message with a self-destruct timer.";
"Media.SendWithTimer" = "Send With Timer";

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "ic_lt_timer.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -36,6 +36,7 @@
@property (nonatomic) bool hasSchedule;
@property (nonatomic) bool reminder;
@property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t));
@property (nonatomic, copy) void (^presentTimerController)(void (^)(int32_t));
@property (nonatomic, strong) NSArray *underlyingViews;
@property (nonatomic, assign) bool openEditor;

View File

@ -60,6 +60,7 @@ typedef enum {
@property (nonatomic, copy) void(^customPresentOverlayController)(TGOverlayController *(^)(id<LegacyComponentsContext>));
@property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t));
@property (nonatomic, copy) void (^presentTimerController)(void (^)(int32_t));
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context saveEditedPhotos:(bool)saveEditedPhotos saveCapturedMedia:(bool)saveCapturedMedia;
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context saveEditedPhotos:(bool)saveEditedPhotos saveCapturedMedia:(bool)saveCapturedMedia intent:(TGCameraControllerIntent)intent;

View File

@ -64,6 +64,7 @@ typedef enum
@property (nonatomic, assign) bool hasSchedule;
@property (nonatomic, assign) bool reminder;
@property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t));
@property (nonatomic, copy) void (^presentTimerController)(void (^)(int32_t));
@property (nonatomic, assign) bool liveVideoUploadEnabled;
@property (nonatomic, assign) bool shouldShowFileTipIfNeeded;

View File

@ -34,6 +34,7 @@
@property (nonatomic, assign) bool hasSchedule;
@property (nonatomic, assign) bool reminder;
@property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t));
@property (nonatomic, copy) void (^presentTimerController)(void (^)(int32_t));
@property (nonatomic, strong) TGMediaAssetsPallete *pallete;

View File

@ -30,6 +30,7 @@
@property (nonatomic, copy) void (^editorClosed)(void);
@property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t));
@property (nonatomic, copy) void (^presentTimerController)(void (^)(int32_t));
- (instancetype)initWithContext:(id<LegacyComponentsContext>)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 hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder stickersContext:(id<TGPhotoPaintStickersContext>)stickersContext;

View File

@ -7,8 +7,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) void (^send)(void);
@property (nonatomic, copy) void (^sendSilently)(void);
@property (nonatomic, copy) void (^schedule)(void);
@property (nonatomic, copy) void (^sendWithTimer)(void);
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context isDark:(bool)isDark sendButtonFrame:(CGRect)sendButtonFrame canSendSilently:(bool)canSendSilently canSchedule:(bool)canSchedule reminder:(bool)reminder;
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context isDark:(bool)isDark sendButtonFrame:(CGRect)sendButtonFrame canSendSilently:(bool)canSendSilently canSchedule:(bool)canSchedule reminder:(bool)reminder hasTimer:(bool)hasTimer;
@end

View File

@ -803,6 +803,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500;
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 hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder stickersContext:self.stickersContext];
mixin.presentScheduleController = self.presentScheduleController;
mixin.presentTimerController = self.presentTimerController;
__weak TGAttachmentCarouselItemView *weakSelf = self;
mixin.thumbnailSignalForItem = ^SSignal *(id item)
{

View File

@ -1280,7 +1280,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
}
}
TGMediaPickerSendActionSheetController *controller = [[TGMediaPickerSendActionSheetController alloc] initWithContext:strongSelf->_context isDark:true sendButtonFrame:strongModel.interfaceView.doneButtonFrame canSendSilently:strongSelf->_hasSilentPosting canSchedule:effectiveHasSchedule reminder:strongSelf->_reminder];
TGMediaPickerSendActionSheetController *controller = [[TGMediaPickerSendActionSheetController alloc] initWithContext:strongSelf->_context isDark:true sendButtonFrame:strongModel.interfaceView.doneButtonFrame canSendSilently:strongSelf->_hasSilentPosting canSchedule:effectiveHasSchedule reminder:strongSelf->_reminder hasTimer:strongSelf->_hasTimer];
controller.send = ^{
__strong TGCameraController *strongSelf = weakSelf;
__strong TGMediaPickerGalleryModel *strongModel = weakModel;

View File

@ -127,6 +127,7 @@
pickerController.hasSchedule = strongController.hasSchedule;
pickerController.reminder = strongController.reminder;
pickerController.presentScheduleController = strongController.presentScheduleController;
pickerController.presentTimerController = strongController.presentTimerController;
[strongController pushViewController:pickerController animated:true];
};
[groupsController loadViewIfNeeded];
@ -235,6 +236,11 @@
self.pickerController.presentScheduleController = presentScheduleController;
}
- (void)setPresentTimerController:(void (^)(void (^)(int32_t)))presentTimerController {
_presentTimerController = [presentTimerController copy];
self.pickerController.presentTimerController = presentTimerController;
}
- (void)setOnlyCrop:(bool)onlyCrop
{
_onlyCrop = onlyCrop;
@ -856,7 +862,7 @@
if (adjustments.toolsApplied) {
image = [PGPhotoEditor resultImageForImage:image adjustments:adjustments];
}
UIImage *thumbnailImage = TGPhotoEditorCrop(image, paintingImage, adjustments.cropOrientation, 0, scaledCropRect, adjustments.cropMirrored, TGScaleToFill(asset.dimensions, CGSizeMake(384, 384)), asset.dimensions, true);
UIImage *thumbnailImage = TGPhotoEditorVideoCrop(image, paintingImage, adjustments.cropOrientation, 0, adjustments.cropRect, adjustments.cropMirrored, TGScaleToFill(asset.dimensions, CGSizeMake(384, 384)), adjustments.originalSize, true, true);
if (thumbnailImage != nil) {
dict[@"previewImage"] = thumbnailImage;
}

View File

@ -342,6 +342,7 @@
TGMediaPickerModernGalleryMixin *mixin = [self _galleryMixinForContext:_context item:asset thumbnailImage:thumbnailImage selectionContext:self.selectionContext editingContext:self.editingContext suggestionContext:self.suggestionContext hasCaptions:self.captionsEnabled allowCaptionEntities:self.allowCaptionEntities inhibitDocumentCaptions:self.inhibitDocumentCaptions asFile:asFile];
mixin.presentScheduleController = self.presentScheduleController;
mixin.presentTimerController = self.presentTimerController;
__weak TGMediaAssetsPickerController *weakSelf = self;
mixin.thumbnailSignalForItem = ^SSignal *(id item)
{

View File

@ -167,7 +167,7 @@
}
}
TGMediaPickerSendActionSheetController *controller = [[TGMediaPickerSendActionSheetController alloc] initWithContext:strongSelf->_context isDark:true sendButtonFrame:strongSelf.galleryModel.interfaceView.doneButtonFrame canSendSilently:hasSilentPosting canSchedule:effectiveHasSchedule reminder:reminder];
TGMediaPickerSendActionSheetController *controller = [[TGMediaPickerSendActionSheetController alloc] initWithContext:strongSelf->_context isDark:true sendButtonFrame:strongSelf.galleryModel.interfaceView.doneButtonFrame canSendSilently:hasSilentPosting canSchedule:effectiveHasSchedule reminder:reminder hasTimer:hasTimer];
controller.send = ^{
__strong TGMediaPickerModernGalleryMixin *strongSelf = weakSelf;
if (strongSelf == nil)
@ -204,6 +204,22 @@
strongSelf.completeWithItem(item, false, time);
});
};
controller.sendWithTimer = ^{
__strong TGMediaPickerModernGalleryMixin *strongSelf = weakSelf;
if (strongSelf == nil)
return;
strongSelf.presentScheduleController(^(int32_t time) {
__strong TGMediaPickerModernGalleryMixin *strongSelf = weakSelf;
if (strongSelf == nil)
return;
strongSelf->_galleryModel.dismiss(true, false);
if (strongSelf.completeWithItem != nil)
strongSelf.completeWithItem(item, false, time);
});
};
TGOverlayControllerWindow *controllerWindow = [[TGOverlayControllerWindow alloc] initWithManager:[strongSelf->_context makeOverlayWindowManager] parentController:strongSelf->_parentController contentController:controller];
controllerWindow.hidden = false;

View File

@ -105,6 +105,7 @@
bool _canSendSilently;
bool _canSchedule;
bool _reminder;
bool _hasTimer;
bool _autorotationWasEnabled;
bool _dismissed;
@ -115,12 +116,13 @@
UIView *_separatorView;
TGMediaPickerSendActionSheetItemView *_sendSilentlyButton;
TGMediaPickerSendActionSheetItemView *_scheduleButton;
TGMediaPickerSendActionSheetItemView *_timerButton;
}
@end
@implementation TGMediaPickerSendActionSheetController
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context isDark:(bool)isDark sendButtonFrame:(CGRect)sendButtonFrame canSendSilently:(bool)canSendSilently canSchedule:(bool)canSchedule reminder:(bool)reminder {
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context isDark:(bool)isDark sendButtonFrame:(CGRect)sendButtonFrame canSendSilently:(bool)canSendSilently canSchedule:(bool)canSchedule reminder:(bool)reminder hasTimer:(bool)hasTimer {
self = [super initWithContext:context];
if (self != nil) {
_context = context;
@ -129,6 +131,7 @@
_canSendSilently = canSendSilently;
_canSchedule = canSchedule;
_reminder = reminder;
_hasTimer = hasTimer;
}
return self;
}
@ -158,7 +161,7 @@
__weak TGMediaPickerSendActionSheetController *weakSelf = self;
if (_canSendSilently) {
_sendSilentlyButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(@"Conversation.SendMessage.SendSilently") icon:TGComponentsImageNamed(@"MediaMute") isDark:_isDark isLast:!_canSchedule];
_sendSilentlyButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(@"Conversation.SendMessage.SendSilently") icon:TGComponentsImageNamed(@"MediaMute") isDark:_isDark isLast:!_canSchedule && !_hasTimer];
_sendSilentlyButton.pressed = ^{
__strong TGMediaPickerSendActionSheetController *strongSelf = weakSelf;
[strongSelf sendSilentlyPressed];
@ -167,7 +170,7 @@
}
if (_canSchedule) {
_scheduleButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(_reminder ? @"Conversation.SendMessage.SetReminder" : @"Conversation.SendMessage.ScheduleMessage") icon:TGComponentsImageNamed(@"MediaSchedule") isDark:_isDark isLast:true];
_scheduleButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(_reminder ? @"Conversation.SendMessage.SetReminder" : @"Conversation.SendMessage.ScheduleMessage") icon:TGComponentsImageNamed(@"MediaSchedule") isDark:_isDark isLast:!_hasTimer];
_scheduleButton.pressed = ^{
__strong TGMediaPickerSendActionSheetController *strongSelf = weakSelf;
[strongSelf schedulePressed];
@ -175,6 +178,15 @@
[_containerView addSubview:_scheduleButton];
}
if (_hasTimer) {
_timerButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(@"Media.SendWithTimer") icon:TGTintedImage([UIImage imageNamed:@"Editor/Timer"], [UIColor whiteColor]) isDark:_isDark isLast:true];
_timerButton.pressed = ^{
__strong TGMediaPickerSendActionSheetController *strongSelf = weakSelf;
[strongSelf timerPressed];
};
[_containerView addSubview:_timerButton];
}
TGMediaAssetsPallete *pallete = nil;
if ([[LegacyComponentsGlobals provider] respondsToSelector:@selector(mediaAssetsPallete)])
pallete = [[LegacyComponentsGlobals provider] mediaAssetsPallete];
@ -281,14 +293,20 @@
CGFloat itemHeight = 44.0;
CGFloat containerWidth = 240.0;
CGFloat containerHeight = _canSendSilently && _canSchedule ? itemHeight * 2.0 : itemHeight;
CGFloat containerHeight = (_canSendSilently + _canSchedule + _hasTimer) * itemHeight;
containerWidth = MAX(containerWidth, MAX(_sendSilentlyButton.buttonLabel.frame.size.width, _scheduleButton.buttonLabel.frame.size.width) + 84.0);
if (!_dismissed) {
_containerView.frame = CGRectMake(CGRectGetMaxX(_sendButtonFrame) - containerWidth - 8.0, _sendButtonFrame.origin.y - containerHeight - 4.0, containerWidth, containerHeight);
}
_sendSilentlyButton.frame = CGRectMake(0.0, 0.0, containerWidth, itemHeight);
_scheduleButton.frame = CGRectMake(0.0, containerHeight - itemHeight, containerWidth, itemHeight);
CGFloat offset = 0.0f;
_sendSilentlyButton.frame = CGRectMake(0.0, offset, containerWidth, itemHeight);
offset += _sendSilentlyButton.frame.size.height;
_scheduleButton.frame = CGRectMake(0.0, offset, containerWidth, itemHeight);
offset += _scheduleButton.frame.size.height;
_timerButton.frame = CGRectMake(0.0, offset, containerWidth, itemHeight);
}
- (void)sendPressed {
@ -312,4 +330,11 @@
self.schedule();
}
- (void)timerPressed {
[self animateOut:false];
if (self.sendWithTimer != nil)
self.sendWithTimer();
}
@end

View File

@ -58,6 +58,7 @@ const CGFloat TGPhotoPaintDefaultColorLocation = 1.0f;
UIPanGestureRecognizer *_panGestureRecognizer;
UILongPressGestureRecognizer *_pressGestureRecognizer;
UITapGestureRecognizer *_tapGestureRecognizer;
CGPoint _gestureStartLocation;
@ -92,6 +93,9 @@ const CGFloat TGPhotoPaintDefaultColorLocation = 1.0f;
_pressGestureRecognizer.minimumPressDuration = 0.1;
[self addGestureRecognizer:_pressGestureRecognizer];
_tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self addGestureRecognizer:_tapGestureRecognizer];
_location = [self restoreLastColorLocation];
_weight = 0.08f;
}
@ -316,6 +320,16 @@ const CGFloat TGPhotoPaintDefaultColorLocation = 1.0f;
}
}
- (void)handleTap:(UITapGestureRecognizer *)gestureRecognizer
{
CGPoint location = [gestureRecognizer locationInView:gestureRecognizer.view];
if (!CGRectContainsPoint(_knobView.frame, location))
{
CGFloat colorLocation = MAX(0.0f, MIN(1.0f, self.frame.size.width > self.frame.size.height ? location.x / gestureRecognizer.view.frame.size.width : location.y / gestureRecognizer.view.frame.size.height));
[self setLocation:colorLocation animated:true];
}
}
+ (UIColor *)colorForLocation:(CGFloat)location
{
NSArray *locations = [TGPhotoPaintColorPickerBackground locations];

View File

@ -724,7 +724,7 @@ typedef enum
bool effectiveHasSchedule = true;
TGMediaPickerSendActionSheetController *controller = [[TGMediaPickerSendActionSheetController alloc] initWithContext:_context isDark:self.pallete.isDark sendButtonFrame:[_controlsView convertRect:[_controlsView frameForSendButton] toView:nil] canSendSilently:_canSendSilently canSchedule:_canSchedule reminder:_reminder];
TGMediaPickerSendActionSheetController *controller = [[TGMediaPickerSendActionSheetController alloc] initWithContext:_context isDark:self.pallete.isDark sendButtonFrame:[_controlsView convertRect:[_controlsView frameForSendButton] toView:nil] canSendSilently:_canSendSilently canSchedule:_canSchedule reminder:_reminder hasTimer:false];
__weak TGVideoMessageCaptureController *weakSelf = self;
controller.send = ^{
__strong TGVideoMessageCaptureController *strongSelf = weakSelf;

View File

@ -150,6 +150,11 @@ public func legacyAttachmentMenu(context: AccountContext, peer: Peer, editMediaO
done?(time)
}
}
carouselItem.presentTimerController = { done in
presentSchedulePicker { time in
done?(time)
}
}
carouselItem.sendPressed = { [weak controller, weak carouselItem] currentItem, asFiles, silentPosting, scheduleTime in
if let controller = controller, let carouselItem = carouselItem {
let intent: TGMediaAssetsControllerIntent = asFiles ? TGMediaAssetsControllerSendFileIntent : TGMediaAssetsControllerSendMediaIntent

View File

@ -48,6 +48,11 @@ public func configureLegacyAssetPicker(_ controller: TGMediaAssetsController, co
done?(time)
}
}
controller.presentTimerController = { done in
presentSchedulePicker { time in
done?(time)
}
}
controller.dismissalBlock = {
}
controller.selectionLimitExceeded = {

View File

@ -34,6 +34,11 @@ func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAt
done?(time)
}
}
controller.presentTimerController = { done in
presentSchedulePicker { time in
done?(time)
}
}
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
} else {