diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h index 7ee9d2b520..ee21c29ebe 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoEditorTabController.h @@ -29,6 +29,7 @@ @property (nonatomic, copy) void (^tabsChanged)(void); +@property (nonatomic, copy) bool (^isVideoPlaying)(); @property (nonatomic, copy) void (^controlVideoPlayback)(bool); @property (nonatomic, copy) void (^controlVideoSeek)(NSTimeInterval); @property (nonatomic, copy) void (^controlVideoEndTime)(NSTimeInterval); diff --git a/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m b/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m index 138c163556..83f5edd1b5 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoAvatarPreviewController.m @@ -43,6 +43,8 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel UIView *_landscapeToolControlView; UILabel *_coverLabel; + bool _wasPlayingBeforeCropping; + bool _scheduledTransitionIn; } @@ -80,6 +82,10 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel if (strongSelf == nil) return; + if (strongSelf.isVideoPlaying != nil) { + strongSelf->_wasPlayingBeforeCropping = strongSelf.isVideoPlaying(); + } + strongSelf.controlVideoPlayback(false); }; void(^interactionEnded)(void) = ^ @@ -91,7 +97,9 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel if ([strongSelf shouldAutorotate]) [TGViewController attemptAutorotation]; - strongSelf.controlVideoPlayback(true); + if (strongSelf->_wasPlayingBeforeCropping) { + strongSelf.controlVideoPlayback(true); + } }; PGPhotoEditor *photoEditor = self.photoEditor; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 24ed610fcc..e4b65d1d0c 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -1274,6 +1274,12 @@ [strongSelf stopVideoPlayback:false]; } }; + cropController.isVideoPlaying = ^bool{ + __strong TGPhotoEditorController *strongSelf = weakSelf; + if (strongSelf == nil) + return false; + return strongSelf->_isPlaying; + }; cropController.togglePlayback = ^{ __strong TGPhotoEditorController *strongSelf = weakSelf; if (strongSelf == nil || !strongSelf->_item.isVideo) @@ -2902,5 +2908,4 @@ return self.item.originalSize; } - @end diff --git a/submodules/TelegramUI/Sources/CreateChannelController.swift b/submodules/TelegramUI/Sources/CreateChannelController.swift index 9d54534f0b..7b9f0965f5 100644 --- a/submodules/TelegramUI/Sources/CreateChannelController.swift +++ b/submodules/TelegramUI/Sources/CreateChannelController.swift @@ -368,7 +368,7 @@ public func createChannelController(context: AccountContext) -> ViewController { } if let timestamp = videoStartTimestamp { - videoStartTimestamp = max(0.0, min(timestamp, result.duration)) + videoStartTimestamp = max(0.0, min(timestamp, result.duration - 0.05)) } var value = stat() diff --git a/submodules/TelegramUI/Sources/CreateGroupController.swift b/submodules/TelegramUI/Sources/CreateGroupController.swift index 638e69dff8..c4e5a59f15 100644 --- a/submodules/TelegramUI/Sources/CreateGroupController.swift +++ b/submodules/TelegramUI/Sources/CreateGroupController.swift @@ -626,7 +626,7 @@ public func createGroupControllerImpl(context: AccountContext, peerIds: [PeerId] } if let timestamp = videoStartTimestamp { - videoStartTimestamp = max(0.0, min(timestamp, result.duration)) + videoStartTimestamp = max(0.0, min(timestamp, result.duration - 0.05)) } var value = stat() diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift index 9a6326a6f8..ec3b44da15 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift @@ -445,7 +445,7 @@ final class PeerInfoAvatarListContainerNode: ASDisplayNode { playerPosition = playerStatus.timestamp } - if let videoStartTimestamp = videoStartTimestamp { + if let videoStartTimestamp = videoStartTimestamp, false { playerPosition -= videoStartTimestamp if playerPosition < 0.0 { playerPosition = playerStatus.duration + playerPosition @@ -1069,22 +1069,7 @@ final class PeerInfoAvatarTransformContainerNode: ASDisplayNode { self.tapped?() } } - - func reattachVideoNode() { - if let videoNode = self.videoNode { - let maskPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(), size: self.avatarNode.frame.size)) - let shape = CAShapeLayer() - shape.path = maskPath.cgPath - videoNode.layer.mask = shape - - videoNode.transform = CATransform3DIdentity - videoNode.updateLayout(size: self.avatarNode.frame.size, transition: .immediate) - videoNode.frame = self.avatarNode.frame - - self.addSubnode(videoNode) - } - } - + func updateTransitionFraction(_ fraction: CGFloat, transition: ContainedViewLayoutTransition) { if let videoNode = self.videoNode { if case .immediate = transition, fraction == 1.0 { @@ -1212,11 +1197,6 @@ final class PeerInfoAvatarTransformContainerNode: ASDisplayNode { let update = { videoNode.canAttachContent = !self.isExpanded && self.canAttachVideo if videoNode.canAttachContent { -// if let videoStartTimestamp = self.videoStartTimestamp { -// videoNode.seek(videoStartTimestamp) -// } else { -// videoNode.seek(0.0) -// } videoNode.play() } } @@ -2292,6 +2272,7 @@ final class PeerInfoHeaderNode: ASDisplayNode { private(set) var isAvatarExpanded: Bool private(set) var twoLineInfo = false var skipCollapseCompletion = false + var ignoreCollapse = false let avatarListNode: PeerInfoAvatarListNode @@ -2842,7 +2823,7 @@ final class PeerInfoHeaderNode: ASDisplayNode { } self.avatarListNode.listContainerNode.update(size: expandedAvatarListSize, peer: peer, isExpanded: self.isAvatarExpanded, transition: transition) - if self.avatarListNode.listContainerNode.isCollapsing { + if self.avatarListNode.listContainerNode.isCollapsing && !self.ignoreCollapse { self.avatarListNode.avatarContainerNode.canAttachVideo = false } diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 44e4e1bd1e..74abaee9b2 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -3990,13 +3990,11 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD } if self.headerNode.isAvatarExpanded { + self.headerNode.ignoreCollapse = true self.headerNode.updateIsAvatarExpanded(false, transition: .immediate) self.updateNavigationExpansionPresentation(isExpanded: false, animated: true) } - if let (layout, navigationHeight) = self.validLayout { - self.scrollNode.view.setContentOffset(CGPoint(), animated: false) - self.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false) - } + self.scrollNode.view.setContentOffset(CGPoint(), animated: false) let resource = LocalFileMediaResource(fileId: arc4random64()) self.context.account.postbox.mediaBox.storeResourceData(resource.id, data: data) @@ -4006,6 +4004,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD if let (layout, navigationHeight) = self.validLayout { self.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false) } + self.headerNode.ignoreCollapse = false let postbox = self.context.account.postbox let signal = self.isSettings ? updateAccountPhoto(account: self.context.account, resource: resource, videoResource: nil, videoStartTimestamp: nil, mapResourceToAvatarSizes: { resource, representations in @@ -4036,13 +4035,11 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD } if self.headerNode.isAvatarExpanded { + self.headerNode.ignoreCollapse = true self.headerNode.updateIsAvatarExpanded(false, transition: .immediate) self.updateNavigationExpansionPresentation(isExpanded: false, animated: true) } - if let (layout, navigationHeight) = self.validLayout { - self.scrollNode.view.setContentOffset(CGPoint(), animated: false) - self.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false) - } + self.scrollNode.view.setContentOffset(CGPoint(), animated: false) let photoResource = LocalFileMediaResource(fileId: arc4random64()) self.context.account.postbox.mediaBox.storeResourceData(photoResource.id, data: data) @@ -4052,6 +4049,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD if let (layout, navigationHeight) = self.validLayout { self.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate, additive: false) } + self.headerNode.ignoreCollapse = false var videoStartTimestamp: Double? = nil if let adjustments = adjustments, adjustments.videoStartValue > 0.0 { @@ -4083,7 +4081,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD } if let timestamp = videoStartTimestamp { - videoStartTimestamp = max(0.0, min(timestamp, result.duration)) + videoStartTimestamp = max(0.0, min(timestamp, result.duration - 0.05)) } var value = stat() @@ -4155,6 +4153,12 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD return } + var currentIsVideo = false + let item = self.headerNode.avatarListNode.listContainerNode.currentItemNode?.item + if let item = item, case let .image(image) = item { + currentIsVideo = !image.2.isEmpty + } + let peerId = self.peerId let _ = (self.context.account.postbox.transaction { transaction -> (Peer?, SearchBotsConfiguration) in return (transaction.getPeer(peerId), currentSearchBotsConfiguration(transaction: transaction)) @@ -4184,7 +4188,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD hasPhotos = true } - let mixin = TGMediaAvatarMenuMixin(context: legacyController.context, parentController: emptyController, hasSearchButton: true, hasDeleteButton: hasPhotos && hasRemove, hasViewButton: false, personalPhoto: strongSelf.isSettings, isVideo: false, saveEditedPhotos: false, saveCapturedMedia: false, signup: false)! + let mixin = TGMediaAvatarMenuMixin(context: legacyController.context, parentController: emptyController, hasSearchButton: true, hasDeleteButton: hasPhotos && hasRemove, hasViewButton: false, personalPhoto: strongSelf.isSettings, isVideo: currentIsVideo, saveEditedPhotos: false, saveCapturedMedia: false, signup: false)! let _ = strongSelf.currentAvatarMixin.swap(mixin) mixin.requestSearchController = { [weak self] assetsController in guard let strongSelf = self else { @@ -5803,23 +5807,7 @@ public final class PeerInfoScreen: ViewController { super.displayNodeDidLoad() } - - public override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - self.controllerNode.canAttachVideo = false - } - - override public func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - self.controllerNode.canAttachVideo = true - - if let (layout, navigationHeight) = self.validLayout { - self.controllerNode.containerLayoutUpdated(layout: layout, navigationHeight: navigationHeight, transition: .immediate) - } - } - override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { super.containerLayoutUpdated(layout, transition: transition) diff --git a/submodules/UrlHandling/Sources/UrlHandling.swift b/submodules/UrlHandling/Sources/UrlHandling.swift index cb08db7f87..743e955e10 100644 --- a/submodules/UrlHandling/Sources/UrlHandling.swift +++ b/submodules/UrlHandling/Sources/UrlHandling.swift @@ -448,7 +448,7 @@ public func resolveUrlImpl(account: Account, url: String) -> Signal