2021-04-14 10:24:40 +02:00
|
|
|
//
|
|
|
|
// NotificationStatusTableViewCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/14.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
final class NotificationStatusTableViewCell: UITableViewCell {
|
|
|
|
static let actionImageBorderWidth: CGFloat = 2
|
|
|
|
|
2021-04-15 04:16:30 +02:00
|
|
|
static let statusPadding = UIEdgeInsets(top: 50, left: 73, bottom: 24, right: 24)
|
2021-04-14 10:24:40 +02:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
2021-04-14 11:37:58 +02:00
|
|
|
var pollCountdownSubscription: AnyCancellable?
|
2021-04-14 10:24:40 +02:00
|
|
|
var delegate: NotificationTableViewCellDelegate?
|
|
|
|
|
|
|
|
let avatatImageView: UIImageView = {
|
|
|
|
let imageView = UIImageView()
|
|
|
|
imageView.layer.cornerRadius = 4
|
|
|
|
imageView.layer.cornerCurve = .continuous
|
|
|
|
imageView.clipsToBounds = true
|
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
|
|
|
let actionImageView: UIImageView = {
|
|
|
|
let imageView = UIImageView()
|
2021-04-14 12:00:43 +02:00
|
|
|
imageView.tintColor = Asset.Colors.Background.pure.color
|
2021-04-14 10:24:40 +02:00
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
|
|
|
let actionImageBackground: UIView = {
|
|
|
|
let view = UIView()
|
|
|
|
view.layer.cornerRadius = (24 + NotificationStatusTableViewCell.actionImageBorderWidth) / 2
|
|
|
|
view.layer.cornerCurve = .continuous
|
|
|
|
view.clipsToBounds = true
|
|
|
|
view.layer.borderWidth = NotificationStatusTableViewCell.actionImageBorderWidth
|
2021-04-14 12:00:43 +02:00
|
|
|
view.layer.borderColor = Asset.Colors.Background.pure.color.cgColor
|
|
|
|
view.tintColor = Asset.Colors.Background.pure.color
|
2021-04-14 10:24:40 +02:00
|
|
|
return view
|
|
|
|
}()
|
|
|
|
|
|
|
|
let actionLabel: UILabel = {
|
|
|
|
let label = UILabel()
|
|
|
|
label.textColor = Asset.Colors.Label.secondary.color
|
|
|
|
label.font = UIFont.preferredFont(forTextStyle: .body)
|
|
|
|
label.lineBreakMode = .byTruncatingTail
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
|
|
|
let nameLabel: UILabel = {
|
|
|
|
let label = UILabel()
|
|
|
|
label.textColor = Asset.Colors.brandBlue.color
|
|
|
|
label.font = .systemFont(ofSize: 15, weight: .semibold)
|
|
|
|
label.lineBreakMode = .byTruncatingTail
|
|
|
|
return label
|
|
|
|
}()
|
|
|
|
|
|
|
|
let statusContainer: UIView = {
|
|
|
|
let view = UIView()
|
|
|
|
view.backgroundColor = .clear
|
|
|
|
view.layer.cornerRadius = 6
|
|
|
|
view.layer.borderWidth = 2
|
|
|
|
view.layer.cornerCurve = .continuous
|
|
|
|
view.layer.borderColor = Asset.Colors.Border.notification.color.cgColor
|
|
|
|
view.clipsToBounds = true
|
|
|
|
return view
|
|
|
|
}()
|
|
|
|
|
|
|
|
let statusView = StatusView()
|
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
|
|
|
avatatImageView.af.cancelImageRequest()
|
|
|
|
statusView.isStatusTextSensitive = false
|
|
|
|
statusView.cleanUpContentWarning()
|
|
|
|
statusView.pollTableView.dataSource = nil
|
|
|
|
statusView.playerContainerView.reset()
|
|
|
|
statusView.playerContainerView.isHidden = true
|
2021-04-14 14:02:41 +02:00
|
|
|
|
2021-04-14 10:24:40 +02:00
|
|
|
disposeBag.removeAll()
|
|
|
|
}
|
|
|
|
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
configure()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
configure()
|
|
|
|
}
|
|
|
|
|
|
|
|
override func layoutSubviews() {
|
|
|
|
super.layoutSubviews()
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.statusView.drawContentWarningImageView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationStatusTableViewCell {
|
|
|
|
func configure() {
|
|
|
|
selectionStyle = .none
|
|
|
|
|
2021-04-15 04:37:46 +02:00
|
|
|
let container = UIView()
|
|
|
|
container.backgroundColor = .clear
|
|
|
|
contentView.addSubview(container)
|
|
|
|
container.constrain([
|
|
|
|
container.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
|
|
container.leadingAnchor.constraint(equalTo: contentView.readableContentGuide.leadingAnchor),
|
|
|
|
container.trailingAnchor.constraint(equalTo: contentView.readableContentGuide.trailingAnchor),
|
|
|
|
container.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
|
|
|
|
])
|
|
|
|
|
|
|
|
container.addSubview(avatatImageView)
|
2021-04-14 10:24:40 +02:00
|
|
|
avatatImageView.pin(toSize: CGSize(width: 35, height: 35))
|
|
|
|
avatatImageView.pin(top: 12, left: 12, bottom: nil, right: nil)
|
|
|
|
|
2021-04-15 04:37:46 +02:00
|
|
|
container.addSubview(actionImageBackground)
|
|
|
|
actionImageBackground.pin(toSize: CGSize(width: 24 + NotificationTableViewCell.actionImageBorderWidth, height: 24 + NotificationTableViewCell.actionImageBorderWidth))
|
2021-04-14 10:24:40 +02:00
|
|
|
actionImageBackground.pin(top: 33, left: 33, bottom: nil, right: nil)
|
|
|
|
|
|
|
|
actionImageBackground.addSubview(actionImageView)
|
|
|
|
actionImageView.constrainToCenter()
|
2021-04-15 04:37:46 +02:00
|
|
|
|
|
|
|
container.addSubview(nameLabel)
|
2021-04-14 10:24:40 +02:00
|
|
|
nameLabel.constrain([
|
2021-04-15 04:37:46 +02:00
|
|
|
nameLabel.topAnchor.constraint(equalTo: container.topAnchor, constant: 12),
|
|
|
|
nameLabel.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 61)
|
|
|
|
|
2021-04-14 10:24:40 +02:00
|
|
|
])
|
|
|
|
|
2021-04-15 04:37:46 +02:00
|
|
|
container.addSubview(actionLabel)
|
2021-04-14 10:24:40 +02:00
|
|
|
actionLabel.constrain([
|
|
|
|
actionLabel.leadingAnchor.constraint(equalTo: nameLabel.trailingAnchor, constant: 4),
|
|
|
|
actionLabel.centerYAnchor.constraint(equalTo: nameLabel.centerYAnchor),
|
2021-04-15 04:53:03 +02:00
|
|
|
container.trailingAnchor.constraint(greaterThanOrEqualTo: actionLabel.trailingAnchor, constant: 4).priority(.defaultLow)
|
2021-04-14 10:24:40 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
statusView.contentWarningBlurContentImageView.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color
|
2021-04-14 14:02:41 +02:00
|
|
|
statusView.isUserInteractionEnabled = false
|
|
|
|
// remove item don't display
|
|
|
|
statusView.actionToolbarContainer.removeFromSuperview()
|
|
|
|
statusView.avatarView.removeFromSuperview()
|
|
|
|
statusView.usernameLabel.removeFromSuperview()
|
|
|
|
|
2021-04-15 04:37:46 +02:00
|
|
|
container.addSubview(statusContainer)
|
2021-04-14 10:24:40 +02:00
|
|
|
statusContainer.pin(top: 40, left: 63, bottom: 14, right: 14)
|
|
|
|
|
2021-04-15 04:37:46 +02:00
|
|
|
container.addSubview(statusView)
|
2021-04-14 11:13:23 +02:00
|
|
|
statusView.pin(top: NotificationStatusTableViewCell.statusPadding.top, left: NotificationStatusTableViewCell.statusPadding.left, bottom: NotificationStatusTableViewCell.statusPadding.bottom, right: NotificationStatusTableViewCell.statusPadding.right)
|
2021-04-14 10:24:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
|
|
|
statusContainer.layer.borderColor = Asset.Colors.Border.notification.color.cgColor
|
2021-04-14 12:00:43 +02:00
|
|
|
actionImageBackground.layer.borderColor = Asset.Colors.Background.pure.color.cgColor
|
2021-04-14 10:24:40 +02:00
|
|
|
}
|
|
|
|
}
|