diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift index 4a1b88d0..bcf455ca 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift @@ -35,6 +35,7 @@ class ProfileHeaderView: UIView { @IBOutlet weak var relationshipLabel: UILabel! @IBOutlet weak var noteTextView: StatusContentTextView! @IBOutlet weak var fieldsView: ProfileFieldsView! + @IBOutlet weak var followCountButton: UIButton! private(set) var pagesSegmentedControl: ScrollingSegmentedControl! var accountID: String! @@ -148,6 +149,26 @@ class ProfileHeaderView: UIView { fieldsView.delegate = delegate fieldsView.updateUI(account: account) + let (followingAbbr, followingSpelledOut) = formatBigNumber(account.followingCount) + let (followersAbbr, followersSpelledOut) = formatBigNumber(account.followersCount) + let followCountTitle = NSMutableAttributedString() + followCountTitle.append(NSAttributedString(string: followingAbbr, attributes: [ + .font: UIFont.preferredFont(forTextStyle: .body).withTraits(.traitBold)!, + .foregroundColor: UIColor.label, + ])) + followCountTitle.append(NSAttributedString(string: " Following, ", attributes: [ + .foregroundColor: UIColor.secondaryLabel, + ])) + followCountTitle.append(NSAttributedString(string: followersAbbr, attributes: [ + .font: UIFont.preferredFont(forTextStyle: .body).withTraits(.traitBold)!, + .foregroundColor: UIColor.label, + ])) + followCountTitle.append(NSAttributedString(string: " Follower\(account.followersCount == 1 ? "" : "s")", attributes: [ + .foregroundColor: UIColor.secondaryLabel, + ])) + followCountButton.setAttributedTitle(followCountTitle, for: .normal) + followCountButton.accessibilityLabel = "\(followingSpelledOut) following, \(followersSpelledOut) followers" + accessibilityElements = [ displayNameLabel!, usernameLabel!, @@ -260,6 +281,22 @@ class ProfileHeaderView: UIView { } } + private func formatBigNumber(_ value: Int) -> (String, String) { + let formatter = NumberFormatter() + formatter.maximumFractionDigits = 1 + + for (threshold, abbr, spelledOut) in [(1_000_000, "m", "million"), (1_000, "k", "thousand")] { + if value >= threshold { + let frac = Double(value) / Double(threshold) + let s = formatter.string(from: frac as NSNumber)! + return ("\(s)\(abbr)", "\(s) \(spelledOut)") + } + } + + let s = formatter.string(from: value as NSNumber)! + return (s, s) + } + // MARK: Interaction @objc func avatarPressed() { @@ -313,6 +350,8 @@ class ProfileHeaderView: UIView { } } + @IBAction func followCountButtonPressed(_ sender: Any) { + } } extension ProfileHeaderView { diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.xib b/Tusker/Views/Profile Header/ProfileHeaderView.xib index 8bf8a393..b1b73820 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.xib +++ b/Tusker/Views/Profile Header/ProfileHeaderView.xib @@ -61,7 +61,7 @@ - + - + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - + + + + + + + + + @@ -149,6 +167,7 @@ +