Show (optional) published-date (IOS-284)

This commit is contained in:
Nathan Mattes 2024-06-29 19:00:36 +02:00
parent 96798f941c
commit a3b4528862
3 changed files with 17 additions and 2 deletions

View File

@ -36,6 +36,7 @@ extension Mastodon.Entity {
public let embedURL: String?
public let blurhash: String?
public let authors: [Mastodon.Entity.Card.Author]?
public let publishedAt: Date?
enum CodingKeys: String, CodingKey {
case url
@ -53,6 +54,7 @@ extension Mastodon.Entity {
case embedURL = "embed_url"
case blurhash
case authors
case publishedAt = "published_at"
}
}
}

View File

@ -27,7 +27,11 @@ extension Date {
formatter.timeStyle = .none // none
return formatter
}()
public var abbreviatedDate: String {
return Date.abbreviatedDateFormatter.string(from: self)
}
public var localizedAbbreviatedSlowedTimeAgoSinceNow: String {
return Date.relativeTimestampFormatter.localizedString(for: self, relativeTo: Date())
}

View File

@ -97,6 +97,8 @@ public final class StatusCardControl: UIControl {
authorLabel.numberOfLines = 1
publisherLabel.numberOfLines = 1
publisherLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .regular))
publisherLabel.textColor = .secondaryLabel
var buttonConfiguration = UIButton.Configuration.filled()
buttonConfiguration.background.cornerRadius = 10
@ -201,7 +203,14 @@ public final class StatusCardControl: UIControl {
}
if let providerName = card.providerName {
publisherLabel.text = providerName
let publisherDateText: String
if let formattedPublishedDate = card.publishedAt?.abbreviatedDate {
publisherDateText = "\(providerName) · \(formattedPublishedDate)"
} else {
publisherDateText = providerName
}
publisherLabel.text = publisherDateText
publisherLabel.isHidden = false
} else {
publisherLabel.isHidden = true