Swiftgram/TelegramUI/ChatInterfaceStateNavigationButtons.swift
2017-09-26 03:01:24 +03:00

41 lines
1.7 KiB
Swift

import Foundation
import UIKit
enum ChatNavigationButtonAction {
case openChatInfo
case clearHistory
case cancelMessageSelection
}
struct ChatNavigationButton: Equatable {
let action: ChatNavigationButtonAction
let buttonItem: UIBarButtonItem
static func ==(lhs: ChatNavigationButton, rhs: ChatNavigationButton) -> Bool {
return lhs.action == rhs.action && lhs.buttonItem === rhs.buttonItem
}
}
func leftNavigationButtonForChatInterfaceState(_ chatInterfaceState: ChatInterfaceState, strings: PresentationStrings, currentButton: ChatNavigationButton?, target: Any?, selector: Selector?) -> ChatNavigationButton? {
if let _ = chatInterfaceState.selectionState {
if let currentButton = currentButton, currentButton.action == .clearHistory {
return currentButton
} else {
return ChatNavigationButton(action: .clearHistory, buttonItem: UIBarButtonItem(title: strings.Conversation_ClearAll, style: .plain, target: target, action: selector))
}
}
return nil
}
func rightNavigationButtonForChatInterfaceState(_ chatInterfaceState: ChatInterfaceState, strings: PresentationStrings, currentButton: ChatNavigationButton?, target: Any?, selector: Selector?, chatInfoNavigationButton: ChatNavigationButton?) -> ChatNavigationButton? {
if let _ = chatInterfaceState.selectionState {
if let currentButton = currentButton, currentButton.action == .cancelMessageSelection {
return currentButton
} else {
return ChatNavigationButton(action: .cancelMessageSelection, buttonItem: UIBarButtonItem(title: strings.Common_Cancel, style: .plain, target: target, action: selector))
}
}
return chatInfoNavigationButton
}