2018-08-28 18:29:06 +00:00
|
|
|
//
|
|
|
|
// ConversationMainStatusTableViewCell.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/28/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2019-08-02 03:01:15 +00:00
|
|
|
import Combine
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2018-08-28 18:29:06 +00:00
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
class ConversationMainStatusTableViewCell: BaseStatusTableViewCell {
|
2018-08-28 18:29:06 +00:00
|
|
|
|
2019-09-07 21:10:58 +00:00
|
|
|
static let dateFormatter: DateFormatter = {
|
|
|
|
let formatter = DateFormatter()
|
|
|
|
formatter.dateStyle = .medium
|
|
|
|
formatter.timeStyle = .medium
|
|
|
|
return formatter
|
|
|
|
}()
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-09-27 00:53:22 +00:00
|
|
|
@IBOutlet weak var profileDetailContainerView: UIView!
|
2019-09-14 18:55:30 +00:00
|
|
|
@IBOutlet weak var favoriteAndReblogCountStackView: UIStackView!
|
2019-09-07 21:10:58 +00:00
|
|
|
@IBOutlet weak var totalFavoritesButton: UIButton!
|
|
|
|
@IBOutlet weak var totalReblogsButton: UIButton!
|
|
|
|
@IBOutlet weak var timestampAndClientLabel: UILabel!
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
var profileAccessibilityElement: UIAccessibilityElement!
|
2019-08-02 03:01:15 +00:00
|
|
|
|
2018-08-28 18:29:06 +00:00
|
|
|
override func awakeFromNib() {
|
2019-11-19 17:08:11 +00:00
|
|
|
super.awakeFromNib()
|
|
|
|
|
2019-09-27 00:53:22 +00:00
|
|
|
profileAccessibilityElement = UIAccessibilityElement(accessibilityContainer: self)
|
|
|
|
profileAccessibilityElement.accessibilityFrameInContainerSpace = profileDetailContainerView.convert(profileDetailContainerView.frame, to: self)
|
2020-01-18 21:00:38 +00:00
|
|
|
accessibilityElements = [profileAccessibilityElement!, contentWarningLabel!, collapseButton!, contentTextView!, totalFavoritesButton!, totalReblogsButton!, timestampAndClientLabel!, replyButton!, favoriteButton!, reblogButton!, moreButton!]
|
|
|
|
|
2020-09-07 22:49:25 +00:00
|
|
|
contentTextView.defaultFont = .systemFont(ofSize: 18)
|
2018-08-28 18:29:06 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 23:36:58 +00:00
|
|
|
override func updateUI(statusID: String, state: StatusState) {
|
|
|
|
super.updateUI(statusID: statusID, state: state)
|
2020-04-14 02:41:31 +00:00
|
|
|
guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError() }
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-09-07 21:10:58 +00:00
|
|
|
var timestampAndClientText = ConversationMainStatusTableViewCell.dateFormatter.string(from: status.createdAt)
|
2020-05-06 22:40:12 +00:00
|
|
|
if let application = status.applicationName {
|
2020-04-14 02:41:31 +00:00
|
|
|
timestampAndClientText += " • \(application)"
|
2019-09-07 21:10:58 +00:00
|
|
|
}
|
|
|
|
timestampAndClientLabel.text = timestampAndClientText
|
2019-08-02 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 16:54:27 +00:00
|
|
|
override func updateStatusState(status: StatusMO) {
|
2019-11-19 17:08:11 +00:00
|
|
|
super.updateStatusState(status: status)
|
|
|
|
|
2019-09-07 21:10:58 +00:00
|
|
|
// 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)
|
2019-08-02 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 16:54:27 +00:00
|
|
|
override func updateUI(account: AccountMO) {
|
2019-11-19 17:08:11 +00:00
|
|
|
super.updateUI(account: account)
|
|
|
|
|
2020-03-02 00:40:32 +00:00
|
|
|
profileAccessibilityElement.accessibilityLabel = account.displayNameWithoutCustomEmoji
|
2018-08-28 18:29:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 03:22:34 +00:00
|
|
|
override func updateUIForPreferences(account: AccountMO) {
|
|
|
|
super.updateUIForPreferences(account: account)
|
|
|
|
|
2019-09-14 18:55:30 +00:00
|
|
|
favoriteAndReblogCountStackView.isHidden = !Preferences.shared.showFavoriteAndReblogCounts
|
2019-08-03 00:05:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func totalFavoritesPressed() {
|
2019-09-07 21:10:58 +00:00
|
|
|
if let delegate = delegate {
|
|
|
|
// accounts aren't known, pass nil so the VC will load them
|
2019-11-28 23:36:58 +00:00
|
|
|
let vc = delegate.statusActionAccountList(action: .favorite, statusID: statusID, statusState: statusState.copy(), accountIDs: nil)
|
2019-09-07 21:10:58 +00:00
|
|
|
vc.showInacurateCountWarning = true
|
|
|
|
delegate.show(vc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func totalReblogsPressed() {
|
2019-09-07 21:10:58 +00:00
|
|
|
if let delegate = delegate {
|
|
|
|
// accounts aren't known, pass nil so the VC will load them
|
2019-11-28 23:36:58 +00:00
|
|
|
let vc = delegate.statusActionAccountList(action: .reblog, statusID: statusID, statusState: statusState.copy(), accountIDs: nil)
|
2019-09-07 21:10:58 +00:00
|
|
|
vc.showInacurateCountWarning = true
|
|
|
|
delegate.show(vc)
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 18:29:06 +00:00
|
|
|
}
|