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

View File

@ -28,6 +28,10 @@ extension Date {
return formatter return formatter
}() }()
public var abbreviatedDate: String {
return Date.abbreviatedDateFormatter.string(from: self)
}
public var localizedAbbreviatedSlowedTimeAgoSinceNow: String { public var localizedAbbreviatedSlowedTimeAgoSinceNow: String {
return Date.relativeTimestampFormatter.localizedString(for: self, relativeTo: Date()) return Date.relativeTimestampFormatter.localizedString(for: self, relativeTo: Date())
} }

View File

@ -97,6 +97,8 @@ public final class StatusCardControl: UIControl {
authorLabel.numberOfLines = 1 authorLabel.numberOfLines = 1
publisherLabel.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() var buttonConfiguration = UIButton.Configuration.filled()
buttonConfiguration.background.cornerRadius = 10 buttonConfiguration.background.cornerRadius = 10
@ -201,7 +203,14 @@ public final class StatusCardControl: UIControl {
} }
if let providerName = card.providerName { 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 publisherLabel.isHidden = false
} else { } else {
publisherLabel.isHidden = true publisherLabel.isHidden = true