84 lines
3.2 KiB
Swift
84 lines
3.2 KiB
Swift
//
|
|
// StatusTableRowCollectionViewCell.swift
|
|
// MastoSearchMobile
|
|
//
|
|
// Created by Shadowfacts on 7/3/22.
|
|
//
|
|
|
|
import UIKit
|
|
import MastoSearchCore
|
|
import SwiftSoup
|
|
|
|
class StatusTableRowCollectionViewCell: UICollectionViewCell {
|
|
|
|
// private static let formatter: DateFormatter = {
|
|
// let f = DateFormatter()
|
|
// f.locale = .current
|
|
// f.setLocalizedDateFormatFromTemplate("yyyy-MM-dd hh:mm a")
|
|
// return f
|
|
// }()
|
|
private static let dateStyle: Date.FormatStyle = {
|
|
Date.FormatStyle()
|
|
.year(.extended(minimumLength: 4))
|
|
.month(.twoDigits)
|
|
.day(.twoDigits)
|
|
.hour(.twoDigits(amPM: .abbreviated))
|
|
.minute(.twoDigits)
|
|
}()
|
|
|
|
private let dateLabel = UILabel()
|
|
private let contentWarningLabel = UILabel()
|
|
private let contentLabel = UILabel()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
dateLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
dateLabel.font = .monospacedDigitSystemFont(ofSize: 17, weight: .regular)
|
|
addSubview(dateLabel)
|
|
|
|
contentWarningLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
addSubview(contentWarningLabel)
|
|
|
|
let spacer = UIView()
|
|
spacer.translatesAutoresizingMaskIntoConstraints = false
|
|
addSubview(spacer)
|
|
|
|
contentLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
contentLabel.font = .preferredFont(forTextStyle: .callout)
|
|
contentLabel.numberOfLines = 2
|
|
addSubview(contentLabel)
|
|
|
|
NSLayoutConstraint.activate([
|
|
dateLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: leadingAnchor, multiplier: 2),
|
|
dateLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
|
|
|
|
contentWarningLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: dateLabel.trailingAnchor, multiplier: 2),
|
|
contentWarningLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
|
|
|
|
spacer.leadingAnchor.constraint(equalTo: contentWarningLabel.trailingAnchor),
|
|
centerXAnchor.constraint(equalToSystemSpacingAfter: spacer.trailingAnchor, multiplier: 1),
|
|
|
|
contentLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: centerXAnchor, multiplier: 1),
|
|
contentLabel.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
contentLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
|
|
contentLabel.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: 4),
|
|
bottomAnchor.constraint(greaterThanOrEqualTo: contentLabel.bottomAnchor, constant: 4),
|
|
|
|
heightAnchor.constraint(greaterThanOrEqualToConstant: 32),
|
|
])
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
func updateUI(status: Status) {
|
|
dateLabel.text = status.published.formatted(StatusTableRowCollectionViewCell.dateStyle)
|
|
contentWarningLabel.text = status.summary ?? ""
|
|
let doc = try! SwiftSoup.parseBodyFragment(status.content)
|
|
contentLabel.text = try! doc.body()!.text()
|
|
}
|
|
|
|
}
|