Show account-information from entities
This commit is contained in:
parent
5058bac018
commit
7432b6f22b
|
@ -14,6 +14,7 @@ import MastodonMeta
|
||||||
import MastodonCore
|
import MastodonCore
|
||||||
import Meta
|
import Meta
|
||||||
import MastodonSDK
|
import MastodonSDK
|
||||||
|
import MastodonAsset
|
||||||
|
|
||||||
extension UserView {
|
extension UserView {
|
||||||
public func configure(user: MastodonUser, delegate: UserViewDelegate?) {
|
public func configure(user: MastodonUser, delegate: UserViewDelegate?) {
|
||||||
|
@ -67,12 +68,51 @@ extension UserView {
|
||||||
}
|
}
|
||||||
|
|
||||||
func configure(with account: Mastodon.Entity.Account) {
|
func configure(with account: Mastodon.Entity.Account) {
|
||||||
//TODO: Implement
|
|
||||||
viewModel.account = account
|
viewModel.account = account
|
||||||
viewModel.user = nil
|
viewModel.user = nil
|
||||||
|
|
||||||
// username
|
let authorUsername = PlaintextMetaContent(string: "@\(account.username)")
|
||||||
let metaContent = PlaintextMetaContent(string: "@\(account.username)")
|
authorUsernameLabel.configure(content: authorUsername)
|
||||||
authorUsernameLabel.configure(content: metaContent)
|
|
||||||
|
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,7 +26,8 @@ public final class UserView: UIView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private var currentButtonState: ButtonState = .none
|
private var currentButtonState: ButtonState = .none
|
||||||
|
public static var metricFormatter = MastodonMetricFormatter()
|
||||||
|
|
||||||
public weak var delegate: UserViewDelegate?
|
public weak var delegate: UserViewDelegate?
|
||||||
|
|
||||||
public var disposeBag = Set<AnyCancellable>()
|
public var disposeBag = Set<AnyCancellable>()
|
||||||
|
@ -102,7 +103,7 @@ public final class UserView: UIView {
|
||||||
return label
|
return label
|
||||||
}()
|
}()
|
||||||
|
|
||||||
private let followButtonWrapper = UIView()
|
public let followButtonWrapper = UIView()
|
||||||
private let followButton: UIButton = {
|
private let followButton: UIButton = {
|
||||||
var buttonConfiguration = UIButton.Configuration.filled()
|
var buttonConfiguration = UIButton.Configuration.filled()
|
||||||
buttonConfiguration.background.cornerRadius = 10
|
buttonConfiguration.background.cornerRadius = 10
|
||||||
|
|
Loading…
Reference in New Issue