From d80ead5f676c7439ca6fb76f88a19bf08d2672d4 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 28 Oct 2021 16:37:34 +0400 Subject: [PATCH] Various Fixes --- .../Sources/ItemListInviteRequestItem.swift | 10 +++ .../Sources/ItemListPeerActionItem.swift | 2 +- .../NotificationsPeerCategoryController.swift | 2 +- .../RecentSessionScreen.swift | 86 ++++++++++++++++--- .../Sources/Search/SettingsSearchItem.swift | 21 ++--- .../Search/SettingsSearchRecentItem.swift | 11 ++- .../Sources/PeerInfo/PeerInfoScreen.swift | 6 ++ 7 files changed, 111 insertions(+), 27 deletions(-) diff --git a/submodules/InviteLinksUI/Sources/ItemListInviteRequestItem.swift b/submodules/InviteLinksUI/Sources/ItemListInviteRequestItem.swift index 35a0e24e12..1638c4e7b3 100644 --- a/submodules/InviteLinksUI/Sources/ItemListInviteRequestItem.swift +++ b/submodules/InviteLinksUI/Sources/ItemListInviteRequestItem.swift @@ -245,6 +245,16 @@ public class ItemListInviteRequestItemNode: ListViewItemNode, ItemListItemNode { } self.dismissButton.addTarget(self, action: #selector(self.dismissPressed), forControlEvents: .touchUpInside) + self.containerNode.shouldBegin = { [weak self] point in + guard let strongSelf = self else { + return false + } + if strongSelf.addButton.frame.contains(point) || strongSelf.dismissButton.frame.contains(point) { + return false + } + return true + } + self.containerNode.activated = { [weak self] gesture, _ in guard let strongSelf = self, let item = strongSelf.layoutParams?.0, let _ = item.importer, let contextAction = item.contextAction else { gesture.cancel() diff --git a/submodules/ItemListPeerActionItem/Sources/ItemListPeerActionItem.swift b/submodules/ItemListPeerActionItem/Sources/ItemListPeerActionItem.swift index b3ce620fd0..de2a3ae3c8 100644 --- a/submodules/ItemListPeerActionItem/Sources/ItemListPeerActionItem.swift +++ b/submodules/ItemListPeerActionItem/Sources/ItemListPeerActionItem.swift @@ -168,7 +168,7 @@ class ItemListPeerActionItemNode: ListViewItemNode { case .generic: verticalInset = 11.0 verticalOffset = 0.0 - leftInset = (item.icon == nil ? 16.0 : 59.0) + params.leftInset + leftInset = (item.icon == nil ? 16.0 : 65.0) + params.leftInset case .peerList: verticalInset = 14.0 verticalOffset = 0.0 diff --git a/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift b/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift index c412e75d91..2b4e87fdbd 100644 --- a/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift +++ b/submodules/SettingsUI/Sources/NotificationsPeerCategoryController.swift @@ -222,7 +222,7 @@ private enum NotificationsPeerCategoryEntry: ItemListNodeEntry { case let .exceptionsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .addException(theme, text): - return ItemListPeerActionItem(presentationData: presentationData, icon: PresentationResourcesItemList.addPersonIcon(theme), title: text, sectionId: self.section, height: .generic, color: .accent, editing: false, action: { + return ItemListPeerActionItem(presentationData: presentationData, icon: PresentationResourcesItemList.plusIconImage(theme), title: text, sectionId: self.section, height: .generic, color: .accent, editing: false, action: { arguments.addException() }) case let .exception(_, _, _, dateTimeFormat, nameDisplayOrder, peer, description, _, editing, revealed): diff --git a/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift b/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift index 40a52c2d8e..cca09cdee0 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift @@ -18,6 +18,7 @@ import StickerResources import AnimatedStickerNode import TelegramAnimatedStickerNode import AvatarNode +import UndoUI private func closeButtonImage(theme: PresentationTheme) -> UIImage? { return generateImage(CGSize(width: 30.0, height: 30.0), contextGenerator: { size, context in @@ -391,6 +392,74 @@ private class RecentSessionScreenNode: ViewControllerTracingNode, UIScrollViewDe } } + override func didLoad() { + super.didLoad() + + if #available(iOSApplicationExtension 11.0, iOS 11.0, *) { + self.wrappingScrollNode.view.contentInsetAdjustmentBehavior = .never + } + + self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture))) + + let titleGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleTitleLongPress(_:))) + self.titleNode.view.addGestureRecognizer(titleGestureRecognizer) + + let deviceGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleDeviceLongPress(_:))) + self.deviceValueNode.view.addGestureRecognizer(deviceGestureRecognizer) + + let locationGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLocationLongPress(_:))) + self.locationValueNode.view.addGestureRecognizer(locationGestureRecognizer) + + let ipGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleIpLongPress(_:))) + self.ipValueNode.view.addGestureRecognizer(ipGestureRecognizer) + } + + @objc private func handleTitleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { + if gestureRecognizer.state == .began { + self.displayCopyContextMenu(self.titleNode, self.titleNode.attributedText?.string ?? "") + } + } + + @objc private func handleDeviceLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { + if gestureRecognizer.state == .began { + self.displayCopyContextMenu(self.deviceValueNode, self.deviceValueNode.attributedText?.string ?? "") + } + } + + @objc private func handleLocationLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { + if gestureRecognizer.state == .began { + self.displayCopyContextMenu(self.locationValueNode, self.locationValueNode.attributedText?.string ?? "") + } + } + + @objc private func handleIpLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) { + if gestureRecognizer.state == .began { + self.displayCopyContextMenu(self.ipValueNode, self.ipValueNode.attributedText?.string ?? "") + } + } + + private func displayCopyContextMenu(_ node: ASDisplayNode, _ string: String) { + if !string.isEmpty { + var actions: [ContextMenuAction] = [] + actions.append(ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: { [weak self] in + UIPasteboard.general.string = string + + if let strongSelf = self { + let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } + strongSelf.controller?.present(UndoOverlayController(presentationData: presentationData, content: .copy(text: presentationData.strings.Conversation_TextCopied), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .window(.root)) + } + })) + let contextMenuController = ContextMenuController(actions: actions) + self.controller?.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in + if let strongSelf = self { + return (node, node.bounds.insetBy(dx: 0.0, dy: -2.0), strongSelf, strongSelf.view.bounds) + } else { + return nil + } + })) + } + } + func updatePresentationData(_ presentationData: PresentationData) { guard !self.animatedOut else { return @@ -427,16 +496,6 @@ private class RecentSessionScreenNode: ViewControllerTracingNode, UIScrollViewDe self.cancelButton.setImage(closeButtonImage(theme: self.presentationData.theme), for: .normal) self.terminateButton.updateTheme(SolidRoundedButtonTheme(backgroundColor: self.presentationData.theme.list.itemBlocksBackgroundColor, foregroundColor: self.presentationData.theme.list.itemDestructiveColor)) } - - override func didLoad() { - super.didLoad() - - if #available(iOSApplicationExtension 11.0, iOS 11.0, *) { - self.wrappingScrollNode.view.contentInsetAdjustmentBehavior = .never - } - - self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture))) - } @objc func cancelButtonPressed() { self.animateOut() @@ -486,6 +545,13 @@ private class RecentSessionScreenNode: ViewControllerTracingNode, UIScrollViewDe offsetCompleted = true internalCompletion() }) + + + self.controller?.window?.forEachController { c in + if let c = c as? UndoOverlayController { + c.dismiss() + } + } } var passthroughHitTestImpl: ((CGPoint) -> UIView?)? diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift index 745c267742..1016a473cb 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift @@ -14,17 +14,6 @@ import SearchBarNode import SearchUI import ChatListSearchItemHeader -/*extension NavigationBarSearchContentNode: ItemListControllerSearchNavigationContentNode { - public func activate() { - } - - public func deactivate() { - } - - public func setQueryUpdated(_ f: @escaping (String) -> Void) { - } -}*/ - extension SettingsSearchableItemIcon { func image() -> UIImage? { switch self { @@ -298,8 +287,14 @@ private enum SettingsSearchRecentEntry: Comparable, Identifiable { func item(account: Account, theme: PresentationTheme, strings: PresentationStrings, interaction: SettingsSearchInteraction) -> ListViewItem { switch self { - case let .recent(_, item, header), let .faq(_, item, header): - return SettingsSearchRecentItem(account: account, theme: theme, strings: strings, title: item.title, breadcrumbs: item.breadcrumbs, action: { + case let .recent(_, item, header): + return SettingsSearchRecentItem(account: account, theme: theme, strings: strings, title: item.title, breadcrumbs: item.breadcrumbs, isFaq: false, action: { + interaction.openItem(item) + }, deleted: { + interaction.deleteRecentItem(item.id) + }, header: header) + case let .faq(_, item, header): + return SettingsSearchRecentItem(account: account, theme: theme, strings: strings, title: item.title, breadcrumbs: item.breadcrumbs, isFaq: true, action: { interaction.openItem(item) }, deleted: { interaction.deleteRecentItem(item.id) diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift index 6ee7a4f1c9..9dc72ac32f 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchRecentItem.swift @@ -19,17 +19,19 @@ class SettingsSearchRecentItem: ListViewItem { let account: Account let title: String let breadcrumbs: [String] + let isFaq: Bool let action: () -> Void let deleted: () -> Void let header: ListViewItemHeader? - init(account: Account, theme: PresentationTheme, strings: PresentationStrings, title: String, breadcrumbs: [String], action: @escaping () -> Void, deleted: @escaping () -> Void, header: ListViewItemHeader) { + init(account: Account, theme: PresentationTheme, strings: PresentationStrings, title: String, breadcrumbs: [String], isFaq: Bool, action: @escaping () -> Void, deleted: @escaping () -> Void, header: ListViewItemHeader) { self.theme = theme self.strings = strings self.account = account self.title = title self.breadcrumbs = breadcrumbs + self.isFaq = isFaq self.action = action self.deleted = deleted self.header = header @@ -227,7 +229,12 @@ class SettingsSearchRecentItemNode: ItemListRevealOptionsItemNode { strongSelf.updateLayout(size: nodeLayout.contentSize, leftInset: params.leftInset, rightInset: params.rightInset) - strongSelf.setRevealOptions((left: [], right: [ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: item.strings.Common_Delete, icon: .none, color: item.theme.list.itemDisclosureActions.destructive.fillColor, textColor: item.theme.list.itemDisclosureActions.destructive.foregroundColor)])) + var revealOptions: [ItemListRevealOption] = [] + if item.isFaq { + } else { + revealOptions.append(ItemListRevealOption(key: RevealOptionKey.delete.rawValue, title: item.strings.Common_Delete, icon: .none, color: item.theme.list.itemDisclosureActions.destructive.fillColor, textColor: item.theme.list.itemDisclosureActions.destructive.foregroundColor)) + } + strongSelf.setRevealOptions((left: [], right: revealOptions)) } }) }) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index c73f0fc131..4bd668e436 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -5959,6 +5959,8 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } if self.isSettings { + (self.controller?.parent as? TabBarController)?.updateIsTabBarHidden(true, transition: .animated(duration: 0.3, curve: .linear)) + if let settings = self.data?.globalSettings { self.searchDisplayController = SearchDisplayController(presentationData: self.presentationData, mode: .list, placeholder: self.presentationData.strings.Settings_Search, hasBackground: true, hasSeparator: true, contentNode: SettingsSearchContainerNode(context: self.context, openResult: { [weak self] result in if let strongSelf = self, let navigationController = strongSelf.controller?.navigationController as? NavigationController { @@ -6038,6 +6040,10 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate self.searchDisplayController = nil searchDisplayController.deactivate(placeholder: nil) + if self.isSettings { + (self.controller?.parent as? TabBarController)?.updateIsTabBarHidden(false, transition: .animated(duration: 0.3, curve: .linear)) + } + let transition: ContainedViewLayoutTransition = .animated(duration: 0.35, curve: .easeInOut) if let navigationBar = self.controller?.navigationBar { transition.updateAlpha(node: navigationBar, alpha: 1.0)