From b020f566f47012e9e87edb48537e767d32129700 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Wed, 23 Nov 2022 17:54:53 +0100 Subject: [PATCH] feat: Implement real numbers of HashtagTimelineHeader --- .../HashtagTimelineHeaderView.swift | 27 +++++++++++-- .../Button/tagFollow.colorset/Contents.json | 38 +++++++++++++++++++ .../Button/tagUnfollow.colorset/Contents.json | 38 +++++++++++++++++++ .../MastodonAsset/Generated/Assets.swift | 2 + 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagFollow.colorset/Contents.json create mode 100644 MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagUnfollow.colorset/Contents.json diff --git a/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift b/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift index 49442c03d..996c18ffb 100644 --- a/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift +++ b/Mastodon/Scene/HashtagTimeline/HashtagTimelineHeaderView.swift @@ -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) { diff --git a/MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagFollow.colorset/Contents.json b/MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagFollow.colorset/Contents.json new file mode 100644 index 000000000..9bc42278d --- /dev/null +++ b/MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagFollow.colorset/Contents.json @@ -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 + } +} diff --git a/MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagUnfollow.colorset/Contents.json b/MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagUnfollow.colorset/Contents.json new file mode 100644 index 000000000..2790f171d --- /dev/null +++ b/MastodonSDK/Sources/MastodonAsset/Assets.xcassets/Colors/Button/tagUnfollow.colorset/Contents.json @@ -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 + } +} diff --git a/MastodonSDK/Sources/MastodonAsset/Generated/Assets.swift b/MastodonSDK/Sources/MastodonAsset/Generated/Assets.swift index 155227685..607fe4390 100644 --- a/MastodonSDK/Sources/MastodonAsset/Generated/Assets.swift +++ b/MastodonSDK/Sources/MastodonAsset/Generated/Assets.swift @@ -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")