2021-04-12 10:31:53 +02:00
|
|
|
//
|
|
|
|
// NotificationTableViewCell.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/13.
|
|
|
|
//
|
|
|
|
|
2021-04-14 09:00:48 +02:00
|
|
|
import Combine
|
2021-04-15 04:16:30 +02:00
|
|
|
import CoreDataStack
|
2021-04-12 10:31:53 +02:00
|
|
|
import Foundation
|
|
|
|
import UIKit
|
|
|
|
|
2021-04-15 04:16:30 +02:00
|
|
|
protocol NotificationTableViewCellDelegate: AnyObject {
|
2021-04-14 09:00:48 +02:00
|
|
|
var context: AppContext! { get }
|
|
|
|
|
|
|
|
func parent() -> UIViewController
|
2021-04-14 11:37:58 +02:00
|
|
|
|
2021-04-15 04:16:30 +02:00
|
|
|
func userAvatarDidPressed(notification: MastodonNotification)
|
2021-04-14 09:00:48 +02:00
|
|
|
}
|
2021-04-12 10:31:53 +02:00
|
|
|
|
|
|
|
final class NotificationTableViewCell: UITableViewCell {
|
2021-04-13 15:31:49 +02:00
|
|
|
static let actionImageBorderWidth: CGFloat = 2
|
2021-04-12 10:31:53 +02:00
|
|
|
|
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
2021-04-14 09:00:48 +02:00
|
|
|
var delegate: NotificationTableViewCellDelegate?
|
|
|
|
|
2021-04-12 10:31:53 +02:00
|
|
|
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-12 10:31:53 +02:00
|
|
|
return imageView
|
|
|
|
}()
|
|
|
|
|
2021-04-13 15:31:49 +02:00
|
|
|
let actionImageBackground: UIView = {
|
|
|
|
let view = UIView()
|
2021-04-14 09:00:48 +02:00
|
|
|
view.layer.cornerRadius = (24 + NotificationTableViewCell.actionImageBorderWidth) / 2
|
2021-04-13 15:31:49 +02:00
|
|
|
view.layer.cornerCurve = .continuous
|
|
|
|
view.clipsToBounds = true
|
|
|
|
view.layer.borderWidth = NotificationTableViewCell.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-13 15:31:49 +02:00
|
|
|
return view
|
|
|
|
}()
|
|
|
|
|
2021-04-12 10:31:53 +02:00
|
|
|
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
|
|
|
|
}()
|
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
super.prepareForReuse()
|
|
|
|
avatatImageView.af.cancelImageRequest()
|
2021-04-14 09:00:48 +02:00
|
|
|
disposeBag.removeAll()
|
2021-04-12 10:31:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
configure()
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
configure()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationTableViewCell {
|
|
|
|
func configure() {
|
2021-04-14 09:00:48 +02:00
|
|
|
selectionStyle = .none
|
|
|
|
|
2021-04-12 10:31:53 +02:00
|
|
|
contentView.addSubview(avatatImageView)
|
|
|
|
avatatImageView.pin(toSize: CGSize(width: 35, height: 35))
|
|
|
|
avatatImageView.pin(top: 12, left: 12, bottom: nil, right: nil)
|
|
|
|
|
2021-04-13 15:31:49 +02:00
|
|
|
contentView.addSubview(actionImageBackground)
|
|
|
|
actionImageBackground.pin(toSize: CGSize(width: 24 + NotificationTableViewCell.actionImageBorderWidth, height: 24 + NotificationTableViewCell.actionImageBorderWidth))
|
|
|
|
actionImageBackground.pin(top: 33, left: 33, bottom: nil, right: nil)
|
|
|
|
|
|
|
|
actionImageBackground.addSubview(actionImageView)
|
|
|
|
actionImageView.constrainToCenter()
|
2021-04-14 10:24:40 +02:00
|
|
|
|
2021-04-13 15:31:49 +02:00
|
|
|
contentView.addSubview(nameLabel)
|
2021-04-12 10:31:53 +02:00
|
|
|
nameLabel.constrain([
|
2021-04-14 10:24:40 +02:00
|
|
|
nameLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 24),
|
|
|
|
contentView.bottomAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 24),
|
2021-04-12 10:31:53 +02:00
|
|
|
nameLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 61)
|
|
|
|
])
|
|
|
|
|
2021-04-13 15:31:49 +02:00
|
|
|
contentView.addSubview(actionLabel)
|
2021-04-12 10:31:53 +02:00
|
|
|
actionLabel.constrain([
|
|
|
|
actionLabel.leadingAnchor.constraint(equalTo: nameLabel.trailingAnchor, constant: 4),
|
2021-04-14 09:00:48 +02:00
|
|
|
actionLabel.centerYAnchor.constraint(equalTo: nameLabel.centerYAnchor),
|
|
|
|
contentView.trailingAnchor.constraint(equalTo: actionLabel.trailingAnchor, constant: 4).priority(.defaultLow)
|
2021-04-12 10:31:53 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
|
|
|
super.traitCollectionDidChange(previousTraitCollection)
|
2021-04-14 12:00:43 +02:00
|
|
|
actionImageBackground.layer.borderColor = Asset.Colors.Background.pure.color.cgColor
|
2021-04-12 10:31:53 +02:00
|
|
|
}
|
|
|
|
}
|