mastodon-app-ufficiale-ipho.../Mastodon/Scene/SuggestionAccount/TableView-Components/SuggestionAccountTableViewC...

105 lines
3.6 KiB
Swift
Raw Normal View History

2021-04-21 08:46:31 +02:00
//
// SuggestionAccountTableViewCell.swift
// Mastodon
//
// Created by sxiaojian on 2021/4/21.
//
import Combine
import CoreData
import CoreDataStack
import Foundation
import MastodonSDK
import UIKit
2021-07-23 13:10:27 +02:00
import MetaTextKit
import MastodonMeta
import MastodonAsset
import MastodonLocalization
2022-02-16 10:25:55 +01:00
import MastodonUI
import MastodonCore
2021-04-21 08:46:31 +02:00
protocol SuggestionAccountTableViewCellDelegate: AnyObject, UserViewDelegate {}
2021-04-21 08:46:31 +02:00
final class SuggestionAccountTableViewCell: UITableViewCell {
2023-05-12 22:06:44 +02:00
static let reuseIdentifier = "SuggestionAccountTableViewCell"
2021-04-21 08:46:31 +02:00
var disposeBag = Set<AnyCancellable>()
weak var delegate: SuggestionAccountTableViewCellDelegate?
let userView: UserView
let bioMetaLabel: MetaLabel
private let contentStackView: UIStackView
2021-04-21 11:58:56 +02:00
2021-04-21 08:46:31 +02:00
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
2022-02-16 10:25:55 +01:00
userView = UserView()
userView.translatesAutoresizingMaskIntoConstraints = false
bioMetaLabel = MetaLabel()
bioMetaLabel.translatesAutoresizingMaskIntoConstraints = false
bioMetaLabel.numberOfLines = 0
bioMetaLabel.textAttributes = [
.font: UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular)),
.foregroundColor: UIColor.label
]
bioMetaLabel.linkAttributes = [
.font: UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold)),
2023-06-02 09:52:12 +02:00
.foregroundColor: Asset.Colors.Brand.blurple.color
]
bioMetaLabel.isUserInteractionEnabled = false
2021-04-21 08:46:31 +02:00
contentStackView = UIStackView(arrangedSubviews: [userView, bioMetaLabel])
contentStackView.translatesAutoresizingMaskIntoConstraints = false
contentStackView.alignment = .leading
contentStackView.axis = .vertical
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(contentStackView)
2023-05-12 22:06:44 +02:00
backgroundColor = .systemBackground
setupConstraints()
2021-04-21 08:46:31 +02:00
}
required init?(coder: NSCoder) { fatalError("We don't support ancient technology like Storyboards") }
2022-02-16 10:25:55 +01:00
private func setupConstraints() {
let constraints = [
contentStackView.topAnchor.constraint(equalTo: contentView.topAnchor),
contentStackView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor),
contentView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: contentStackView.trailingAnchor),
contentView.bottomAnchor.constraint(equalTo: contentStackView.bottomAnchor, constant: 16),
userView.widthAnchor.constraint(equalTo: contentStackView.widthAnchor),
bioMetaLabel.widthAnchor.constraint(equalTo: contentStackView.widthAnchor),
]
NSLayoutConstraint.activate(constraints)
}
2022-02-16 10:25:55 +01:00
override func prepareForReuse() {
super.prepareForReuse()
disposeBag.removeAll()
}
func configure(account: Mastodon.Entity.Account, relationship: Mastodon.Entity.Relationship?) {
userView.configure(with: account, relationship: relationship, delegate: delegate)
userView.updateButtonState(with: relationship, isMe: false)
let metaContent: MetaContent = {
do {
let mastodonContent = MastodonContent(content: account.note, emojis: account.emojis?.asDictionary ?? [:])
return try MastodonMetaContent.convert(document: mastodonContent)
} catch {
assertionFailure()
return PlaintextMetaContent(string: account.note)
}
}()
bioMetaLabel.configure(content: metaContent)
2021-04-21 08:46:31 +02:00
}
}