// // ConversationMainStatusTableViewCell.swift // Tusker // // Created by Shadowfacts on 8/28/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import UIKit import Combine import Pachyderm class ConversationMainStatusTableViewCell: BaseStatusTableViewCell { static let dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateStyle = .medium formatter.timeStyle = .medium return formatter }() @IBOutlet weak var profileDetailContainerView: UIView! @IBOutlet weak var favoriteAndReblogCountStackView: UIStackView! @IBOutlet weak var totalFavoritesButton: UIButton! @IBOutlet weak var totalReblogsButton: UIButton! @IBOutlet weak var timestampAndClientLabel: UILabel! var profileAccessibilityElement: UIAccessibilityElement! override func awakeFromNib() { super.awakeFromNib() profileAccessibilityElement = UIAccessibilityElement(accessibilityContainer: self) profileAccessibilityElement.accessibilityFrameInContainerSpace = profileDetailContainerView.convert(profileDetailContainerView.frame, to: self) accessibilityElements = [profileAccessibilityElement!, contentWarningLabel!, collapseButton!, contentLabel!, totalFavoritesButton!, totalReblogsButton!, timestampAndClientLabel!, replyButton!, favoriteButton!, reblogButton!, moreButton!] } override func updateUI(statusID: String) { super.updateUI(statusID: statusID) guard let status = MastodonCache.status(for: statusID) else { fatalError() } var timestampAndClientText = ConversationMainStatusTableViewCell.dateFormatter.string(from: status.createdAt) if let application = status.application { timestampAndClientText += " • \(application.name)" } timestampAndClientLabel.text = timestampAndClientText } override func updateStatusState(status: Status) { super.updateStatusState(status: status) // todo: localize me totalFavoritesButton.setTitle("\(status.favouritesCount) Favorite\(status.favouritesCount == 1 ? "" : "s")", for: .normal) totalReblogsButton.setTitle("\(status.reblogsCount) Reblog\(status.reblogsCount == 1 ? "" : "s")", for: .normal) } override func updateUI(account: Account) { super.updateUI(account: account) profileAccessibilityElement.accessibilityLabel = account.realDisplayName } @objc override func updateUIForPreferences() { super.updateUIForPreferences() favoriteAndReblogCountStackView.isHidden = !Preferences.shared.showFavoriteAndReblogCounts } @IBAction func totalFavoritesPressed() { if let delegate = delegate { // accounts aren't known, pass nil so the VC will load them let vc = delegate.statusActionAccountList(action: .favorite, statusID: statusID, accountIDs: nil) vc.showInacurateCountWarning = true delegate.show(vc) } } @IBAction func totalReblogsPressed() { if let delegate = delegate { // accounts aren't known, pass nil so the VC will load them let vc = delegate.statusActionAccountList(action: .reblog, statusID: statusID, accountIDs: nil) vc.showInacurateCountWarning = true delegate.show(vc) } } }