feat: Implement real numbers of HashtagTimelineHeader

This commit is contained in:
Marcus Kida 2022-11-23 17:54:53 +01:00
parent 9d245d3205
commit b020f566f4
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
4 changed files with 102 additions and 3 deletions

View File

@ -8,6 +8,7 @@
import UIKit
import MastodonSDK
import MastodonUI
import MastodonAsset
fileprivate extension CGFloat {
static let padding: CGFloat = 16
@ -32,7 +33,6 @@ final class HashtagTimelineHeaderView: UIView {
button.cornerRadius = 10
button.contentEdgeInsets = UIEdgeInsets(top: 6, left: 16, bottom: 5, right: 16) // set 28pt height
button.titleLabel?.font = .systemFont(ofSize: 14, weight: .bold)
button.backgroundColor = .black
return button
}()
@ -101,8 +101,7 @@ private extension HashtagTimelineHeaderView {
followButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -CGFloat.padding),
followButton.bottomAnchor.constraint(equalTo: postsTodayDescLabel.bottomAnchor),
followButton.topAnchor.constraint(equalTo: postsTodayLabel.topAnchor),
followButton.widthAnchor.constraint(equalToConstant: 84)
followButton.topAnchor.constraint(equalTo: postsTodayLabel.topAnchor)
])
}
}
@ -111,6 +110,28 @@ extension HashtagTimelineHeaderView {
func update(_ entity: Mastodon.Entity.Tag) {
titleLabel.text = "#\(entity.name)"
followButton.setTitle(entity.following == true ? "Unfollow" : "Follow", for: .normal)
followButton.backgroundColor = entity.following == true ? Asset.Colors.Button.tagUnfollow.color : Asset.Colors.Button.tagFollow.color
followButton.setTitleColor(
entity.following == true ? Asset.Colors.Button.tagFollow.color : Asset.Colors.Button.tagUnfollow.color,
for: .normal
)
if let history = entity.history {
postCountLabel.text = String(
history.reduce(0) { res, acc in
res + (Int(acc.uses) ?? 0)
}
)
participantsLabel.text = String(
history.reduce(0) { res, acc in
res + (Int(acc.accounts) ?? 0)
}
)
postsTodayLabel.text = history.first?.uses
}
}
func updateWidthConstraint(_ constant: CGFloat) {

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x38",
"green" : "0x29",
"red" : "0x2B"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "0.700",
"blue" : "0x38",
"green" : "0x29",
"red" : "0x2B"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0xFF",
"red" : "0xFF"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "0.250",
"blue" : "0x38",
"green" : "0x29",
"red" : "0x2B"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -49,6 +49,8 @@ public enum Asset {
public static let actionToolbar = ColorAsset(name: "Colors/Button/action.toolbar")
public static let disabled = ColorAsset(name: "Colors/Button/disabled")
public static let inactive = ColorAsset(name: "Colors/Button/inactive")
public static let tagFollow = ColorAsset(name: "Colors/Button/tagFollow")
public static let tagUnfollow = ColorAsset(name: "Colors/Button/tagUnfollow")
}
public enum Icon {
public static let plus = ColorAsset(name: "Colors/Icon/plus")