From b9fb58b312ffde7bf93d1a3c9470ac8541569d19 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 4 Apr 2022 20:06:05 +0400 Subject: [PATCH] Update menu --- .../ContextControllerActionsStackNode.swift | 22 ++++-- .../Sources/PeerInfo/PeerInfoScreen.swift | 73 ++++++++++--------- 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/submodules/ContextUI/Sources/ContextControllerActionsStackNode.swift b/submodules/ContextUI/Sources/ContextControllerActionsStackNode.swift index 8a59bc8e9a..b30ea3e75f 100644 --- a/submodules/ContextUI/Sources/ContextControllerActionsStackNode.swift +++ b/submodules/ContextUI/Sources/ContextControllerActionsStackNode.swift @@ -13,7 +13,8 @@ public protocol ContextControllerActionsStackItemNode: ASDisplayNode { func update( presentationData: PresentationData, constrainedSize: CGSize, - standardWidth: CGFloat, + standardMinWidth: CGFloat, + standardMaxWidth: CGFloat, transition: ContainedViewLayoutTransition ) -> (size: CGSize, apparentHeight: CGFloat) @@ -476,7 +477,8 @@ final class ContextControllerActionsListStackItem: ContextControllerActionsStack func update( presentationData: PresentationData, constrainedSize: CGSize, - standardWidth: CGFloat, + standardMinWidth: CGFloat, + standardMaxWidth: CGFloat, transition: ContainedViewLayoutTransition ) -> (size: CGSize, apparentHeight: CGFloat) { var itemNodeLayouts: [(minSize: CGSize, apply: (_ size: CGSize, _ transition: ContainedViewLayoutTransition) -> Void)] = [] @@ -486,13 +488,13 @@ final class ContextControllerActionsListStackItem: ContextControllerActionsStack let itemNodeLayout = item.node.update( presentationData: presentationData, - constrainedSize: CGSize(width: standardWidth, height: constrainedSize.height) + constrainedSize: CGSize(width: standardMaxWidth, height: constrainedSize.height) ) itemNodeLayouts.append(itemNodeLayout) combinedSize.width = max(combinedSize.width, itemNodeLayout.minSize.width) combinedSize.height += itemNodeLayout.minSize.height } - combinedSize.width = max(combinedSize.width, standardWidth) + combinedSize.width = max(combinedSize.width, standardMinWidth) var nextItemOrigin = CGPoint() for i in 0 ..< self.itemNodes.count { @@ -619,7 +621,8 @@ final class ContextControllerActionsCustomStackItem: ContextControllerActionsSta func update( presentationData: PresentationData, constrainedSize: CGSize, - standardWidth: CGFloat, + standardMinWidth: CGFloat, + standardMaxWidth: CGFloat, transition: ContainedViewLayoutTransition ) -> (size: CGSize, apparentHeight: CGFloat) { let contentLayout = self.contentNode.update( @@ -830,14 +833,16 @@ final class ContextControllerActionsStackNode: ASDisplayNode { func update( presentationData: PresentationData, constrainedSize: CGSize, - standardWidth: CGFloat, + standardMinWidth: CGFloat, + standardMaxWidth: CGFloat, transitionFraction: CGFloat, transition: ContainedViewLayoutTransition ) -> (size: CGSize, apparentHeight: CGFloat) { let (size, apparentHeight) = self.node.update( presentationData: presentationData, constrainedSize: constrainedSize, - standardWidth: standardWidth, + standardMinWidth: standardMinWidth, + standardMaxWidth: standardMaxWidth, transition: transition ) @@ -1076,7 +1081,8 @@ final class ContextControllerActionsStackNode: ASDisplayNode { let itemSize = itemContainer.update( presentationData: presentationData, constrainedSize: CGSize(width: constrainedSize.width, height: itemConstrainedHeight), - standardWidth: 250.0, + standardMinWidth: 220.0, + standardMaxWidth: 240.0, transitionFraction: alphaTransitionFraction, transition: itemContainerTransition ) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 8aed53a141..dd1df3eb29 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -3542,40 +3542,6 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate var items: [ContextMenuItem] = [] - var isSoundEnabled = true - if let notificationSettings = self.data?.notificationSettings { - switch notificationSettings.messageSound { - case .none: - isSoundEnabled = false - default: - break - } - } - - if !isSoundEnabled { - items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.PeerInfo_EnableSound, icon: { theme in - return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Unmute"), color: theme.contextMenu.primaryColor) - }, action: { [weak self] _, f in - f(.default) - - guard let strongSelf = self else { - return - } - let _ = strongSelf.context.engine.peers.updatePeerNotificationSoundInteractive(peerId: strongSelf.peerId, sound: .default).start() - }))) - } else { - items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.PeerInfo_DisableSound, icon: { theme in - return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Muted"), color: theme.contextMenu.primaryColor) - }, action: { [weak self] _, f in - f(.default) - - guard let strongSelf = self else { - return - } - let _ = strongSelf.context.engine.peers.updatePeerNotificationSoundInteractive(peerId: strongSelf.peerId, sound: .none).start() - }))) - } - items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.PeerInfo_MuteFor, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Mute2d"), color: theme.contextMenu.primaryColor) }, action: { [weak self] c, _ in @@ -3622,6 +3588,42 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate c.pushItems(items: .single(ContextController.Items(content: .list(subItems)))) }))) + items.append(.separator) + + var isSoundEnabled = true + if let notificationSettings = self.data?.notificationSettings { + switch notificationSettings.messageSound { + case .none: + isSoundEnabled = false + default: + break + } + } + + if !isSoundEnabled { + items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.PeerInfo_EnableSound, icon: { theme in + return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Unmute"), color: theme.contextMenu.primaryColor) + }, action: { [weak self] _, f in + f(.default) + + guard let strongSelf = self else { + return + } + let _ = strongSelf.context.engine.peers.updatePeerNotificationSoundInteractive(peerId: strongSelf.peerId, sound: .default).start() + }))) + } else { + items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.PeerInfo_DisableSound, icon: { theme in + return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Muted"), color: theme.contextMenu.primaryColor) + }, action: { [weak self] _, f in + f(.default) + + guard let strongSelf = self else { + return + } + let _ = strongSelf.context.engine.peers.updatePeerNotificationSoundInteractive(peerId: strongSelf.peerId, sound: .none).start() + }))) + } + items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.PeerInfo_NotificationsCustomize, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Customize"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in @@ -3795,8 +3797,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate subItems.append(.separator) let presetValues: [Int32] = [ - 60 * 60, - 24 * 60 * 60, + 1 * 24 * 60 * 60, 7 * 24 * 60 * 60, 31 * 24 * 60 * 60 ]