From 074b0280152e04c61991d35a8e0db3e62ef3e668 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 9 Mar 2024 13:54:56 -0500 Subject: [PATCH] Show first verified link on account collection view cell --- .../AccountCollectionViewCell.swift | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Tusker/Views/Account Cell/AccountCollectionViewCell.swift b/Tusker/Views/Account Cell/AccountCollectionViewCell.swift index 128fa63a..b6c3d4c3 100644 --- a/Tusker/Views/Account Cell/AccountCollectionViewCell.swift +++ b/Tusker/Views/Account Cell/AccountCollectionViewCell.swift @@ -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) }