From b4deaf2e4f16ffc83edfc069ec24e6deac504830 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 29 May 2020 12:04:17 +0300 Subject: [PATCH] Video editor fixes --- .../TGPhotoPaintStickersContext.h | 1 + .../Sources/TGPhotoEntitiesContainerView.h | 2 ++ .../Sources/TGPhotoEntitiesContainerView.m | 13 +++++++++++ .../Sources/TGPhotoPaintController.m | 2 ++ .../Sources/TGPhotoStickerEntityView.h | 2 ++ .../Sources/TGPhotoStickerEntityView.m | 4 ++++ .../Sources/LegacyPaintStickerView.swift | 23 ++++++++++++++----- .../Sources/ChatMediaInputGridEntries.swift | 15 +++++++----- .../Sources/ChatMediaInputNode.swift | 17 ++++++++------ .../ChatMediaInputStickerGridItem.swift | 6 ++--- .../Sources/DrawingStickersScreen.swift | 8 +++---- 11 files changed, 67 insertions(+), 26 deletions(-) diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h index 4d57659d47..4c6e2e14ce 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoPaintStickersContext.h @@ -13,6 +13,7 @@ @protocol TGPhotoPaintStickerRenderView +- (void)setIsVisible:(bool)isVisible; - (int64_t)documentId; - (UIImage *)image; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h index f856159f02..09bcdf009b 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h +++ b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.h @@ -13,6 +13,8 @@ @property (nonatomic, copy) void (^entitySelected)(TGPhotoPaintEntityView *); @property (nonatomic, copy) void (^entityRemoved)(TGPhotoPaintEntityView *); +- (void)updateVisibility:(bool)visible; + - (void)setupWithPaintingData:(TGPaintingData *)paintingData; - (TGPhotoPaintEntityView *)createEntityViewWithEntity:(TGPhotoPaintEntity *)entity; diff --git a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m index 7daca2f6c2..4ded3095dd 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEntitiesContainerView.m @@ -27,6 +27,19 @@ return self; } +- (void)updateVisibility:(bool)visible +{ + for (TGPhotoPaintEntityView *view in self.subviews) + { + if (![view isKindOfClass:[TGPhotoPaintEntityView class]]) + continue; + + if ([view isKindOfClass:[TGPhotoStickerEntityView class]]) { + [(TGPhotoStickerEntityView *)view updateVisibility:visible]; + } + } +} + - (BOOL)gestureRecognizer:(UIGestureRecognizer *)__unused gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)__unused otherGestureRecognizer { return false; diff --git a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m index 1c76a478c6..704274fea7 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoPaintController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoPaintController.m @@ -1019,12 +1019,14 @@ const CGFloat TGPhotoPaintStickerKeyboardSize = 260.0f; __strong TGPhotoPaintController *strongSelf = weakSelf; if (strongSelf != nil) { strongSelf.controlVideoPlayback(false); + [strongSelf->_entitiesContainerView updateVisibility:false]; } }; _stickersScreen.screenWillDisappear = ^{ __strong TGPhotoPaintController *strongSelf = weakSelf; if (strongSelf != nil) { strongSelf.controlVideoPlayback(true); + [strongSelf->_entitiesContainerView updateVisibility:true]; } }; } diff --git a/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.h b/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.h index 6e8cc7cd00..828588add6 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.h +++ b/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.h @@ -16,6 +16,8 @@ - (void)mirror; - (UIImage *)image; +- (void)updateVisibility:(bool)visible; + - (CGRect)realBounds; @end diff --git a/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.m b/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.m index 21635b65d1..bd632b6631 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.m +++ b/submodules/LegacyComponents/Sources/TGPhotoStickerEntityView.m @@ -170,6 +170,10 @@ const CGFloat TGPhotoStickerSelectionViewHandleSide = 30.0f; return CGRectMake((self.bounds.size.width - side) / 2.0f, (self.bounds.size.height - side) / 2.0f, side, side); } +- (void)updateVisibility:(bool)visible { + [_stickerView setIsVisible:visible]; +} + @end diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift index d3cc4988b0..6e8d1a2b41 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickerView.swift @@ -86,14 +86,25 @@ class LegacyPaintStickerView: UIView, TGPhotoPaintStickerRenderView { } } + var isVisible: Bool = true + func setIsVisible(_ visible: Bool) { + self.isVisible = visible + updateVisibility() + } + + var isPlaying = false func updateVisibility() { - if !self.didSetUpAnimationNode { - self.didSetUpAnimationNode = true + let isPlaying = self.isVisible + if self.isPlaying != isPlaying { + self.isPlaying = isPlaying - self.animationNode?.visibility = true - let dimensions = self.file.dimensions ?? PixelDimensions(width: 512, height: 512) - let fittedDimensions = dimensions.cgSize.aspectFitted(CGSize(width: 512.0, height: 512.0)) - self.animationNode?.setup(source: AnimatedStickerResourceSource(account: self.context.account, resource: self.file.resource), width: Int(fittedDimensions.width), height: Int(fittedDimensions.height), mode: .cached) + self.animationNode?.visibility = isPlaying + if isPlaying && !self.didSetUpAnimationNode { + self.didSetUpAnimationNode = true + let dimensions = self.file.dimensions ?? PixelDimensions(width: 512, height: 512) + let fittedDimensions = dimensions.cgSize.aspectFitted(CGSize(width: 512.0, height: 512.0)) + self.animationNode?.setup(source: AnimatedStickerResourceSource(account: self.context.account, resource: self.file.resource), width: Int(fittedDimensions.width), height: Int(fittedDimensions.height), mode: .cached) + } } } diff --git a/submodules/TelegramUI/Sources/ChatMediaInputGridEntries.swift b/submodules/TelegramUI/Sources/ChatMediaInputGridEntries.swift index a778e27499..7c2b354a48 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputGridEntries.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputGridEntries.swift @@ -87,7 +87,7 @@ enum ChatMediaInputGridEntryIndex: Equatable, Comparable { enum ChatMediaInputGridEntry: Equatable, Comparable, Identifiable { case search(theme: PresentationTheme, strings: PresentationStrings) case peerSpecificSetup(theme: PresentationTheme, strings: PresentationStrings, dismissed: Bool) - case sticker(index: ItemCollectionViewEntryIndex, stickerItem: StickerPackItem, stickerPackInfo: StickerPackCollectionInfo?, canManagePeerSpecificPack: Bool?, theme: PresentationTheme) + case sticker(index: ItemCollectionViewEntryIndex, stickerItem: StickerPackItem, stickerPackInfo: StickerPackCollectionInfo?, canManagePeerSpecificPack: Bool?, maybeManageable: Bool, theme: PresentationTheme) case trending(TrendingPanePackEntry) var index: ChatMediaInputGridEntryIndex { @@ -96,7 +96,7 @@ enum ChatMediaInputGridEntry: Equatable, Comparable, Identifiable { return .search case let .peerSpecificSetup(_, _, dismissed): return .peerSpecificSetup(dismissed: dismissed) - case let .sticker(index, _, _, _, _): + case let .sticker(index, _, _, _, _, _): return .collectionIndex(index) case let .trending(entry): return .trending(entry.info.id, entry.index) @@ -127,8 +127,8 @@ enum ChatMediaInputGridEntry: Equatable, Comparable, Identifiable { } else { return false } - case let .sticker(lhsIndex, lhsStickerItem, lhsStickerPackInfo, lhsCanManagePeerSpecificPack, lhsTheme): - if case let .sticker(rhsIndex, rhsStickerItem, rhsStickerPackInfo, rhsCanManagePeerSpecificPack, rhsTheme) = rhs { + case let .sticker(lhsIndex, lhsStickerItem, lhsStickerPackInfo, lhsCanManagePeerSpecificPack, lhsMaybeManageable, lhsTheme): + if case let .sticker(rhsIndex, rhsStickerItem, rhsStickerPackInfo, rhsCanManagePeerSpecificPack, rhsMaybeManageable, rhsTheme) = rhs { if lhsIndex != rhsIndex { return false } @@ -141,6 +141,9 @@ enum ChatMediaInputGridEntry: Equatable, Comparable, Identifiable { if lhsCanManagePeerSpecificPack != rhsCanManagePeerSpecificPack { return false } + if lhsMaybeManageable != rhsMaybeManageable { + return false + } if lhsTheme !== rhsTheme { return false } @@ -173,8 +176,8 @@ enum ChatMediaInputGridEntry: Equatable, Comparable, Identifiable { }, dismiss: dismissed ? nil : { inputNodeInteraction.dismissPeerSpecificSettings() }) - case let .sticker(index, stickerItem, stickerPackInfo, canManagePeerSpecificPack, theme): - return ChatMediaInputStickerGridItem(account: account, collectionId: index.collectionId, stickerPackInfo: stickerPackInfo, index: index, stickerItem: stickerItem, canManagePeerSpecificPack: canManagePeerSpecificPack, interfaceInteraction: interfaceInteraction, inputNodeInteraction: inputNodeInteraction, theme: theme, selected: { }) + case let .sticker(index, stickerItem, stickerPackInfo, canManagePeerSpecificPack, maybeManageable, theme): + return ChatMediaInputStickerGridItem(account: account, collectionId: index.collectionId, stickerPackInfo: stickerPackInfo, index: index, stickerItem: stickerItem, canManagePeerSpecificPack: canManagePeerSpecificPack, interfaceInteraction: interfaceInteraction, inputNodeInteraction: inputNodeInteraction, hasAccessory: maybeManageable, theme: theme, selected: { }) case let .trending(entry): return entry.item(account: account, interaction: trendingInteraction, grid: false) } diff --git a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift index 3e7006cc4e..5302a782b6 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputNode.swift @@ -163,7 +163,7 @@ func preparedChatMediaInputGridEntryTransition(account: Account, view: ItemColle return ChatMediaInputGridTransition(deletions: deletions, insertions: insertions, updates: updates, updateFirstIndexInSectionOffset: firstIndexInSectionOffset, stationaryItems: stationaryItems, scrollToItem: scrollToItem, updateOpaqueState: opaqueState, animated: animated) } -func chatMediaInputPanelEntries(view: ItemCollectionsView, savedStickers: OrderedItemListView?, recentStickers: OrderedItemListView?, peerSpecificPack: PeerSpecificPackData?, canInstallPeerSpecificPack: CanInstallPeerSpecificPack, hasUnreadTrending: Bool?, theme: PresentationTheme, hasGifs: Bool = true) -> [ChatMediaInputPanelEntry] { +func chatMediaInputPanelEntries(view: ItemCollectionsView, savedStickers: OrderedItemListView?, recentStickers: OrderedItemListView?, peerSpecificPack: PeerSpecificPackData?, canInstallPeerSpecificPack: CanInstallPeerSpecificPack, hasUnreadTrending: Bool?, theme: PresentationTheme, hasGifs: Bool = true, hasSettings: Bool = true) -> [ChatMediaInputPanelEntry] { var entries: [ChatMediaInputPanelEntry] = [] if hasGifs { entries.append(.recentGifs(theme)) @@ -213,7 +213,9 @@ func chatMediaInputPanelEntries(view: ItemCollectionsView, savedStickers: Ordere entries.append(.peerSpecific(theme: theme, peer: peer)) } - entries.append(.settings(theme)) + if hasSettings { + entries.append(.settings(theme)) + } return entries } @@ -230,7 +232,7 @@ func chatMediaInputPanelGifModeEntries(theme: PresentationTheme, reactions: [Str return entries } -func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: OrderedItemListView?, recentStickers: OrderedItemListView?, peerSpecificPack: PeerSpecificPackData?, canInstallPeerSpecificPack: CanInstallPeerSpecificPack, hasSearch: Bool = true, strings: PresentationStrings, theme: PresentationTheme) -> [ChatMediaInputGridEntry] { +func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: OrderedItemListView?, recentStickers: OrderedItemListView?, peerSpecificPack: PeerSpecificPackData?, canInstallPeerSpecificPack: CanInstallPeerSpecificPack, hasSearch: Bool = true, hasAccessories: Bool = true, strings: PresentationStrings, theme: PresentationTheme) -> [ChatMediaInputGridEntry] { var entries: [ChatMediaInputGridEntry] = [] if hasSearch && view.lower == nil { @@ -253,7 +255,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered savedStickerIds.insert(item.file.fileId.id) let index = ItemCollectionItemIndex(index: Int32(i), id: item.file.fileId.id) let stickerItem = StickerPackItem(index: index, file: item.file, indexKeys: []) - entries.append(.sticker(index: ItemCollectionViewEntryIndex(collectionIndex: -3, collectionId: packInfo.id, itemIndex: index), stickerItem: stickerItem, stickerPackInfo: packInfo, canManagePeerSpecificPack: nil, theme: theme)) + entries.append(.sticker(index: ItemCollectionViewEntryIndex(collectionIndex: -3, collectionId: packInfo.id, itemIndex: index), stickerItem: stickerItem, stickerPackInfo: packInfo, canManagePeerSpecificPack: nil, maybeManageable: hasAccessories, theme: theme)) } } } @@ -269,7 +271,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered if !savedStickerIds.contains(mediaId.id) { let index = ItemCollectionItemIndex(index: Int32(i), id: mediaId.id) let stickerItem = StickerPackItem(index: index, file: file, indexKeys: []) - entries.append(.sticker(index: ItemCollectionViewEntryIndex(collectionIndex: -2, collectionId: packInfo.id, itemIndex: index), stickerItem: stickerItem, stickerPackInfo: packInfo, canManagePeerSpecificPack: nil, theme: theme)) + entries.append(.sticker(index: ItemCollectionViewEntryIndex(collectionIndex: -2, collectionId: packInfo.id, itemIndex: index), stickerItem: stickerItem, stickerPackInfo: packInfo, canManagePeerSpecificPack: nil, maybeManageable: hasAccessories, theme: theme)) addedCount += 1 } } @@ -292,7 +294,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered if let item = peerSpecificPack.items[i] as? StickerPackItem { let index = ItemCollectionItemIndex(index: Int32(i), id: item.file.fileId.id) let stickerItem = StickerPackItem(index: index, file: item.file, indexKeys: []) - entries.append(.sticker(index: ItemCollectionViewEntryIndex(collectionIndex: -1, collectionId: packInfo.id, itemIndex: index), stickerItem: stickerItem, stickerPackInfo: packInfo, canManagePeerSpecificPack: canManagePeerSpecificPack, theme: theme)) + entries.append(.sticker(index: ItemCollectionViewEntryIndex(collectionIndex: -1, collectionId: packInfo.id, itemIndex: index), stickerItem: stickerItem, stickerPackInfo: packInfo, canManagePeerSpecificPack: canManagePeerSpecificPack, maybeManageable: hasAccessories, theme: theme)) } } } @@ -300,7 +302,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered for entry in view.entries { if let item = entry.item as? StickerPackItem { - entries.append(.sticker(index: entry.index, stickerItem: item, stickerPackInfo: stickerPackInfos[entry.index.collectionId], canManagePeerSpecificPack: false, theme: theme)) + entries.append(.sticker(index: entry.index, stickerItem: item, stickerPackInfo: stickerPackInfos[entry.index.collectionId], canManagePeerSpecificPack: false, maybeManageable: hasAccessories, theme: theme)) } } @@ -367,6 +369,7 @@ final class ChatMediaInputNodeInteraction { var previewedStickerPackItem: StickerPreviewPeekItem? var appearanceTransition: CGFloat = 1.0 var displayStickerPlaceholder = true + var displayStickerPackManageControls = true init(navigateToCollectionId: @escaping (ItemCollectionId) -> Void, navigateBackToStickers: @escaping () -> Void, setGifMode: @escaping (ChatMediaInputGifMode) -> Void, openSettings: @escaping () -> Void, toggleSearch: @escaping (Bool, ChatMediaInputSearchMode?, String) -> Void, openPeerSpecificSettings: @escaping () -> Void, dismissPeerSpecificSettings: @escaping () -> Void, clearRecentlyUsedStickers: @escaping () -> Void) { self.navigateToCollectionId = navigateToCollectionId diff --git a/submodules/TelegramUI/Sources/ChatMediaInputStickerGridItem.swift b/submodules/TelegramUI/Sources/ChatMediaInputStickerGridItem.swift index a75092a9a2..dba715fafd 100644 --- a/submodules/TelegramUI/Sources/ChatMediaInputStickerGridItem.swift +++ b/submodules/TelegramUI/Sources/ChatMediaInputStickerGridItem.swift @@ -126,7 +126,7 @@ final class ChatMediaInputStickerGridItem: GridItem { let section: GridSection? - init(account: Account, collectionId: ItemCollectionId, stickerPackInfo: StickerPackCollectionInfo?, index: ItemCollectionViewEntryIndex, stickerItem: StickerPackItem, canManagePeerSpecificPack: Bool?, interfaceInteraction: ChatControllerInteraction?, inputNodeInteraction: ChatMediaInputNodeInteraction, theme: PresentationTheme, selected: @escaping () -> Void) { + init(account: Account, collectionId: ItemCollectionId, stickerPackInfo: StickerPackCollectionInfo?, index: ItemCollectionViewEntryIndex, stickerItem: StickerPackItem, canManagePeerSpecificPack: Bool?, interfaceInteraction: ChatControllerInteraction?, inputNodeInteraction: ChatMediaInputNodeInteraction, hasAccessory: Bool, theme: PresentationTheme, selected: @escaping () -> Void) { self.account = account self.index = index self.stickerItem = stickerItem @@ -138,9 +138,9 @@ final class ChatMediaInputStickerGridItem: GridItem { self.section = nil } else { let accessory: ChatMediaInputStickerGridSectionAccessory - if stickerPackInfo?.id.namespace == ChatMediaInputPanelAuxiliaryNamespace.peerSpecific.rawValue, let canManage = canManagePeerSpecificPack, canManage { + if hasAccessory && stickerPackInfo?.id.namespace == ChatMediaInputPanelAuxiliaryNamespace.peerSpecific.rawValue, let canManage = canManagePeerSpecificPack, canManage { accessory = .setup - } else if stickerPackInfo?.id.namespace == ChatMediaInputPanelAuxiliaryNamespace.recentStickers.rawValue { + } else if hasAccessory && stickerPackInfo?.id.namespace == ChatMediaInputPanelAuxiliaryNamespace.recentStickers.rawValue { accessory = .clear } else { accessory = .none diff --git a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift index fb3b226442..9d5bc37775 100644 --- a/submodules/TelegramUI/Sources/DrawingStickersScreen.swift +++ b/submodules/TelegramUI/Sources/DrawingStickersScreen.swift @@ -585,8 +585,8 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { } } - let panelEntries = chatMediaInputPanelEntries(view: view, savedStickers: savedStickers, recentStickers: recentStickers, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasUnreadTrending: nil, theme: theme, hasGifs: false) - let gridEntries = chatMediaInputGridEntries(view: view, savedStickers: savedStickers, recentStickers: recentStickers, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasSearch: false, strings: strings, theme: theme) + let panelEntries = chatMediaInputPanelEntries(view: view, savedStickers: savedStickers, recentStickers: recentStickers, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasUnreadTrending: nil, theme: theme, hasGifs: false, hasSettings: false) + let gridEntries = chatMediaInputGridEntries(view: view, savedStickers: savedStickers, recentStickers: recentStickers, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasSearch: false, hasAccessories: false, strings: strings, theme: theme) // if view.higher == nil { // var hasTopSeparator = true @@ -636,8 +636,8 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode { installedPacks.insert(info.0) } - let panelEntries = chatMediaInputPanelEntries(view: view, savedStickers: nil, recentStickers: nil, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasUnreadTrending: nil, theme: theme, hasGifs: false) - let gridEntries = chatMediaInputGridEntries(view: view, savedStickers: nil, recentStickers: nil, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasSearch: false, strings: strings, theme: theme) + let panelEntries = chatMediaInputPanelEntries(view: view, savedStickers: nil, recentStickers: nil, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasUnreadTrending: nil, theme: theme, hasGifs: false, hasSettings: false) + let gridEntries = chatMediaInputGridEntries(view: view, savedStickers: nil, recentStickers: nil, peerSpecificPack: nil, canInstallPeerSpecificPack: .none, hasSearch: false, hasAccessories: false, strings: strings, theme: theme) let (previousPanelEntries, previousGridEntries) = previousMaskEntries.swap((panelEntries, gridEntries)) return (view, preparedChatMediaInputPanelEntryTransition(context: context, from: previousPanelEntries, to: panelEntries, inputNodeInteraction: masksInputNodeInteraction), previousPanelEntries.isEmpty, preparedChatMediaInputGridEntryTransition(account: context.account, view: view, from: previousGridEntries, to: gridEntries, update: update, interfaceInteraction: controllerInteraction, inputNodeInteraction: masksInputNodeInteraction, trendingInteraction: trendingInteraction), previousGridEntries.isEmpty)