Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable keyboard buttons when one pressed #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 59 additions & 48 deletions TelegramUI/ChatButtonKeyboardInputNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ private final class ChatButtonKeyboardInputButtonNode: ASButtonNode {
func updateTheme(theme: PresentationTheme) {
if theme !== self.theme {
self.theme = theme

self.setBackgroundImage(PresentationResourcesChat.chatInputButtonPanelButtonImage(theme), for: [])
self.setBackgroundImage(PresentationResourcesChat.chatInputButtonPanelButtonHighlightedImage(theme), for: [.highlighted])
let highlightedImage = PresentationResourcesChat.chatInputButtonPanelButtonHighlightedImage(theme)
self.setBackgroundImage(highlightedImage, for: .highlighted)
self.setBackgroundImage(highlightedImage, for: .selected)
}
}
}
Expand Down Expand Up @@ -87,7 +89,8 @@ final class ChatButtonKeyboardInputNode: ChatInputNode {
}
}
}


let messageChanged = self.message?.id != interfaceState.keyboardButtonsMessage?.id
self.message = interfaceState.keyboardButtonsMessage

if let markup = validatedMarkup {
Expand Down Expand Up @@ -116,6 +119,10 @@ final class ChatButtonKeyboardInputNode: ChatInputNode {
if buttonIndex < self.buttonNodes.count {
buttonNode = self.buttonNodes[buttonIndex]
buttonNode.updateTheme(theme: interfaceState.theme)
if messageChanged {
buttonNode.isEnabled = true
buttonNode.isSelected = false
}
} else {
buttonNode = ChatButtonKeyboardInputButtonNode(theme: interfaceState.theme)
buttonNode.titleNode.maximumNumberOfLines = 2
Expand Down Expand Up @@ -156,55 +163,59 @@ final class ChatButtonKeyboardInputNode: ChatInputNode {
}
}

@objc func buttonPressed(_ button: ASButtonNode) {
if let button = button as? ChatButtonKeyboardInputButtonNode, let markupButton = button.button {
switch markupButton.action {
case .text:
self.controllerInteraction.sendMessage(markupButton.title)
case let .url(url):
self.controllerInteraction.openUrl(url, true, nil)
case .requestMap:
self.controllerInteraction.shareCurrentLocation()
case .requestPhone:
self.controllerInteraction.shareAccountContact()
case .openWebApp:
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, nil, true)
@objc private func buttonPressed(_ button: ChatButtonKeyboardInputButtonNode) {
button.isSelected = true
for buttonNode in self.buttonNodes {
buttonNode.isEnabled = false
}

let markupButton = button.button!
switch markupButton.action {
case .text:
self.controllerInteraction.sendMessage(markupButton.title)
case let .url(url):
self.controllerInteraction.openUrl(url, true, nil)
case .requestMap:
self.controllerInteraction.shareCurrentLocation()
case .requestPhone:
self.controllerInteraction.shareAccountContact()
case .openWebApp:
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, nil, true)
}
case let .callback(data):
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, data, false)
}
case let .switchInline(samePeer, query):
if let message = message {
var botPeer: Peer?

var found = false
for attribute in message.attributes {
if let attribute = attribute as? InlineBotMessageAttribute, let peerId = attribute.peerId {
botPeer = message.peers[peerId]
found = true
}
}
case let .callback(data):
if let message = self.message {
self.controllerInteraction.requestMessageActionCallback(message.id, data, false)
if !found {
botPeer = message.author
}
case let .switchInline(samePeer, query):
if let message = message {
var botPeer: Peer?

var found = false
for attribute in message.attributes {
if let attribute = attribute as? InlineBotMessageAttribute, let peerId = attribute.peerId {
botPeer = message.peers[peerId]
found = true
}
}
if !found {
botPeer = message.author
}

var peerId: PeerId?
if samePeer {
peerId = message.id.peerId
}
if let botPeer = botPeer, let addressName = botPeer.addressName {
self.controllerInteraction.openPeer(peerId, .chat(textInputState: ChatTextInputState(inputText: NSAttributedString(string: "@\(addressName) \(query)")), messageId: nil), nil)
}

var peerId: PeerId?
if samePeer {
peerId = message.id.peerId
}
case .payment:
break
case let .urlAuth(url, buttonId):
if let message = self.message {
self.controllerInteraction.requestMessageActionUrlAuth(url, message.id, buttonId)
if let botPeer = botPeer, let addressName = botPeer.addressName {
self.controllerInteraction.openPeer(peerId, .chat(textInputState: ChatTextInputState(inputText: NSAttributedString(string: "@\(addressName) \(query)")), messageId: nil), nil)
}
}
}
case .payment:
break
case let .urlAuth(url, buttonId):
if let message = self.message {
self.controllerInteraction.requestMessageActionUrlAuth(url, message.id, buttonId)
}
}
}
}