2018-08-28 01:27:34 +00:00
|
|
|
//
|
|
|
|
// ProfileHeaderTableViewCell.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/27/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import MastodonKit
|
|
|
|
|
|
|
|
protocol ProfileHeaderTableViewCellDelegate: StatusTableViewCellDelegate {
|
|
|
|
|
2018-08-28 21:53:59 +00:00
|
|
|
func showMoreOptions()
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
2018-08-28 01:27:34 +00:00
|
|
|
|
|
|
|
var delegate: ProfileHeaderTableViewCellDelegate?
|
|
|
|
|
|
|
|
@IBOutlet weak var displayNameLabel: UILabel!
|
|
|
|
@IBOutlet weak var usernameLabel: UILabel!
|
|
|
|
@IBOutlet weak var noteLabel: HTMLContentLabel!
|
|
|
|
@IBOutlet weak var avatarContainerView: UIView!
|
|
|
|
@IBOutlet weak var avatarImageView: UIImageView!
|
|
|
|
@IBOutlet weak var headerImageView: UIImageView!
|
|
|
|
|
|
|
|
var account: Account!
|
|
|
|
|
|
|
|
var avatarURL: URL?
|
|
|
|
|
|
|
|
var headerImageDownloadTask: URLSessionDataTask?
|
|
|
|
|
|
|
|
override func awakeFromNib() {
|
|
|
|
avatarContainerView.layer.masksToBounds = true
|
|
|
|
avatarImageView.layer.masksToBounds = true
|
2018-09-02 22:22:29 +00:00
|
|
|
avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(avatarPressed)))
|
|
|
|
avatarImageView.isUserInteractionEnabled = true
|
|
|
|
headerImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(headerPressed)))
|
|
|
|
headerImageView.isUserInteractionEnabled = true
|
2018-08-28 01:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
func updateUIForPreferences() {
|
|
|
|
avatarContainerView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarContainerView)
|
|
|
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
2018-08-29 01:18:58 +00:00
|
|
|
displayNameLabel.text = account.realDisplayName
|
2018-08-28 23:49:31 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
func updateUI(for account: Account) {
|
|
|
|
self.account = account
|
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
updateUIForPreferences()
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let url = URL(string: account.header) {
|
|
|
|
headerImageDownloadTask = URLSession.shared.dataTask(with: url) { data, response, error in
|
2018-09-03 20:54:03 +00:00
|
|
|
guard error == nil, let data = data, let image = UIImage(data: data) else { return }
|
2018-08-28 01:27:34 +00:00
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.headerImageView.image = image
|
|
|
|
self.headerImageDownloadTask = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
headerImageDownloadTask!.resume()
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: HTML parsing
|
|
|
|
noteLabel.text = account.note
|
|
|
|
noteLabel.delegate = self
|
|
|
|
}
|
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
if let url = avatarURL {
|
|
|
|
AvatarCache.shared.cancel(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-28 21:53:59 +00:00
|
|
|
@IBAction func morePressed(_ sender: Any) {
|
|
|
|
delegate?.showMoreOptions()
|
|
|
|
}
|
|
|
|
|
2018-09-02 22:22:29 +00:00
|
|
|
@objc func avatarPressed() {
|
|
|
|
delegate?.showLargeImage(avatarImageView.image!, description: nil, animatingFrom: avatarImageView)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func headerPressed() {
|
|
|
|
delegate?.showLargeImage(headerImageView.image!, description: nil, animatingFrom: headerImageView)
|
|
|
|
}
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension ProfileHeaderTableViewCell: HTMLContentLabelDelegate {
|
|
|
|
|
|
|
|
func selected(mention: Mention) {
|
|
|
|
delegate?.selected(mention: mention)
|
|
|
|
}
|
|
|
|
|
|
|
|
func selected(tag: Tag) {
|
|
|
|
delegate?.selected(tag: tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
func selected(url: URL) {
|
|
|
|
delegate?.selected(url: url)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|