2021-04-19 14:34:08 +02:00
|
|
|
//
|
|
|
|
// ReportedStatusTableViewCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by ihugo on 2021/4/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import AVKit
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
2021-06-28 13:41:41 +02:00
|
|
|
import Meta
|
2021-07-22 13:34:24 +02:00
|
|
|
import MetaTextKit
|
2021-04-19 14:34:08 +02:00
|
|
|
|
|
|
|
final class ReportedStatusTableViewCell: UITableViewCell, StatusCell {
|
|
|
|
|
|
|
|
static let bottomPaddingHeight: CGFloat = 10
|
|
|
|
|
2021-04-26 11:41:24 +02:00
|
|
|
weak var dependency: ReportViewController?
|
2021-04-19 14:34:08 +02:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
var observations = Set<NSKeyValueObservation>()
|
|
|
|
|
|
|
|
let statusView = StatusView()
|
|
|
|
let separatorLine = UIView.separatorLine
|
|
|
|
|
|
|
|
let checkbox: UIImageView = {
|
|
|
|
let imageView = UIImageView()
|
|
|
|
imageView.preferredSymbolConfiguration = UIImage.SymbolConfiguration(textStyle: .body)
|
|
|
|
imageView.tintColor = Asset.Colors.Label.secondary.color
|
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
|
|
|
var separatorLineToEdgeLeadingLayoutConstraint: NSLayoutConstraint!
|
|
|
|
var separatorLineToEdgeTrailingLayoutConstraint: NSLayoutConstraint!
|
|
|
|
|
|
|
|
var separatorLineToMarginLeadingLayoutConstraint: NSLayoutConstraint!
|
|
|
|
var separatorLineToMarginTrailingLayoutConstraint: NSLayoutConstraint!
|
|
|
|
|
2021-07-09 13:07:12 +02:00
|
|
|
// not support filter
|
|
|
|
var isFiltered: Bool = false
|
|
|
|
|
2021-04-19 14:34:08 +02:00
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
2021-04-22 07:08:53 +02:00
|
|
|
statusView.updateContentWarningDisplay(isHidden: true, animated: false)
|
|
|
|
statusView.statusMosaicImageViewContainer.contentWarningOverlayView.isUserInteractionEnabled = true
|
2021-04-19 14:34:08 +02:00
|
|
|
statusView.pollTableView.dataSource = nil
|
|
|
|
statusView.playerContainerView.reset()
|
2021-04-22 07:08:53 +02:00
|
|
|
statusView.playerContainerView.contentWarningOverlayView.isUserInteractionEnabled = true
|
2021-04-19 14:34:08 +02:00
|
|
|
statusView.playerContainerView.isHidden = true
|
|
|
|
disposeBag.removeAll()
|
|
|
|
observations.removeAll()
|
|
|
|
}
|
|
|
|
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
_init()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
|
|
|
|
super.setHighlighted(highlighted, animated: animated)
|
|
|
|
if highlighted {
|
|
|
|
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
|
2021-06-22 14:52:30 +02:00
|
|
|
checkbox.tintColor = Asset.Colors.brandBlue.color
|
2021-04-25 12:28:47 +02:00
|
|
|
} else if !isSelected {
|
2021-04-19 14:34:08 +02:00
|
|
|
checkbox.image = UIImage(systemName: "circle")
|
|
|
|
checkbox.tintColor = Asset.Colors.Label.secondary.color
|
|
|
|
}
|
|
|
|
}
|
2021-04-25 12:28:47 +02:00
|
|
|
|
|
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
|
|
|
super.setSelected(selected, animated: animated)
|
|
|
|
|
|
|
|
if isSelected {
|
|
|
|
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
|
|
|
|
} else {
|
|
|
|
checkbox.image = UIImage(systemName: "circle")
|
|
|
|
}
|
|
|
|
checkbox.tintColor = Asset.Colors.Label.secondary.color
|
|
|
|
}
|
2021-04-19 14:34:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extension ReportedStatusTableViewCell {
|
|
|
|
|
|
|
|
private func _init() {
|
2021-07-05 10:07:17 +02:00
|
|
|
backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
|
|
|
|
ThemeService.shared.currentTheme
|
|
|
|
.receive(on: RunLoop.main)
|
|
|
|
.sink { [weak self] theme in
|
|
|
|
guard let self = self else { return }
|
|
|
|
self.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemGroupedBackgroundColor
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
2021-04-19 14:34:08 +02:00
|
|
|
|
|
|
|
checkbox.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(checkbox)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
checkbox.widthAnchor.constraint(equalToConstant: 23),
|
|
|
|
checkbox.heightAnchor.constraint(equalToConstant: 22),
|
|
|
|
checkbox.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor, constant: 12),
|
|
|
|
checkbox.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
|
|
|
|
])
|
|
|
|
|
|
|
|
statusView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(statusView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
statusView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20),
|
|
|
|
statusView.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: 20),
|
|
|
|
contentView.readableContentGuide.trailingAnchor.constraint(equalTo: statusView.trailingAnchor),
|
|
|
|
contentView.bottomAnchor.constraint(equalTo: statusView.bottomAnchor, constant: 20),
|
|
|
|
])
|
|
|
|
|
|
|
|
separatorLine.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(separatorLine)
|
|
|
|
separatorLineToEdgeLeadingLayoutConstraint = separatorLine.leadingAnchor.constraint(equalTo: contentView.leadingAnchor)
|
|
|
|
separatorLineToEdgeTrailingLayoutConstraint = separatorLine.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
|
|
|
|
separatorLineToMarginLeadingLayoutConstraint = separatorLine.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor)
|
|
|
|
separatorLineToMarginTrailingLayoutConstraint = separatorLine.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
separatorLine.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
|
|
separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: contentView)),
|
|
|
|
])
|
|
|
|
resetSeparatorLineLayout()
|
|
|
|
|
|
|
|
selectionStyle = .none
|
2021-04-25 17:49:19 +02:00
|
|
|
statusView.delegate = self
|
|
|
|
statusView.statusMosaicImageViewContainer.delegate = self
|
2021-04-19 14:34:08 +02:00
|
|
|
statusView.actionToolbarContainer.isHidden = true
|
|
|
|
}
|
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
|
|
|
|
|
|
resetSeparatorLineLayout()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ReportedStatusTableViewCell {
|
|
|
|
private func resetSeparatorLineLayout() {
|
|
|
|
separatorLineToEdgeLeadingLayoutConstraint.isActive = false
|
|
|
|
separatorLineToEdgeTrailingLayoutConstraint.isActive = false
|
|
|
|
separatorLineToMarginLeadingLayoutConstraint.isActive = false
|
|
|
|
separatorLineToMarginTrailingLayoutConstraint.isActive = false
|
|
|
|
|
|
|
|
if traitCollection.userInterfaceIdiom == .phone {
|
|
|
|
// to edge
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
separatorLineToEdgeLeadingLayoutConstraint,
|
|
|
|
separatorLineToEdgeTrailingLayoutConstraint,
|
|
|
|
])
|
|
|
|
} else {
|
|
|
|
if traitCollection.horizontalSizeClass == .compact {
|
|
|
|
// to edge
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
separatorLineToEdgeLeadingLayoutConstraint,
|
|
|
|
separatorLineToEdgeTrailingLayoutConstraint,
|
|
|
|
])
|
|
|
|
} else {
|
|
|
|
// to margin
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
separatorLineToMarginLeadingLayoutConstraint,
|
|
|
|
separatorLineToMarginTrailingLayoutConstraint,
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-25 17:49:19 +02:00
|
|
|
|
|
|
|
extension ReportedStatusTableViewCell: MosaicImageViewContainerDelegate {
|
|
|
|
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
|
|
|
|
|
|
|
guard let dependency = self.dependency else { return }
|
|
|
|
StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ReportedStatusTableViewCell: StatusViewDelegate {
|
2021-06-23 14:47:49 +02:00
|
|
|
|
2021-04-25 17:49:19 +02:00
|
|
|
func statusView(_ statusView: StatusView, headerInfoLabelDidPressed label: UILabel) {
|
|
|
|
}
|
2021-06-23 14:47:49 +02:00
|
|
|
|
|
|
|
func statusView(_ statusView: StatusView, avatarImageViewDidPressed imageView: UIImageView) {
|
2021-04-25 17:49:19 +02:00
|
|
|
}
|
2021-06-23 14:47:49 +02:00
|
|
|
|
2021-04-25 17:49:19 +02:00
|
|
|
func statusView(_ statusView: StatusView, revealContentWarningButtonDidPressed button: UIButton) {
|
|
|
|
guard let dependency = self.dependency else { return }
|
|
|
|
StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self)
|
|
|
|
}
|
|
|
|
|
|
|
|
func statusView(_ statusView: StatusView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
|
|
|
guard let dependency = self.dependency else { return }
|
|
|
|
StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self)
|
|
|
|
}
|
|
|
|
|
|
|
|
func statusView(_ statusView: StatusView, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
|
|
|
guard let dependency = self.dependency else { return }
|
|
|
|
StatusProviderFacade.responseToStatusContentWarningRevealAction(dependency: dependency, cell: self)
|
|
|
|
}
|
|
|
|
|
|
|
|
func statusView(_ statusView: StatusView, pollVoteButtonPressed button: UIButton) {
|
|
|
|
}
|
2021-06-28 13:41:41 +02:00
|
|
|
|
|
|
|
func statusView(_ statusView: StatusView, metaText: MetaText, didSelectMeta meta: Meta) {
|
|
|
|
}
|
|
|
|
|
2021-04-25 17:49:19 +02:00
|
|
|
}
|