2021-02-23 08:16:55 +01:00
|
|
|
//
|
|
|
|
// StatusTableViewCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/1/27.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import AVKit
|
|
|
|
import Combine
|
|
|
|
|
|
|
|
|
|
|
|
protocol StatusTableViewCellDelegate: class {
|
|
|
|
func statusTableViewCell(_ cell: StatusTableViewCell, actionToolbarContainer: ActionToolbarContainer, likeButtonDidPressed sender: UIButton)
|
2021-02-24 09:11:48 +01:00
|
|
|
func statusTableViewCell(_ cell: StatusTableViewCell, statusView: StatusView, contentWarningActionButtonPressed button: UIButton)
|
2021-02-23 08:16:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
final class StatusTableViewCell: UITableViewCell {
|
|
|
|
|
|
|
|
|
|
|
|
weak var delegate: StatusTableViewCellDelegate?
|
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
var observations = Set<NSKeyValueObservation>()
|
|
|
|
|
|
|
|
let statusView = StatusView()
|
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
2021-02-24 08:29:16 +01:00
|
|
|
statusView.cleanUpContentWarning()
|
2021-02-23 08:16:55 +01:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension StatusTableViewCell {
|
|
|
|
|
|
|
|
private func _init() {
|
|
|
|
selectionStyle = .none
|
|
|
|
backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color
|
|
|
|
|
|
|
|
statusView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(statusView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
statusView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20),
|
|
|
|
statusView.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
|
|
|
contentView.readableContentGuide.trailingAnchor.constraint(equalTo: statusView.trailingAnchor),
|
|
|
|
])
|
|
|
|
|
|
|
|
let bottomPaddingView = UIView()
|
|
|
|
bottomPaddingView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
contentView.addSubview(bottomPaddingView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
bottomPaddingView.topAnchor.constraint(equalTo: statusView.bottomAnchor, constant: 10),
|
|
|
|
bottomPaddingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
|
|
|
bottomPaddingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
|
|
|
|
bottomPaddingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
|
|
bottomPaddingView.heightAnchor.constraint(equalToConstant: 10).priority(.defaultHigh),
|
|
|
|
])
|
|
|
|
|
2021-02-24 09:11:48 +01:00
|
|
|
statusView.delegate = self
|
2021-02-23 08:16:55 +01:00
|
|
|
statusView.actionToolbarContainer.delegate = self
|
|
|
|
bottomPaddingView.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-02-24 09:11:48 +01:00
|
|
|
|
|
|
|
// MARK: - StatusViewDelegate
|
|
|
|
extension StatusTableViewCell: StatusViewDelegate {
|
|
|
|
func statusView(_ statusView: StatusView, contentWarningActionButtonPressed button: UIButton) {
|
|
|
|
delegate?.statusTableViewCell(self, statusView: statusView, contentWarningActionButtonPressed: button)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 08:16:55 +01:00
|
|
|
// MARK: - ActionToolbarContainerDelegate
|
|
|
|
extension StatusTableViewCell: ActionToolbarContainerDelegate {
|
|
|
|
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, replayButtonDidPressed sender: UIButton) {
|
|
|
|
|
|
|
|
}
|
|
|
|
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, retootButtonDidPressed sender: UIButton) {
|
|
|
|
|
|
|
|
}
|
|
|
|
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, starButtonDidPressed sender: UIButton) {
|
|
|
|
delegate?.statusTableViewCell(self, actionToolbarContainer: actionToolbarContainer, likeButtonDidPressed: sender)
|
|
|
|
}
|
|
|
|
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, bookmarkButtonDidPressed sender: UIButton) {
|
|
|
|
|
|
|
|
}
|
|
|
|
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, moreButtonDidPressed sender: UIButton) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|