diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorController.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorController.h index 7e480079f4..b2406758b0 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorController.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorController.h @@ -34,7 +34,7 @@ typedef enum { @property (nonatomic, copy) UIView *(^beginTransitionIn)(CGRect *referenceFrame, UIView **parentView); @property (nonatomic, copy) void (^finishedTransitionIn)(void); -@property (nonatomic, copy) UIView *(^beginTransitionOut)(CGRect *referenceFrame, UIView **parentView); +@property (nonatomic, copy) UIView *(^beginTransitionOut)(CGRect *referenceFrame, UIView **parentView, bool saving); @property (nonatomic, copy) void (^finishedTransitionOut)(bool saved); @property (nonatomic, copy) void (^onDismiss)(); diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h index bd87dbf0e8..c738996f98 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h @@ -30,7 +30,7 @@ @property (nonatomic, copy) UIView *(^beginTransitionIn)(CGRect *referenceFrame, UIView **parentView, bool *noTransitionView); @property (nonatomic, copy) void(^finishedTransitionIn)(void); -@property (nonatomic, copy) UIView *(^beginTransitionOut)(CGRect *referenceFrame, UIView **parentView); +@property (nonatomic, copy) UIView *(^beginTransitionOut)(CGRect *referenceFrame, UIView **parentView, bool saving); @property (nonatomic, copy) void(^finishedTransitionOut)(void); @property (nonatomic, copy) void (^valuesChanged)(void); diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h index 6e5c165ac0..8c113270c6 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h @@ -6,6 +6,6 @@ + (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSAttributedString *)caption withItem:(id)item paint:(bool)paint adjustments:(bool)adjustments recipientName:(NSString *)recipientName stickersContext:(id)stickersContext fromRect:(CGRect)fromRect mainSnapshot:(UIView *)mainSnapshot snapshots:(NSArray *)snapshots immediate:(bool)immediate appeared:(void (^)(void))appeared completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed; -+ (void)presentEditorWithContext:(id)context controller:(TGViewController *)controller withItem:(id)item cropRect:(CGRect)cropRect adjustments:(id)adjustments referenceView:(UIView *)referenceView completion:(void (^)(UIImage *, id))completion fullSizeCompletion:(void (^)(UIImage *))fullSizeCompletion beginTransitionOut:(void (^)())beginTransitionOut finishTransitionOut:(void (^)())finishTransitionOut; ++ (void)presentEditorWithContext:(id)context controller:(TGViewController *)controller withItem:(id)item cropRect:(CGRect)cropRect adjustments:(id)adjustments referenceView:(UIView *)referenceView completion:(void (^)(UIImage *, id))completion fullSizeCompletion:(void (^)(UIImage *))fullSizeCompletion beginTransitionOut:(void (^)(bool))beginTransitionOut finishTransitionOut:(void (^)())finishTransitionOut; @end diff --git a/submodules/LegacyComponents/Sources/TGCameraController.m b/submodules/LegacyComponents/Sources/TGCameraController.m index 4dc4705dac..182b89cfd7 100644 --- a/submodules/LegacyComponents/Sources/TGCameraController.m +++ b/submodules/LegacyComponents/Sources/TGCameraController.m @@ -2030,7 +2030,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus return imageView; }; - controller.beginTransitionOut = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView) + controller.beginTransitionOut = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView, __unused bool saving) { __strong TGCameraController *strongSelf = weakSelf; if (strongSelf == nil) diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m index c786c20090..6dd0f99aa7 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m @@ -516,7 +516,7 @@ [zoomableItemView reset]; }; - controller.beginTransitionOut = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView) + controller.beginTransitionOut = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView, __unused bool saving) { __strong TGMediaPickerGalleryModel *strongSelf = weakSelf; if (strongSelf == nil) diff --git a/submodules/LegacyComponents/Sources/TGPhotoCropController.m b/submodules/LegacyComponents/Sources/TGPhotoCropController.m index 90760c8b22..d8786151bb 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoCropController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoCropController.m @@ -389,7 +389,7 @@ NSString * const TGPhotoCropOriginalAspectRatio = @"original"; UIView *parentView = nil; if (self.beginTransitionOut != nil) - referenceView = self.beginTransitionOut(&referenceFrame, &parentView); + referenceView = self.beginTransitionOut(&referenceFrame, &parentView, saving); UIView *toTransitionView = nil; CGRect targetFrame = CGRectZero; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m index 497c2548dc..a54c7c0792 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorTabController.m @@ -274,7 +274,7 @@ const CGFloat TGPhotoEditorToolbarSize = 49.0f; } if (self.beginTransitionOut != nil) - referenceView = self.beginTransitionOut(&referenceFrame, &parentView); + referenceView = self.beginTransitionOut(&referenceFrame, &parentView, saving); if (parentView == nil) parentView = referenceView.superview.superview; diff --git a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m index 1dfec01a9e..6956c9ab0f 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m @@ -499,7 +499,13 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize [TGPhotoEditorAnimation performBlock:^(__unused bool allFinished) { - [snapshotView removeFromSuperview]; + if (self.intent == TGPhotoEditorControllerWallpaperIntent) { + TGDispatchAfter(0.3, dispatch_get_main_queue(), ^{ + [snapshotView removeFromSuperview]; + }); + } else { + [snapshotView removeFromSuperview]; + } if (completion != nil) completion(); diff --git a/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m b/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m index 537beec6c3..ae56a52631 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m +++ b/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m @@ -283,7 +283,7 @@ } } -+ (void)presentEditorWithContext:(id)context controller:(TGViewController *)controller withItem:(id)item cropRect:(CGRect)cropRect adjustments:(id)adjustments referenceView:(UIView *)referenceView completion:(void (^)(UIImage *, id))completion fullSizeCompletion:(void (^)(UIImage *))fullSizeCompletion beginTransitionOut:(void (^)())beginTransitionOut finishTransitionOut:(void (^)())finishTransitionOut; ++ (void)presentEditorWithContext:(id)context controller:(TGViewController *)controller withItem:(id)item cropRect:(CGRect)cropRect adjustments:(id)adjustments referenceView:(UIView *)referenceView completion:(void (^)(UIImage *, id))completion fullSizeCompletion:(void (^)(UIImage *))fullSizeCompletion beginTransitionOut:(void (^)(bool))beginTransitionOut finishTransitionOut:(void (^)())finishTransitionOut; { id windowManager = [context makeOverlayWindowManager]; @@ -304,18 +304,16 @@ editorController.dontHideStatusBar = true; editorController.ignoreCropForResult = true; - CGRect fromRect = referenceView.frame;// [referenceView convertRect:referenceView.bounds toView:nil]; + CGRect fromRect = referenceView.frame; editorController.beginTransitionIn = ^UIView *(CGRect *referenceFrame, UIView **parentView) { *referenceFrame = fromRect; *parentView = referenceView.superview; - //UIImageView *imageView = [[UIImageView alloc] initWithFrame:fromRect]; - //imageView.image = image; return referenceView; }; - editorController.beginTransitionOut = ^UIView *(CGRect *referenceFrame, UIView **parentView) + editorController.beginTransitionOut = ^UIView *(CGRect *referenceFrame, UIView **parentView, bool saving) { CGRect startFrame = CGRectZero; if (referenceFrame != NULL) @@ -326,7 +324,7 @@ } if (beginTransitionOut) { - beginTransitionOut(); + beginTransitionOut(saving); } return referenceView; @@ -382,126 +380,6 @@ TGOverlayControllerWindow *controllerWindow = [[TGOverlayControllerWindow alloc] initWithManager:windowManager parentController:controller contentController:editorController]; controllerWindow.hidden = false; controller.view.clipsToBounds = true; - -// TGModernGalleryController *galleryController = [[TGModernGalleryController alloc] initWithContext:windowContext]; -// galleryController.adjustsStatusBarVisibility = true; -// galleryController.animateTransition = false; -// galleryController.finishedTransitionIn = ^(id item, TGModernGalleryItemView *itemView) { -// appeared(); -// }; -// //galleryController.hasFadeOutTransition = true; -// -// id galleryItem = nil; -// if (item.isVideo) -// galleryItem = [[TGMediaPickerGalleryVideoItem alloc] initWithAsset:item]; -// else -// galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:item]; -// galleryItem.editingContext = editingContext; -// galleryItem.stickersContext = stickersContext; -// -// 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.stickersContext = stickersContext; -// -// model.willFinishEditingItem = ^(id editableItem, id adjustments, id representation, bool hasChanges) -// { -// if (hasChanges) -// { -// [editingContext setAdjustments:adjustments forItem:editableItem]; -// [editingContext setTemporaryRep:representation forItem:editableItem]; -// } -// }; -// -// model.didFinishEditingItem = ^(id editableItem, __unused id adjustments, UIImage *resultImage, UIImage *thumbnailImage) -// { -// [editingContext setImage:resultImage thumbnailImage:thumbnailImage forItem:editableItem synchronous:false]; -// }; -// -// model.saveItemCaption = ^(id editableItem, NSAttributedString *caption) -// { -// [editingContext setCaption:caption forItem:editableItem]; -// }; -// -// model.didFinishRenderingFullSizeImage = ^(id editableItem, UIImage *resultImage) -// { -// [editingContext setFullSizeImage:resultImage forItem:editableItem]; -// }; -// -// model.interfaceView.hasSwipeGesture = false; -// galleryController.model = model; -// -// __weak TGModernGalleryController *weakGalleryController = galleryController; -// -// [model.interfaceView updateSelectionInterface:1 counterVisible:false animated:false]; -// model.interfaceView.thumbnailSignalForItem = ^SSignal *(id item) -// { -// return nil; -// }; -// model.interfaceView.donePressed = ^(TGMediaPickerGalleryItem *item) -// { -// __strong TGModernGalleryController *strongController = weakGalleryController; -// if (strongController == nil) -// return; -// -// if ([item isKindOfClass:[TGMediaPickerGalleryVideoItem class]]) -// { -// TGMediaPickerGalleryVideoItemView *itemView = (TGMediaPickerGalleryVideoItemView *)[strongController itemViewForItem:item]; -// [itemView stop]; -// [itemView setPlayButtonHidden:true animated:true]; -// } -// -// if (completion != nil) -// completion(item.asset, editingContext); -// -// [strongController dismissWhenReadyAnimated:true]; -// }; -// -// galleryController.beginTransitionIn = ^UIView *(__unused TGMediaPickerGalleryItem *item, __unused TGModernGalleryItemView *itemView) -// { -// return nil; -// }; -// -// galleryController.beginTransitionOut = ^UIView *(__unused TGMediaPickerGalleryItem *item, __unused TGModernGalleryItemView *itemView) -// { -// return nil; -// }; -// -// galleryController.completedTransitionOut = ^ -// { -// TGModernGalleryController *strongGalleryController = weakGalleryController; -// if (strongGalleryController != nil && strongGalleryController.overlayWindow == nil) -// { -// TGNavigationController *navigationController = (TGNavigationController *)strongGalleryController.navigationController; -// TGOverlayControllerWindow *window = (TGOverlayControllerWindow *)navigationController.view.window; -// if ([window isKindOfClass:[TGOverlayControllerWindow class]]) -// [window dismiss]; -// } -// if (dismissed) { -// dismissed(); -// } -// }; -// -// if (paint || adjustments) { -// [model.interfaceView immediateEditorTransitionIn]; -// } -// -// for (UIView *view in snapshots) { -// [galleryController.view addSubview:view]; -// } -// -// TGOverlayControllerWindow *controllerWindow = [[TGOverlayControllerWindow alloc] initWithManager:windowManager parentController:controller contentController:galleryController]; -// controllerWindow.hidden = false; -// galleryController.view.clipsToBounds = true; -// -// if (paint) { -// TGDispatchAfter(0.05, dispatch_get_main_queue(), ^{ -// [model presentPhotoEditorForItem:galleryItem tab:TGPhotoEditorPaintTab snapshots:snapshots fromRect:fromRect]; -// }); -// } else if (adjustments) { -// TGDispatchAfter(0.05, dispatch_get_main_queue(), ^{ -// [model presentPhotoEditorForItem:galleryItem tab:TGPhotoEditorToolsTab snapshots:snapshots fromRect:fromRect]; -// }); -// } } diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift index 9c5a507cd7..c13b957f82 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift @@ -64,7 +64,7 @@ public enum LegacyMediaEditorMode { } -public func legacyWallpaperEditor(context: AccountContext, item: TGMediaEditableItem, cropRect: CGRect, adjustments: TGMediaEditAdjustments?, referenceView: UIView, beginTransitionOut: (() -> Void)?, finishTransitionOut: (() -> Void)?, completion: @escaping (UIImage?, TGMediaEditAdjustments?) -> Void, fullSizeCompletion: @escaping (UIImage?) -> Void, present: @escaping (ViewController, Any?) -> Void) { +public func legacyWallpaperEditor(context: AccountContext, item: TGMediaEditableItem, cropRect: CGRect, adjustments: TGMediaEditAdjustments?, referenceView: UIView, beginTransitionOut: ((Bool) -> Void)?, finishTransitionOut: (() -> Void)?, completion: @escaping (UIImage?, TGMediaEditAdjustments?) -> Void, fullSizeCompletion: @escaping (UIImage?) -> Void, present: @escaping (ViewController, Any?) -> Void) { let presentationData = context.sharedContext.currentPresentationData.with { $0 } let legacyController = LegacyController(presentation: .custom, theme: presentationData.theme, initialLayout: nil) legacyController.blocksBackgroundWhenInOverlay = true @@ -90,8 +90,8 @@ public func legacyWallpaperEditor(context: AccountContext, item: TGMediaEditable Queue.mainQueue().async { fullSizeCompletion(image) } - }, beginTransitionOut: { - beginTransitionOut?() + }, beginTransitionOut: { saving in + beginTransitionOut?(saving) }, finishTransitionOut: { [weak legacyController] in legacyController?.dismiss() finishTransitionOut?() diff --git a/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift b/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift index 47ef6d0b8f..bddf128ca9 100644 --- a/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift +++ b/submodules/SettingsUI/Sources/Themes/CustomWallpaperPicker.swift @@ -297,19 +297,23 @@ public func uploadCustomPeerWallpaper(context: AccountContext, wallpaper: Wallpa context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data, synchronous: true) context.account.postbox.mediaBox.storeResourceData(resource.id, data: data, synchronous: true) + let _ = context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start() + var intensity: Int32? if let brightness { intensity = max(0, min(100, Int32(brightness * 100.0))) } - let settings = WallpaperSettings(blur: mode.contains(.blur), motion: mode.contains(.motion), colors: [], intensity: intensity) - let temporaryWallpaper: TelegramWallpaper = .image([TelegramMediaImageRepresentation(dimensions: PixelDimensions(thumbnailDimensions), resource: thumbnailResource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false), TelegramMediaImageRepresentation(dimensions: PixelDimensions(croppedImage.size), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false)], settings) - - Queue.mainQueue().async { - completion() + Queue.mainQueue().after(0.05) { + let settings = WallpaperSettings(blur: mode.contains(.blur), motion: mode.contains(.motion), colors: [], intensity: intensity) + let temporaryWallpaper: TelegramWallpaper = .image([TelegramMediaImageRepresentation(dimensions: PixelDimensions(thumbnailDimensions), resource: thumbnailResource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false), TelegramMediaImageRepresentation(dimensions: PixelDimensions(croppedImage.size), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false)], settings) + + context.account.pendingPeerMediaUploadManager.add(peerId: peerId, content: .wallpaper(temporaryWallpaper)) + + Queue.mainQueue().after(0.05) { + completion() + } } - - context.account.pendingPeerMediaUploadManager.add(peerId: peerId, content: .wallpaper(temporaryWallpaper)) } return croppedImage }).start() diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index ed244c8c5e..2a179523d5 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -169,10 +169,10 @@ private func updatedFileWallpaper(id: Int64? = nil, accessHash: Int64? = nil, sl class WallpaperGalleryInteraction { let editMedia: (PHAsset, UIImage, CGRect, TGMediaEditAdjustments?, UIView, @escaping (UIImage?, TGMediaEditAdjustments?) -> Void, @escaping (UIImage?) -> Void) -> Void let beginTransitionToEditor: () -> Void - let beginTransitionFromEditor: () -> Void + let beginTransitionFromEditor: (Bool) -> Void let finishTransitionFromEditor: () -> Void - init(editMedia: @escaping (PHAsset, UIImage, CGRect, TGMediaEditAdjustments?, UIView, @escaping (UIImage?, TGMediaEditAdjustments?) -> Void, @escaping (UIImage?) -> Void) -> Void, beginTransitionToEditor: @escaping () -> Void, beginTransitionFromEditor: @escaping () -> Void, finishTransitionFromEditor: @escaping () -> Void) { + init(editMedia: @escaping (PHAsset, UIImage, CGRect, TGMediaEditAdjustments?, UIView, @escaping (UIImage?, TGMediaEditAdjustments?) -> Void, @escaping (UIImage?) -> Void) -> Void, beginTransitionToEditor: @escaping () -> Void, beginTransitionFromEditor: @escaping (Bool) -> Void, finishTransitionFromEditor: @escaping () -> Void) { self.editMedia = editMedia self.beginTransitionToEditor = beginTransitionToEditor self.beginTransitionFromEditor = beginTransitionFromEditor @@ -253,8 +253,8 @@ public class WallpaperGalleryController: ViewController { return } let item = LegacyWallpaperItem(asset: asset, screenImage: image, dimensions: CGSize(width: asset.pixelWidth, height: asset.pixelHeight)) - legacyWallpaperEditor(context: context, item: item, cropRect: cropRect, adjustments: adjustments, referenceView: referenceView, beginTransitionOut: { [weak self] in - self?.interaction?.beginTransitionFromEditor() + legacyWallpaperEditor(context: context, item: item, cropRect: cropRect, adjustments: adjustments, referenceView: referenceView, beginTransitionOut: { [weak self] saving in + self?.interaction?.beginTransitionFromEditor(saving) }, finishTransitionOut: { [weak self] in self?.interaction?.finishTransitionFromEditor() }, completion: { image, adjustments in @@ -274,7 +274,7 @@ public class WallpaperGalleryController: ViewController { if let toolbarNode = self.toolbarNode { transition.updateAlpha(node: toolbarNode, alpha: 0.0) } - }, beginTransitionFromEditor: { [weak self] in + }, beginTransitionFromEditor: { [weak self] saving in guard let self else { return } @@ -283,7 +283,7 @@ public class WallpaperGalleryController: ViewController { transition.updateAlpha(node: toolbarNode, alpha: 1.0) } if let centralItemNode = self.galleryNode.pager.centralItemNode() as? WallpaperGalleryItemNode { - centralItemNode.beginTransitionFromEditor() + centralItemNode.beginTransitionFromEditor(saving: saving) } }, finishTransitionFromEditor: { [weak self] in guard let self else { diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index 51ccf0e2d1..202a157a15 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -506,10 +506,13 @@ final class WallpaperGalleryItemNode: GalleryItemNode { return context })) - self.temporaryImageNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, delay: 0.2, removeOnCompletion: false, completion: { [weak self] _ in - self?.temporaryImageNode.image = nil - self?.temporaryImageNode.layer.removeAllAnimations() - }) + Queue.mainQueue().after(0.1) { + self.brightnessNode.isHidden = false + self.temporaryImageNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, delay: 0.2, removeOnCompletion: false, completion: { [weak self] _ in + self?.temporaryImageNode.image = nil + self?.temporaryImageNode.layer.removeAllAnimations() + }) + } }, { [weak self] image in guard let self else { return @@ -532,13 +535,38 @@ final class WallpaperGalleryItemNode: GalleryItemNode { public private(set) var editedFullSizeImage: UIImage? private var currentAdjustments: TGMediaEditAdjustments? + func beginTransitionToEditor() { + self.cropNode.isHidden = true + + let transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut) + transition.updateAlpha(node: self.messagesContainerNode, alpha: 0.0) + transition.updateAlpha(node: self.buttonsContainerNode, alpha: 0.0) + transition.updateAlpha(node: self.serviceBackgroundNode, alpha: 0.0) + + self.interaction?.beginTransitionToEditor() + } + + func beginTransitionFromEditor(saving: Bool) { + if saving { + self.brightnessNode.isHidden = true + } + let transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut) + transition.updateAlpha(node: self.messagesContainerNode, alpha: 1.0) + transition.updateAlpha(node: self.buttonsContainerNode, alpha: 1.0) + transition.updateAlpha(node: self.serviceBackgroundNode, alpha: 1.0) + } + + func finishTransitionFromEditor() { + self.cropNode.isHidden = false + self.temporaryImageNode.alpha = 1.0 + } + private func animateIntensityChange(delay: Double) { let targetValue: CGFloat = self.sliderNode.value self.sliderNode.internalUpdateLayout(size: self.sliderNode.frame.size, value: 1.0) self.sliderNode.ignoreUpdates = true Queue.mainQueue().after(delay, { self.brightnessNode.backgroundColor = UIColor(rgb: 0x000000) - self.brightnessNode.layer.compositingFilter = nil self.sliderNode.ignoreUpdates = false let transition: ContainedViewLayoutTransition = .animated(duration: 0.35, curve: .easeInOut) @@ -551,37 +579,12 @@ final class WallpaperGalleryItemNode: GalleryItemNode { let value = self.isDarkAppearance ? self.sliderNode.value : 1.0 if value < 1.0 { self.brightnessNode.backgroundColor = UIColor(rgb: 0x000000) - self.brightnessNode.layer.compositingFilter = nil transition.updateAlpha(node: self.brightnessNode, alpha: 1.0 - value) } else { - self.brightnessNode.layer.compositingFilter = nil transition.updateAlpha(node: self.brightnessNode, alpha: 0.0) } } - func beginTransitionToEditor() { - self.cropNode.isHidden = true - - let transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut) - transition.updateAlpha(node: self.messagesContainerNode, alpha: 0.0) - transition.updateAlpha(node: self.buttonsContainerNode, alpha: 0.0) - transition.updateAlpha(node: self.serviceBackgroundNode, alpha: 0.0) - - self.interaction?.beginTransitionToEditor() - } - - func beginTransitionFromEditor() { - let transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut) - transition.updateAlpha(node: self.messagesContainerNode, alpha: 1.0) - transition.updateAlpha(node: self.buttonsContainerNode, alpha: 1.0) - transition.updateAlpha(node: self.serviceBackgroundNode, alpha: 1.0) - } - - func finishTransitionFromEditor() { - self.cropNode.isHidden = false - self.temporaryImageNode.alpha = 1.0 - } - @objc private func cancelPressed() { self.dismiss() } @@ -680,6 +683,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { } if case let .file(file) = wallpaper, !file.isPattern, let intensity = file.settings.intensity { self.sliderNode.value = (1.0 - CGFloat(intensity) / 100.0) + self.updateIntensity(transition: .immediate) } } case .asset: diff --git a/submodules/TelegramCore/Sources/PendingMessages/PendingPeerMediaUploadManager.swift b/submodules/TelegramCore/Sources/PendingMessages/PendingPeerMediaUploadManager.swift index a1938e5310..626a016847 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/PendingPeerMediaUploadManager.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/PendingPeerMediaUploadManager.swift @@ -147,6 +147,8 @@ private final class PendingPeerMediaUploadManagerImpl { let stateManager: AccountStateManager let accountPeerId: EnginePeer.Id + let sentMessageEventPipe: ValuePipe + private var uploadingPeerMediaValue: [EnginePeer.Id: PeerMediaUploadingItem] = [:] { didSet { if self.uploadingPeerMediaValue != oldValue { @@ -168,6 +170,8 @@ private final class PendingPeerMediaUploadManagerImpl { self.stateManager = stateManager self.accountPeerId = accountPeerId + self.sentMessageEventPipe = ValuePipe() + self.uploadingPeerMediaPromise.set(.single(self.uploadingPeerMediaValue)) } @@ -221,6 +225,8 @@ private final class PendingPeerMediaUploadManagerImpl { context.value = context.value.withMessageId(messageId) strongSelf.updateValues() + strongSelf.sentMessageEventPipe.putNext(peerId) + context.disposable.set((uploadPeerMedia(postbox: postbox, network: network, stateManager: stateManager, peerId: peerId, content: content) |> deliverOn(queue)).start(next: { [weak self, weak context] value in guard let strongSelf = self, let initialContext = context else { @@ -324,6 +330,17 @@ private final class PendingPeerMediaUploadManagerImpl { } |> distinctUntilChanged } + + public func sentMessageEvents(peerId: EnginePeer.Id) -> Signal { + return self.sentMessageEventPipe.signal() + |> mapToSignal { eventPeerId -> Signal in + if eventPeerId == peerId { + return .single(Void()) + } else { + return .complete() + } + } + } } public final class PendingPeerMediaUploadManager { @@ -372,4 +389,16 @@ public final class PendingPeerMediaUploadManager { return disposable } } + + public func sentMessageEvents(peerId: EnginePeer.Id) -> Signal { + return Signal { subscriber in + let disposable = MetaDisposable() + self.impl.with { impl in + disposable.set(impl.sentMessageEvents(peerId: peerId).start(next: { value in + subscriber.putNext(value) + })) + } + return disposable + } + } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 3733d0799d..dc0b4d56cc 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -289,6 +289,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G private let controllerNavigationDisposable = MetaDisposable() private let sentMessageEventsDisposable = MetaDisposable() private let failedMessageEventsDisposable = MetaDisposable() + private let sentPeerMediaMessageEventsDisposable = MetaDisposable() private weak var currentFailedMessagesAlertController: ViewController? private let messageActionCallbackDisposable = MetaDisposable() private let messageActionUrlAuthDisposable = MetaDisposable() @@ -6147,6 +6148,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.controllerNavigationDisposable.dispose() self.sentMessageEventsDisposable.dispose() self.failedMessageEventsDisposable.dispose() + self.sentPeerMediaMessageEventsDisposable.dispose() self.messageActionCallbackDisposable.dispose() self.messageActionUrlAuthDisposable.dispose() self.editMessageDisposable.dispose() @@ -10758,6 +10760,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.present(controller, in: .window(.root)) } })) + + self.sentPeerMediaMessageEventsDisposable.set( + (self.context.account.pendingPeerMediaUploadManager.sentMessageEvents(peerId: peerId) + |> deliverOnMainQueue).start(next: { [weak self] _ in + if let self { + self.chatDisplayNode.historyNode.scrollToEndOfHistory() + } + }) + ) } } diff --git a/submodules/TelegramUI/Sources/ChatMessageWallpaperBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageWallpaperBubbleContentNode.swift index 6624a49de8..b058041762 100644 --- a/submodules/TelegramUI/Sources/ChatMessageWallpaperBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageWallpaperBubbleContentNode.swift @@ -334,7 +334,7 @@ class ChatMessageWallpaperBubbleContentNode: ChatMessageBubbleContentNode { if let dimensions = representations.last?.dimensions.cgSize { imageSize = dimensions.aspectFilled(boundingSize) } - updateImageSignal = wallpaperImage(account: item.context.account, accountManager: item.context.sharedContext.accountManager, fileReference: nil, representations: representations.map({ ImageRepresentationWithReference(representation: $0, reference: .standalone(resource: $0.resource)) }), alwaysShowThumbnailFirst: true, thumbnail: true, autoFetchFullSize: true) + updateImageSignal = wallpaperImage(account: item.context.account, accountManager: item.context.sharedContext.accountManager, fileReference: nil, representations: representations.map({ ImageRepresentationWithReference(representation: $0, reference: .standalone(resource: $0.resource)) }), alwaysShowThumbnailFirst: true, thumbnail: true, autoFetchFullSize: true, blurred: wallpaper?.settings?.blur == true) case let .color(color): updateImageSignal = solidColorImage(color) case let .gradient(colors, rotation): diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift index 6205c1f7fd..d6e654859e 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift @@ -2783,12 +2783,15 @@ final class PeerInfoHeaderNode: ASDisplayNode { if self.isAvatarExpanded, case .animated = transition, transitionFraction == 1.0 { self.avatarListNode.animateAvatarCollapse(transition: transition) } + self.avatarClippingNode.clipsToBounds = false } else { let contentOffset = max(0.0, contentOffset - 140.0) let backgroundTransitionFraction: CGFloat = max(0.0, min(1.0, contentOffset / 30.0)) self.expandedBackgroundNode.updateColor(color: presentationData.theme.rootController.navigationBar.opaqueBackgroundColor.mixedWith(headerBackgroundColor, alpha: 1.0 - backgroundTransitionFraction), forceKeepBlur: true, transition: transition) effectiveSeparatorAlpha = backgroundTransitionFraction + + self.avatarClippingNode.clipsToBounds = true } self.avatarListNode.avatarContainerNode.updateTransitionFraction(transitionFraction, transition: transition) @@ -3291,7 +3294,7 @@ final class PeerInfoHeaderNode: ASDisplayNode { controlsClippingFrame = apparentAvatarFrame } - let avatarClipOffset: CGFloat = !self.isAvatarExpanded && deviceMetrics.hasDynamicIsland ? 48.0 : 0.0 + let avatarClipOffset: CGFloat = !self.isAvatarExpanded && deviceMetrics.hasDynamicIsland && self.avatarClippingNode.clipsToBounds ? 48.0 : 0.0 let clippingNodeTransition = ContainedViewLayoutTransition.immediate clippingNodeTransition.updateFrame(layer: self.avatarClippingNode.layer, frame: CGRect(origin: CGPoint(x: 0.0, y: avatarClipOffset), size: CGSize(width: width, height: 1000.0))) clippingNodeTransition.updateSublayerTransformOffset(layer: self.avatarClippingNode.layer, offset: CGPoint(x: 0.0, y: -avatarClipOffset)) @@ -3338,7 +3341,7 @@ final class PeerInfoHeaderNode: ASDisplayNode { transition.updateSublayerTransformScale(node: self.avatarListNode.listContainerTransformNode, scale: avatarListContainerScale) } - if deviceMetrics.hasDynamicIsland && self.forumTopicThreadId == nil { + if deviceMetrics.hasDynamicIsland && self.forumTopicThreadId == nil && self.navigationTransition == nil { let maskValue = max(0.0, min(1.0, contentOffset / 120.0)) self.avatarListNode.containerNode.view.mask = self.avatarListNode.maskNode.view if maskValue > 0.03 {