Shadowfacts
f96d1d780c
Tapping detected items doesn't work because it conflicts with our tap gesture recognizer, but long pressing does
123 lines
5.0 KiB
Swift
123 lines
5.0 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!
|
|
|
|
var profileAccessibilityElement: UIAccessibilityElement!
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
|
|
profileAccessibilityElement = UIAccessibilityElement(accessibilityContainer: self)
|
|
profileAccessibilityElement.accessibilityFrameInContainerSpace = profileDetailContainerView.convert(profileDetailContainerView.frame, to: self)
|
|
accessibilityElements = [
|
|
profileAccessibilityElement!,
|
|
contentWarningLabel!,
|
|
collapseButton!,
|
|
contentTextView!,
|
|
attachmentsView!,
|
|
pollView!,
|
|
totalFavoritesButton!,
|
|
totalReblogsButton!,
|
|
timestampAndClientLabel!,
|
|
replyButton!,
|
|
favoriteButton!,
|
|
reblogButton!,
|
|
moreButton!,
|
|
]
|
|
|
|
contentTextView.defaultFont = .systemFont(ofSize: 18)
|
|
contentTextView.dataDetectorTypes = [.flightNumber, .address, .shipmentTrackingNumber, .phoneNumber]
|
|
if #available(iOS 16.0, *) {
|
|
contentTextView.dataDetectorTypes.formUnion([.money, .physicalValue])
|
|
}
|
|
|
|
profileDetailContainerView.addInteraction(UIContextMenuInteraction(delegate: self))
|
|
|
|
metaIndicatorsView.allowedIndicators = [.visibility, .localOnly]
|
|
metaIndicatorsView.squeezeHorizontal = true
|
|
}
|
|
|
|
override func doUpdateUI(status: StatusMO, state: StatusState) {
|
|
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.accessibilityLabel = account.displayNameWithoutCustomEmoji
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
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, sourceView: self.avatarImageView) ?? [])
|
|
}
|
|
}
|
|
}
|