Show first verified link on account collection view cell

This commit is contained in:
Shadowfacts 2024-03-09 13:54:56 -05:00
parent bab0dd3294
commit 074b028015
1 changed files with 34 additions and 2 deletions

View File

@ -32,10 +32,11 @@ class AccountCollectionViewCell: UICollectionViewListCell {
private lazy var vStack = UIStackView(arrangedSubviews: [
displayNameLabel,
usernameLabel,
verifiedFieldHStack,
noteLabel,
]).configure {
$0.axis = .vertical
$0.spacing = 4
$0.spacing = 2
$0.alignment = .leading
}
@ -52,9 +53,29 @@ class AccountCollectionViewCell: UICollectionViewListCell {
$0.adjustsFontForContentSizeCategory = true
}
private lazy var verifiedFieldHStack = UIStackView(arrangedSubviews: [
verifiedFieldLabel,
verifiedFieldIcon,
]).configure {
$0.axis = .horizontal
$0.spacing = 4
}
private let verifiedFieldIcon = UIImageView().configure {
let image = UIImage(systemName: "checkmark", withConfiguration: UIImage.SymbolConfiguration(scale: .small))
$0.image = image
$0.tintColor = .systemGreen
}
private let verifiedFieldLabel = UILabel().configure {
$0.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold))
$0.textColor = .systemGreen
$0.adjustsFontForContentSizeCategory = true
}
private let noteLabel = EmojiLabel().configure {
$0.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15))
$0.numberOfLines = 2
$0.adjustsFontForContentSizeCategory = true
}
weak var delegate: (TuskerNavigationDelegate & MenuActionProvider)?
@ -121,6 +142,17 @@ class AccountCollectionViewCell: UICollectionViewListCell {
avatarImageView.update(for: account.avatar)
usernameLabel.text = "@\(account.acct)"
if let verifiedField = account.fields.first(where: { $0.verifiedAt != nil }) {
noteLabel.numberOfLines = 1
verifiedFieldHStack.isHidden = false
let converter = TextConverter(configuration: .init(insertNewlines: false), callbacks: HTMLConverter.Callbacks.self)
verifiedFieldLabel.text = converter.convert(html: verifiedField.value)
} else {
noteLabel.numberOfLines = 2
verifiedFieldHStack.isHidden = true
}
updateUIForPreferences(account: account)
}