forked from shadowfacts/Tusker
101 lines
2.9 KiB
Swift
101 lines
2.9 KiB
Swift
//
|
|
// ConversationMainStatusTableViewCell.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 8/28/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import MastodonKit
|
|
|
|
class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|
|
|
var delegate: StatusTableViewCellDelegate?
|
|
|
|
@IBOutlet weak var displayNameLabel: UILabel!
|
|
@IBOutlet weak var usernameLabel: UILabel!
|
|
@IBOutlet weak var contentLabel: StatusContentLabel!
|
|
@IBOutlet weak var avatarImageView: UIImageView!
|
|
|
|
var status: Status!
|
|
var account: Account!
|
|
|
|
var avatarURL: URL?
|
|
|
|
override func awakeFromNib() {
|
|
displayNameLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
displayNameLabel.isUserInteractionEnabled = true
|
|
usernameLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
usernameLabel.isUserInteractionEnabled = true
|
|
avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
avatarImageView.isUserInteractionEnabled = true
|
|
avatarImageView.layer.masksToBounds = true
|
|
}
|
|
|
|
func updateUIForPreferences() {
|
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
|
displayNameLabel.text = account.realDisplayName
|
|
}
|
|
|
|
func updateUI(for status: Status) {
|
|
self.status = status
|
|
|
|
let account: Account
|
|
if let reblog = status.reblog {
|
|
account = reblog.account
|
|
} else {
|
|
account = status.account
|
|
}
|
|
self.account = account
|
|
|
|
updateUIForPreferences()
|
|
|
|
usernameLabel.text = "@\(account.acct)"
|
|
avatarImageView.image = nil
|
|
if let url = URL(string: account.avatar) {
|
|
avatarURL = url
|
|
AvatarCache.shared.get(url) { image in
|
|
DispatchQueue.main.async {
|
|
self.avatarImageView.image = image
|
|
self.avatarURL = nil
|
|
}
|
|
}
|
|
}
|
|
|
|
contentLabel.status = status
|
|
contentLabel.delegate = self
|
|
}
|
|
|
|
override func prepareForReuse() {
|
|
if let url = avatarURL {
|
|
AvatarCache.shared.cancel(url)
|
|
}
|
|
}
|
|
|
|
@objc func accountPressed() {
|
|
delegate?.selected(account: account)
|
|
}
|
|
|
|
@IBAction func replyPressed(_ sender: Any) {
|
|
delegate?.reply(to: status)
|
|
}
|
|
|
|
}
|
|
|
|
extension ConversationMainStatusTableViewCell: HTMLContentLabelDelegate {
|
|
|
|
func selected(mention: Mention) {
|
|
delegate?.selected(mention: mention)
|
|
}
|
|
|
|
func selected(tag: MastodonKit.Tag) {
|
|
delegate?.selected(tag: tag)
|
|
}
|
|
|
|
func selected(url: URL) {
|
|
delegate?.selected(url: url)
|
|
}
|
|
|
|
}
|