From e2290bbeda7f16ed9a6a4b9de716ac8a37bb5d2f Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 7 Jun 2018 17:28:41 +0300 Subject: [PATCH] no message --- LegacyComponents/PGCamera.h | 2 + LegacyComponents/PGCamera.m | 2 +- LegacyComponents/TGCameraController.h | 3 +- LegacyComponents/TGCameraController.m | 4 +- LegacyComponents/TGModernBarButton.h | 2 + LegacyComponents/TGModernBarButton.m | 12 ++ LegacyComponents/TGModernGalleryController.m | 2 +- LegacyComponents/TGPassportAttachMenu.m | 130 +++++++++++-------- LegacyComponents/TGPassportScanView.m | 2 +- LegacyComponents/TGWebDocument.m | 2 +- 10 files changed, 99 insertions(+), 62 deletions(-) diff --git a/LegacyComponents/PGCamera.h b/LegacyComponents/PGCamera.h index 0f2c2d1e05..f71462efdf 100644 --- a/LegacyComponents/PGCamera.h +++ b/LegacyComponents/PGCamera.h @@ -82,6 +82,8 @@ typedef enum @property (nonatomic, readonly) bool isZoomAvailable; @property (nonatomic, assign) CGFloat zoomLevel; +@property (nonatomic, assign) bool disableResultMirroring; + @property (nonatomic, assign) bool disabled; @property (nonatomic, readonly) bool isCapturing; @property (nonatomic, readonly) NSTimeInterval videoRecordingDuration; diff --git a/LegacyComponents/PGCamera.m b/LegacyComponents/PGCamera.m index c5ec07fdcd..3cf6d29e96 100644 --- a/LegacyComponents/PGCamera.m +++ b/LegacyComponents/PGCamera.m @@ -348,7 +348,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus"; - (void)takePhotoWithCompletion:(void (^)(UIImage *result, PGCameraShotMetadata *metadata))completion { - bool videoMirrored = _previewView.captureConnection.videoMirrored; + bool videoMirrored = !self.disableResultMirroring ? _previewView.captureConnection.videoMirrored : false; [[PGCamera cameraQueue] dispatch:^ { diff --git a/LegacyComponents/TGCameraController.h b/LegacyComponents/TGCameraController.h index 036e147e65..c6c84d211e 100644 --- a/LegacyComponents/TGCameraController.h +++ b/LegacyComponents/TGCameraController.h @@ -14,7 +14,8 @@ typedef enum { TGCameraControllerGenericIntent, TGCameraControllerPassportIntent, TGCameraControllerPassportIdIntent, - TGCameraControllerAvatarIntent, + TGCameraControllerPassportMultipleIntent, + TGCameraControllerAvatarIntent } TGCameraControllerIntent; @interface TGCameraControllerWindow : TGOverlayControllerWindow diff --git a/LegacyComponents/TGCameraController.m b/LegacyComponents/TGCameraController.m index 708ba11645..f17a56c193 100644 --- a/LegacyComponents/TGCameraController.m +++ b/LegacyComponents/TGCameraController.m @@ -1227,8 +1227,8 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus } }]; - bool hasCamera = (_intent == TGCameraControllerGenericIntent && !_shortcut) || (_intent == TGCameraControllerPassportIntent || _intent == TGCameraControllerPassportIdIntent); - 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 inhibitDocumentCaptions:self.inhibitDocumentCaptions hasSelectionPanel:true hasCamera:hasCamera recipientName:self.recipientName]; + bool hasCamera = (_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.controller = galleryController; model.suggestionContext = self.suggestionContext; diff --git a/LegacyComponents/TGModernBarButton.h b/LegacyComponents/TGModernBarButton.h index 51f36cddae..0556e56048 100644 --- a/LegacyComponents/TGModernBarButton.h +++ b/LegacyComponents/TGModernBarButton.h @@ -5,6 +5,8 @@ @property (nonatomic) CGPoint portraitAdjustment; @property (nonatomic) CGPoint landscapeAdjustment; +@property (nonatomic, strong) UIImage *image; + - (instancetype)initWithImage:(UIImage *)image; @end diff --git a/LegacyComponents/TGModernBarButton.m b/LegacyComponents/TGModernBarButton.m index 958b62d138..5653419492 100644 --- a/LegacyComponents/TGModernBarButton.m +++ b/LegacyComponents/TGModernBarButton.m @@ -22,6 +22,18 @@ return self; } +- (UIImage *)image +{ + return _iconView.image; +} + +- (void)setImage:(UIImage *)image +{ + _iconView.image = image; + _iconView.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height); + [self setNeedsLayout]; +} + - (UIEdgeInsets)alignmentRectInsets { UIEdgeInsets insets = UIEdgeInsetsZero; diff --git a/LegacyComponents/TGModernGalleryController.m b/LegacyComponents/TGModernGalleryController.m index c221f9025e..83a5d81542 100644 --- a/LegacyComponents/TGModernGalleryController.m +++ b/LegacyComponents/TGModernGalleryController.m @@ -715,7 +715,7 @@ - (UIView *)findScrollView:(UIView *)view { - if (view == nil || [view isKindOfClass:[UIScrollView class]]) + if (view == nil || ([view isKindOfClass:[UIScrollView class]] && view.tag != 0xbeef)) return view; return [self findScrollView:view.superview]; diff --git a/LegacyComponents/TGPassportAttachMenu.m b/LegacyComponents/TGPassportAttachMenu.m index cb297e3247..63da0e45e1 100644 --- a/LegacyComponents/TGPassportAttachMenu.m +++ b/LegacyComponents/TGPassportAttachMenu.m @@ -51,7 +51,7 @@ __weak TGMenuSheetController *weakController = controller; __weak TGViewController *weakParentController = parentController; - TGAttachmentCarouselItemView *carouselItem = [[TGAttachmentCarouselItemView alloc] initWithContext:context camera:true selfPortrait:intent == TGPassportAttachIntentSelfie forProfilePhoto:false assetType:TGMediaAssetPhotoType saveEditedPhotos:false allowGrouping:false allowSelection:false allowEditing:true document:true]; + TGAttachmentCarouselItemView *carouselItem = [[TGAttachmentCarouselItemView alloc] initWithContext:context camera:true selfPortrait:intent == TGPassportAttachIntentSelfie forProfilePhoto:false assetType:TGMediaAssetPhotoType saveEditedPhotos:false allowGrouping:false allowSelection:intent == TGPassportAttachIntentMultiple allowEditing:true document:true]; __weak TGAttachmentCarouselItemView *weakCarouselItem = carouselItem; carouselItem.onlyCrop = true; carouselItem.parentController = parentController; @@ -75,7 +75,7 @@ __strong TGAttachmentCarouselItemView *strongCarouselItem = weakCarouselItem; - uploadAction([TGPassportAttachMenu resultSignalForEditingContext:strongCarouselItem.editingContext currentItem:(id)currentItem], + uploadAction([TGPassportAttachMenu resultSignalForEditingContext:strongCarouselItem.editingContext selectionContext:strongCarouselItem.selectionContext currentItem:(id)currentItem], ^{ __strong TGMenuSheetController *strongController = weakController; if (strongController != nil) @@ -223,8 +223,7 @@ __weak TGMediaAssetsController *weakController = controller; controller.singleCompletionBlock = ^(id currentItem, TGMediaEditingContext *editingContext) { - exit(1); - uploadAction([TGPassportAttachMenu resultSignalForEditingContext:editingContext currentItem:(id)currentItem], + uploadAction([TGPassportAttachMenu resultSignalForEditingContext:editingContext selectionContext:nil currentItem:(id)currentItem], ^{ __strong TGMediaAssetsController *strongController = weakController; if (strongController != nil && strongController.dismissalBlock != nil) @@ -259,7 +258,7 @@ legacyCameraController.finishedWithImage = ^(UIImage *image) { TGCameraCapturedPhoto *photo = [[TGCameraCapturedPhoto alloc] initWithImage:image metadata:nil]; - uploadAction([TGPassportAttachMenu resultSignalForEditingContext:nil currentItem:photo], ^ + uploadAction([TGPassportAttachMenu resultSignalForEditingContext:nil selectionContext:nil currentItem:photo], ^ { __strong TGViewController *strongParentController = weakParentController; if (strongParentController != nil) @@ -270,7 +269,7 @@ [parentController presentViewController:legacyCameraController animated:true completion:nil]; } -+ (void)_displayCameraWithView:(TGAttachmentCameraView *)cameraView menuController:(TGMenuSheetController *)menuController parentController:(TGViewController *)parentController context:(id)context intent:(bool)intent uploadAction:(void (^)(SSignal *, void (^)(void)))uploadAction ++ (void)_displayCameraWithView:(TGAttachmentCameraView *)cameraView menuController:(TGMenuSheetController *)menuController parentController:(TGViewController *)parentController context:(id)context intent:(TGPassportAttachIntent)intent uploadAction:(void (^)(SSignal *, void (^)(void)))uploadAction { if (![[[LegacyComponentsGlobals provider] accessChecker] checkCameraAuthorizationStatusForIntent:TGCameraAccessIntentDefault alertDismissCompletion:nil]) return; @@ -290,11 +289,22 @@ id windowManager = [context makeOverlayWindowManager]; - if (cameraView.previewView != nil) - controller = [[TGCameraController alloc] initWithContext:[windowManager context] saveEditedPhotos:false saveCapturedMedia:false camera:cameraView.previewView.camera previewView:cameraView.previewView intent:intent == TGPassportAttachIntentIdentityCard ? TGCameraControllerPassportIdIntent : TGCameraControllerPassportIntent]; - else - controller = [[TGCameraController alloc] initWithContext:[windowManager context] saveEditedPhotos:false saveCapturedMedia:false intent:intent == TGPassportAttachIntentIdentityCard ? TGCameraControllerPassportIdIntent : TGCameraControllerPassportIntent]; + TGCameraControllerIntent cameraIntent = TGCameraControllerPassportIntent; + if (intent == TGPassportAttachIntentIdentityCard) + cameraIntent = TGCameraControllerPassportIdIntent; + else if (intent == TGPassportAttachIntentMultiple) + cameraIntent = TGCameraControllerPassportMultipleIntent; + if (cameraView.previewView != nil) + { + if (intent == TGPassportAttachIntentSelfie) + cameraView.previewView.camera.disableResultMirroring = true; + controller = [[TGCameraController alloc] initWithContext:[windowManager context] saveEditedPhotos:false saveCapturedMedia:false camera:cameraView.previewView.camera previewView:cameraView.previewView intent:cameraIntent]; + } + else + { + controller = [[TGCameraController alloc] initWithContext:[windowManager context] saveEditedPhotos:false saveCapturedMedia:false intent:cameraIntent]; + } controller.shouldStoreCapturedAssets = false; TGCameraControllerWindow *controllerWindow = [[TGCameraControllerWindow alloc] initWithManager:windowManager parentController:parentController contentController:controller]; @@ -359,7 +369,7 @@ [strongMenuController dismissAnimated:false]; - uploadAction([TGPassportAttachMenu resultSignalForEditingContext:editingContext currentItem:(id)currentItem],^ + uploadAction([TGPassportAttachMenu resultSignalForEditingContext:editingContext selectionContext:selectionContext currentItem:(id)currentItem],^ { }); }; @@ -388,57 +398,67 @@ [parentController presentViewController:controller animated:true completion:nil]; } -+ (SSignal *)resultSignalForEditingContext:(TGMediaEditingContext *)editingContext currentItem:(id)currentItem ++ (SSignal *)resultSignalForEditingContext:(TGMediaEditingContext *)editingContext selectionContext:(TGMediaSelectionContext *)selectionContext currentItem:(id)currentItem { - SSignal *inlineSignal = nil; - if ([currentItem isKindOfClass:[TGMediaAsset class]]) - inlineSignal = [TGMediaAssetImageSignals imageForAsset:(TGMediaAsset *)currentItem imageType:TGMediaAssetImageTypeScreen size:CGSizeMake(2048, 2048) allowNetworkAccess:false]; - else if ([currentItem isKindOfClass:[TGCameraCapturedPhoto class]]) - inlineSignal = [currentItem originalImageSignal:0.0]; - - SSignal *assetSignal = inlineSignal; - SSignal *imageSignal = assetSignal; - if (editingContext != nil) + SSignal *signal = [SSignal complete]; + NSMutableArray *selectedItems = selectionContext.selectedItems ? [selectionContext.selectedItems mutableCopy] : [[NSMutableArray alloc] init]; + if (selectedItems.count == 0 && currentItem != nil) + [selectedItems addObject:currentItem]; + + for (id item in selectedItems) { - imageSignal = [[[[[editingContext imageSignalForItem:currentItem withUpdates:true] filter:^bool(id result) + SSignal *inlineSignal = nil; + if ([item isKindOfClass:[TGMediaAsset class]]) + inlineSignal = [TGMediaAssetImageSignals imageForAsset:(TGMediaAsset *)item imageType:TGMediaAssetImageTypeScreen size:CGSizeMake(2048, 2048) allowNetworkAccess:false]; + else if ([item isKindOfClass:[TGCameraCapturedPhoto class]]) + inlineSignal = [item originalImageSignal:0.0]; + + SSignal *assetSignal = inlineSignal; + SSignal *imageSignal = assetSignal; + if (editingContext != nil) { - return result == nil || ([result isKindOfClass:[UIImage class]] && !((UIImage *)result).degraded); - }] take:1] mapToSignal:^SSignal *(id result) + imageSignal = [[[[[editingContext imageSignalForItem:item withUpdates:true] filter:^bool(id result) + { + return result == nil || ([result isKindOfClass:[UIImage class]] && !((UIImage *)result).degraded); + }] take:1] mapToSignal:^SSignal *(id result) + { + if (result == nil) + { + return [SSignal fail:nil]; + } + else if ([result isKindOfClass:[UIImage class]]) + { + UIImage *image = (UIImage *)result; + image.edited = true; + return [SSignal single:image]; + } + + return [SSignal complete]; + }] onCompletion:^ + { + __strong TGMediaEditingContext *strongEditingContext = editingContext; + [strongEditingContext description]; + }]; + } + + signal = [signal then:[[imageSignal catch:^SSignal *(__unused id error) { - if (result == nil) - { - return [SSignal fail:nil]; - } - else if ([result isKindOfClass:[UIImage class]]) - { - UIImage *image = (UIImage *)result; - image.edited = true; - return [SSignal single:image]; - } + return inlineSignal; + }] map:^id(UIImage *image) + { + CGFloat maxSide = 2048.0f; + CGSize imageSize = TGFitSize(image.size, CGSizeMake(maxSide, maxSide)); + UIImage *scaledImage = MAX(image.size.width, image.size.height) > maxSide ? TGScaleImageToPixelSize(image, imageSize) : image; - return [SSignal complete]; - }] onCompletion:^ - { - __strong TGMediaEditingContext *strongEditingContext = editingContext; - [strongEditingContext description]; - }]; + CGFloat thumbnailSide = 60.0f * TGScreenScaling(); + CGSize thumbnailSize = TGFitSize(scaledImage.size, CGSizeMake(thumbnailSide, thumbnailSide)); + UIImage *thumbnailImage = TGScaleImageToPixelSize(scaledImage, thumbnailSize); + + return @{ @"image": scaledImage, @"thumbnail": thumbnailImage }; + }]]; } - return [[imageSignal catch:^SSignal *(__unused id error) - { - return inlineSignal; - }] map:^id(UIImage *image) - { - CGFloat maxSide = 2048.0f; - CGSize imageSize = TGFitSize(image.size, CGSizeMake(maxSide, maxSide)); - UIImage *scaledImage = MAX(image.size.width, image.size.height) > maxSide ? TGScaleImageToPixelSize(image, imageSize) : image; - - CGFloat thumbnailSide = 60.0f * TGScreenScaling(); - CGSize thumbnailSize = TGFitSize(scaledImage.size, CGSizeMake(thumbnailSide, thumbnailSide)); - UIImage *thumbnailImage = TGScaleImageToPixelSize(scaledImage, thumbnailSize); - - return @{ @"image": scaledImage, @"thumbnail": thumbnailImage }; - }]; + return signal; } @end diff --git a/LegacyComponents/TGPassportScanView.m b/LegacyComponents/TGPassportScanView.m index 81b70e14a4..a8683121d1 100644 --- a/LegacyComponents/TGPassportScanView.m +++ b/LegacyComponents/TGPassportScanView.m @@ -45,7 +45,7 @@ { [_camera startCaptureForResume:false completion:nil]; - _timer = [TGTimerTarget scheduledMainThreadTimerWithTarget:self action:@selector(handleNextFrame) interval:1.0 repeat:false]; + _timer = [TGTimerTarget scheduledMainThreadTimerWithTarget:self action:@selector(handleNextFrame) interval:0.5 repeat:false]; } - (void)stop diff --git a/LegacyComponents/TGWebDocument.m b/LegacyComponents/TGWebDocument.m index 7af3c627ab..eb312f0e1a 100644 --- a/LegacyComponents/TGWebDocument.m +++ b/LegacyComponents/TGWebDocument.m @@ -31,7 +31,7 @@ - (instancetype)initWithString:(NSString *)string { if ([string hasPrefix:@"webdoc"]) { - NSData *data = [[NSData alloc] initWithBase64EncodedString:[string substringFromIndex:6] options:0]; + NSData *data = iosMajorVersion() >= 7 ? [[NSData alloc] initWithBase64EncodedString:[string substringFromIndex:6] options:NSDataBase64DecodingIgnoreUnknownCharacters] : [[NSData alloc] initWithBase64Encoding:[string substringFromIndex:6]]; if (data != nil) { PSKeyValueDecoder *decoder = [[PSKeyValueDecoder alloc] initWithData:data]; return [[TGWebDocumentReference alloc] initWithKeyValueCoder:decoder];