Show account-information from entities
This commit is contained in:
parent
5058bac018
commit
7432b6f22b
|
@ -14,6 +14,7 @@ import MastodonMeta
|
|||
import MastodonCore
|
||||
import Meta
|
||||
import MastodonSDK
|
||||
import MastodonAsset
|
||||
|
||||
extension UserView {
|
||||
public func configure(user: MastodonUser, delegate: UserViewDelegate?) {
|
||||
|
@ -67,12 +68,51 @@ extension UserView {
|
|||
}
|
||||
|
||||
func configure(with account: Mastodon.Entity.Account) {
|
||||
//TODO: Implement
|
||||
viewModel.account = account
|
||||
viewModel.user = nil
|
||||
|
||||
// username
|
||||
let metaContent = PlaintextMetaContent(string: "@\(account.username)")
|
||||
authorUsernameLabel.configure(content: metaContent)
|
||||
let authorUsername = PlaintextMetaContent(string: "@\(account.username)")
|
||||
authorUsernameLabel.configure(content: authorUsername)
|
||||
|
||||
do {
|
||||
let emojis = account.emojis?.asDictionary ?? [:]
|
||||
let content = MastodonContent(content: account.displayNameWithFallback, emojis: emojis)
|
||||
let metaContent = try MastodonMetaContent.convert(document: content)
|
||||
authorNameLabel.configure(content: metaContent)
|
||||
} catch {
|
||||
let metaContent = PlaintextMetaContent(string: account.displayNameWithFallback)
|
||||
authorNameLabel.configure(content: metaContent)
|
||||
}
|
||||
|
||||
if let imageURL = account.avatarImageURL() {
|
||||
avatarButton.avatarImageView.af.setImage(withURL: imageURL)
|
||||
}
|
||||
|
||||
let count = account.followersCount
|
||||
authorFollowersLabel.attributedText = NSAttributedString(
|
||||
format: NSAttributedString(string: L10n.Common.UserList.followersCount("%@"), attributes: [.font: UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular))]),
|
||||
args: NSAttributedString(string: UserView.metricFormatter.string(from: count) ?? count.formatted(), attributes: [.font: UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .bold))])
|
||||
)
|
||||
|
||||
if let verifiedLinkField = account.verifiedLink {
|
||||
let link = verifiedLinkField.value
|
||||
|
||||
authorVerifiedImageView.image = UIImage(systemName: "checkmark")
|
||||
authorVerifiedImageView.tintColor = Asset.Colors.Brand.blurple.color
|
||||
authorVerifiedLabel.textColor = Asset.Colors.Brand.blurple.color
|
||||
do {
|
||||
let mastodonContent = MastodonContent(content: link, emojis: [:])
|
||||
let content = try MastodonMetaContent.convert(document: mastodonContent)
|
||||
authorVerifiedLabel.configure(content: content)
|
||||
} catch {
|
||||
let content = PlaintextMetaContent(string: link)
|
||||
authorVerifiedLabel.configure(content: content)
|
||||
}
|
||||
} else {
|
||||
authorVerifiedImageView.image = UIImage(systemName: "questionmark.circle")
|
||||
authorVerifiedImageView.tintColor = .secondaryLabel
|
||||
authorVerifiedLabel.configure(content: PlaintextMetaContent(string: L10n.Common.UserList.noVerifiedLink))
|
||||
authorVerifiedLabel.textColor = .secondaryLabel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public final class UserView: UIView {
|
|||
}
|
||||
|
||||
private var currentButtonState: ButtonState = .none
|
||||
public static var metricFormatter = MastodonMetricFormatter()
|
||||
|
||||
public weak var delegate: UserViewDelegate?
|
||||
|
||||
|
@ -102,7 +103,7 @@ public final class UserView: UIView {
|
|||
return label
|
||||
}()
|
||||
|
||||
private let followButtonWrapper = UIView()
|
||||
public let followButtonWrapper = UIView()
|
||||
private let followButton: UIButton = {
|
||||
var buttonConfiguration = UIButton.Configuration.filled()
|
||||
buttonConfiguration.background.cornerRadius = 10
|
||||
|
|
Loading…
Reference in New Issue