164 lines
7.1 KiB
Swift
164 lines
7.1 KiB
Swift
//
|
|
// 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!
|
|
|
|
private var profileAccessibilityElement: ConversationMainStatusProfileAccessibilityElement!
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
|
|
profileAccessibilityElement = ConversationMainStatusProfileAccessibilityElement(accessibilityContainer: self)
|
|
profileAccessibilityElement.accessibilityFrameInContainerSpace = profileDetailContainerView.convert(profileDetailContainerView.frame, to: self)
|
|
accessibilityElements = [
|
|
profileAccessibilityElement!,
|
|
contentWarningLabel!,
|
|
collapseButton!,
|
|
contentTextView!,
|
|
attachmentsView!,
|
|
pollView!,
|
|
totalFavoritesButton!,
|
|
totalReblogsButton!,
|
|
timestampAndClientLabel!,
|
|
replyButton!,
|
|
favoriteButton!,
|
|
reblogButton!,
|
|
moreButton!,
|
|
]
|
|
|
|
profileDetailContainerView.addInteraction(UIContextMenuInteraction(delegate: self))
|
|
|
|
displayNameLabel.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: .systemFont(ofSize: 24, weight: .semibold))
|
|
displayNameLabel.adjustsFontForContentSizeCategory = true
|
|
|
|
usernameLabel.font = UIFontMetrics(forTextStyle: .title2).scaledFont(for: .systemFont(ofSize: 17, weight: .light))
|
|
usernameLabel.adjustsFontForContentSizeCategory = true
|
|
|
|
metaIndicatorsView.allowedIndicators = [.visibility, .localOnly]
|
|
metaIndicatorsView.squeezeHorizontal = true
|
|
metaIndicatorsView.primaryAxis = .horizontal
|
|
|
|
contentWarningLabel.font = .preferredFont(forTextStyle: .body).withTraits(.traitBold)!
|
|
contentWarningLabel.adjustsFontForContentSizeCategory = true
|
|
|
|
contentTextView.defaultFont = UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 18))
|
|
contentTextView.monospaceFont = UIFontMetrics.default.scaledFont(for: .monospacedSystemFont(ofSize: 18, weight: .regular))
|
|
contentTextView.adjustsFontForContentSizeCategory = true
|
|
contentTextView.dataDetectorTypes = [.flightNumber, .address, .shipmentTrackingNumber, .phoneNumber]
|
|
if #available(iOS 16.0, *) {
|
|
contentTextView.dataDetectorTypes.formUnion([.money, .physicalValue])
|
|
}
|
|
|
|
let metaFont = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 15))
|
|
totalFavoritesButton.titleLabel!.font = metaFont
|
|
totalFavoritesButton.titleLabel!.adjustsFontForContentSizeCategory = true
|
|
totalReblogsButton.titleLabel!.font = metaFont
|
|
totalReblogsButton.titleLabel!.adjustsFontForContentSizeCategory = true
|
|
timestampAndClientLabel.font = metaFont
|
|
timestampAndClientLabel.adjustsFontForContentSizeCategory = true
|
|
}
|
|
|
|
override func doUpdateUI(status: StatusMO, state: CollapseState) {
|
|
super.doUpdateUI(status: status, state: state)
|
|
|
|
var timestampAndClientText = ConversationMainStatusTableViewCell.dateFormatter.string(from: status.createdAt)
|
|
if let application = status.applicationName {
|
|
timestampAndClientText += " • \(application)"
|
|
}
|
|
timestampAndClientLabel.text = timestampAndClientText
|
|
}
|
|
|
|
override func updateStatusState(status: StatusMO) {
|
|
super.updateStatusState(status: status)
|
|
|
|
let favoritesFormat = NSLocalizedString("favorites count", comment: "conv main status favorites button label")
|
|
totalFavoritesButton.setTitle(String.localizedStringWithFormat(favoritesFormat, status.favouritesCount), for: .normal)
|
|
let reblogsFormat = NSLocalizedString("reblogs count", comment: "conv main status reblogs button label")
|
|
totalReblogsButton.setTitle(String.localizedStringWithFormat(reblogsFormat, status.reblogsCount), for: .normal)
|
|
}
|
|
|
|
override func updateUI(account: AccountMO) {
|
|
super.updateUI(account: account)
|
|
profileAccessibilityElement.navigationDelegate = delegate
|
|
profileAccessibilityElement.accountID = account.id
|
|
}
|
|
|
|
override func updateUIForPreferences(account: AccountMO, status: StatusMO) {
|
|
super.updateUIForPreferences(account: account, status: status)
|
|
|
|
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, statusState: statusState.copy(), 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, statusState: statusState.copy(), accountIDs: nil)
|
|
vc.showInacurateCountWarning = true
|
|
delegate.show(vc)
|
|
}
|
|
}
|
|
}
|
|
|
|
private class ConversationMainStatusProfileAccessibilityElement: UIAccessibilityElement {
|
|
var navigationDelegate: TuskerNavigationDelegate!
|
|
var mastodonController: MastodonController { navigationDelegate.apiController }
|
|
var accountID: String!
|
|
|
|
override var accessibilityLabel: String? {
|
|
get { mastodonController.persistentContainer.account(for: accountID)?.displayNameWithoutCustomEmoji }
|
|
set {}
|
|
}
|
|
|
|
override var accessibilityHint: String? {
|
|
get { "Double tap to show profile." }
|
|
set {}
|
|
}
|
|
|
|
override func accessibilityActivate() -> Bool {
|
|
navigationDelegate.selected(account: accountID)
|
|
return true
|
|
}
|
|
}
|
|
|
|
extension ConversationMainStatusTableViewCell: UIContextMenuInteractionDelegate {
|
|
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
|
|
return UIContextMenuConfiguration(identifier: nil) {
|
|
ProfileViewController(accountID: self.accountID, mastodonController: self.mastodonController)
|
|
} actionProvider: { (_) in
|
|
return UIMenu(title: "", image: nil, identifier: nil, options: [], children: self.delegate?.actionsForProfile(accountID: self.accountID, source: .view(self.avatarImageView)) ?? [])
|
|
}
|
|
}
|
|
}
|