Tusker/Tusker/Views/StatusTableViewCell.swift

62 lines
1.6 KiB
Swift
Raw Normal View History

2018-08-17 02:39:16 +00:00
//
// StatusTableViewCell.swift
// Tusker
//
// Created by Shadowfacts on 8/16/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
import MastodonKit
import SwiftSoup
class StatusTableViewCell: UITableViewCell {
@IBOutlet weak var displayNameLabel: UILabel!
@IBOutlet weak var usernameLabel: UILabel!
2018-08-26 18:49:22 +00:00
@IBOutlet weak var contentLabel: StatusContentLabel!
2018-08-21 23:23:27 +00:00
@IBOutlet weak var avatarImageView: UIImageView!
2018-08-17 02:39:16 +00:00
var status: Status!
2018-08-21 23:23:27 +00:00
var avatarURL: URL?
var layoutManager: NSLayoutManager!
var textContainer: NSTextContainer!
var textStorage: NSTextStorage!
var links: [NSRange: URL] = [:]
2018-08-17 02:39:16 +00:00
func updateUI(for status: Status) {
self.status = status
let account: Account
if let reblog = status.reblog {
account = reblog.account
} else {
account = status.account
}
displayNameLabel.text = account.displayName
usernameLabel.text = "@\(account.acct)"
2018-08-21 23:23:27 +00:00
avatarImageView.layer.cornerRadius = 5
avatarImageView.layer.masksToBounds = true
avatarImageView.image = nil
if let url = URL(string: account.avatar) {
AvatarCache.shared.get(url) { image in
DispatchQueue.main.async {
self.avatarImageView.image = image
}
}
}
2018-08-26 18:49:22 +00:00
contentLabel.text = status.content
}
2018-08-21 23:23:27 +00:00
override func prepareForReuse() {
if let url = avatarURL {
AvatarCache.shared.cancel(url)
}
}
2018-08-17 02:39:16 +00:00
}