From d94a0050b79d58923fe73194035d942264724afe Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 1 Apr 2019 19:34:50 -0400 Subject: [PATCH] Show fields in profiles Closes #19 --- Pachyderm/Model/Account.swift | 4 +-- .../Profile/ProfileTableViewController.swift | 2 +- .../ProfileHeaderTableViewCell.swift | 36 ++++++++++++++++--- .../ProfileHeaderTableViewCell.xib | 27 +++++++++++--- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/Pachyderm/Model/Account.swift b/Pachyderm/Model/Account.swift index c1a3ba31..9540d6a2 100644 --- a/Pachyderm/Model/Account.swift +++ b/Pachyderm/Model/Account.swift @@ -124,7 +124,7 @@ extension Account: CustomDebugStringConvertible { extension Account { public struct Field: Codable { - let name: String - let value: String + public let name: String + public let value: String } } diff --git a/Tusker/Screens/Profile/ProfileTableViewController.swift b/Tusker/Screens/Profile/ProfileTableViewController.swift index e61e82d5..2235f0f4 100644 --- a/Tusker/Screens/Profile/ProfileTableViewController.swift +++ b/Tusker/Screens/Profile/ProfileTableViewController.swift @@ -180,8 +180,8 @@ class ProfileTableViewController: EnhancedTableViewController, PreferencesAdapti case 0: guard let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as? ProfileHeaderTableViewCell else { fatalError() } cell.selectionStyle = .none - cell.updateUI(for: accountID) cell.delegate = self + cell.updateUI(for: accountID) return cell case 1: guard let cell = tableView.dequeueReusableCell(withIdentifier: "statusCell", for: indexPath) as? StatusTableViewCell else { fatalError() } diff --git a/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift b/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift index b6deb8f2..8b748767 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift @@ -15,11 +15,7 @@ protocol ProfileHeaderTableViewCellDelegate: TuskerNavigationDelegate { class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { - var delegate: ProfileHeaderTableViewCellDelegate? { - didSet { - noteLabel.navigationDelegate = delegate - } - } + var delegate: ProfileHeaderTableViewCellDelegate? @IBOutlet weak var headerImageView: UIImageView! @IBOutlet weak var avatarContainerView: UIView! @@ -28,6 +24,9 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { @IBOutlet weak var usernameLabel: UILabel! @IBOutlet weak var followsYouLabel: UILabel! @IBOutlet weak var noteLabel: StatusContentLabel! + @IBOutlet weak var fieldsStackView: UIStackView! + @IBOutlet weak var fieldNamesStackView: UIStackView! + @IBOutlet weak var fieldValuesStack: UIStackView! var accountID: String! @@ -52,7 +51,9 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { } func updateUI(for accountID: String) { + guard accountID != self.accountID else { return } self.accountID = accountID + guard let account = MastodonCache.account(for: accountID) else { fatalError("Missing cached account \(accountID)") } updateUIForPreferences() @@ -76,7 +77,9 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { } } + noteLabel.navigationDelegate = delegate noteLabel.setTextFromHtml(account.note) + noteLabel.setEmojis(account.emojis) if accountID != MastodonController.account.id { // don't show relationship label for the user's own account @@ -90,6 +93,29 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { } } } + + if let fields = account.fields, !fields.isEmpty { + fieldsStackView.isHidden = false + + for field in fields { + let nameLabel = UILabel() + nameLabel.text = field.name + nameLabel.font = .boldSystemFont(ofSize: 17) + nameLabel.textAlignment = .right + fieldNamesStackView.addArrangedSubview(nameLabel) + + let valueLabel = ContentLabel() + valueLabel.setTextFromHtml(field.value) + valueLabel.setEmojis(account.emojis) + valueLabel.font = .systemFont(ofSize: 17) + valueLabel.textAlignment = .left + valueLabel.awakeFromNib() // TODO: this shouldn't be necessary + valueLabel.navigationDelegate = delegate + fieldValuesStack.addArrangedSubview(valueLabel) + } + } else { + fieldsStackView.isHidden = true + } } override func prepareForReuse() { diff --git a/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.xib b/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.xib index efd4b747..c99e2c66 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.xib +++ b/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.xib @@ -1,10 +1,10 @@ - + - + @@ -54,7 +54,7 @@ - + + + + + + + + + + + +