137 lines
4.7 KiB
Swift
137 lines
4.7 KiB
Swift
//
|
|
// + MessageCellDelegate.swift
|
|
// Wallet
|
|
//
|
|
// Created by Saveliy Stavitsky on 2/9/21.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import MessageKit
|
|
import Foundation
|
|
import UIKit
|
|
|
|
extension CryptoChatControllerChat: MessageCellDelegate {
|
|
func didTapBackground(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Avatar background")
|
|
}
|
|
|
|
func didTapAvatar(in cell: MessageCollectionViewCell) {
|
|
print("Avatar tapped")
|
|
}
|
|
|
|
func didTapMessage(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Message tapped")
|
|
}
|
|
|
|
func didTapImage(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Image tapped")
|
|
guard let indexPath = messagesCollectionView.indexPath(for: cell) else { return }
|
|
guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return }
|
|
let msgData = messages[messages.count - loadedMsgsCount + indexPath.section].data
|
|
.dropFirst("<qr>".count).dropLast("</qr>".count)
|
|
if let data = convertStringToDictionary(text: String(msgData)),
|
|
let action = data["action"] as? String,
|
|
action == "transfer" {
|
|
let viewController = StoryboardScene.Wallet.transfer.instantiate()
|
|
viewController.hidesBack = true
|
|
viewController.dictionary = data
|
|
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
|
|
self.navigationController?.pushViewController(viewController, animated: true)
|
|
} else {
|
|
let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)
|
|
switch message.kind {
|
|
case .photo(let photoItem):
|
|
if let img = photoItem.image {
|
|
self.handleImageTap(image: img)
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
func didTapCellTopLabel(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Top cell label tapped")
|
|
}
|
|
|
|
func didTapCellBottomLabel(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Bottom cell label tapped")
|
|
}
|
|
|
|
func didTapMessageTopLabel(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Top message label tapped")
|
|
}
|
|
|
|
func didTapMessageBottomLabel(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Bottom label tapped")
|
|
}
|
|
|
|
func didTapPlayButton(in cell: AudioMessageCell) {
|
|
}
|
|
|
|
func didStartAudio(in cell: AudioMessageCell) {
|
|
print("Did start playing audio sound")
|
|
}
|
|
|
|
func didPauseAudio(in cell: AudioMessageCell) {
|
|
print("Did pause audio sound")
|
|
}
|
|
|
|
func didStopAudio(in cell: AudioMessageCell) {
|
|
print("Did stop audio sound")
|
|
}
|
|
|
|
func didTapAccessoryView(in cell: MessageCollectionViewCell) {
|
|
self.messageInputBar.inputTextView.resignFirstResponder()
|
|
print("Accessory view tapped")
|
|
}
|
|
|
|
func handleImageTap(image: UIImage) {
|
|
let view = UIView(frame: self.view.frame)
|
|
view.backgroundColor = .black
|
|
view.alpha = 0.5
|
|
self.view.addSubview(view)
|
|
|
|
let width = view.frame.width - 32 - 24
|
|
let height = width / ((image.size.width ?? 1) / (image.size.height ?? 1))
|
|
let center = CGPoint(x: view.frame.midX, y: view.frame.midY)
|
|
let rect = CGRect(x: 12,
|
|
y: 12,
|
|
width: width,
|
|
height: height)
|
|
|
|
let imageView = UIImageView(frame: rect)
|
|
imageView.image = image
|
|
imageView.contentMode = .scaleAspectFit
|
|
|
|
let rect2 = CGRect(x: center.x - (width / 2) - 12,
|
|
y: center.y - (height / 2) - 12,
|
|
width: width + 24,
|
|
height: height + 24)
|
|
let view2 = UIView(frame: rect2)
|
|
view2.backgroundColor = .white
|
|
view2.addSubview(imageView)
|
|
view2.layer.cornerRadius = 4
|
|
self.view.addSubview(view2)
|
|
|
|
let tap1 = UITapGestureRecognizer(trailingClosure: {
|
|
view.removeFromSuperview()
|
|
view2.removeFromSuperview()
|
|
})
|
|
let tap2 = UITapGestureRecognizer(trailingClosure: {
|
|
view.removeFromSuperview()
|
|
view2.removeFromSuperview()
|
|
})
|
|
view.addGestureRecognizer(tap1)
|
|
view2.addGestureRecognizer(tap2)
|
|
}
|
|
|
|
}
|