Files
suixinkan_uikit/suixinkan/UI/Home/Views/HomeCollectionCells.swift

212 lines
5.9 KiB
Swift

//
// HomeCollectionCells.swift
// suixinkan
//
import SnapKit
import UIKit
/// 线 cell
final class HomeWorkStatusCell: UICollectionViewCell {
static let reuseIdentifier = "HomeWorkStatusCell"
let cardView = HomeWorkStatusCardView()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(cardView)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(isOnline: Bool, countdownText: String, reminderMinutes: Int) {
cardView.apply(isOnline: isOnline, countdownText: countdownText, reminderMinutes: reminderMinutes)
}
}
/// cell
final class HomeLocationReportCell: UICollectionViewCell {
static let reuseIdentifier = "HomeLocationReportCell"
let cardView = HomeLocationReportCardView()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(cardView)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(address: String, isReporting: Bool) {
cardView.apply(address: address, isReporting: isReporting)
}
}
/// cell
final class HomeQuickActionsCell: UICollectionViewCell {
static let reuseIdentifier = "HomeQuickActionsCell"
let cardView = HomeQuickActionsView()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(cardView)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(isOnline: Bool) {
cardView.apply(isOnline: isOnline)
}
}
/// cell
final class HomeStoreCell: UICollectionViewCell {
static let reuseIdentifier = "HomeStoreCell"
let cardView = HomeStoreCardView()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(cardView)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(store: StoreItem) {
cardView.apply(store: store)
}
}
/// cell
final class HomeMenuCell: UICollectionViewCell {
static let reuseIdentifier = "HomeMenuCell"
private let cardView = UIView()
private let contentStackView = UIStackView()
private let iconContainerView = UIView()
private let iconView = UIImageView()
private let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(menu: HomeMenuItem) {
iconView.image = HomeMenuIconFactory.image(named: menu.iconName)
iconView.accessibilityIdentifier = menu.iconName
titleLabel.text = menu.title
}
private func setupUI() {
contentView.backgroundColor = .clear
cardView.backgroundColor = AppColor.cardBackground
cardView.layer.cornerRadius = AppRadius.lg
cardView.layer.borderWidth = 1
cardView.layer.borderColor = AppColor.cardOutline.cgColor
cardView.clipsToBounds = true
iconContainerView.backgroundColor = AppColor.iconBackground
iconContainerView.layer.cornerRadius = 20
iconView.tintColor = AppColor.primary
iconView.contentMode = .scaleAspectFit
iconView.preferredSymbolConfiguration = HomeMenuIconFactory.symbolConfiguration
contentStackView.axis = .vertical
contentStackView.alignment = .center
contentStackView.spacing = AppSpacing.xs
contentStackView.isUserInteractionEnabled = false
titleLabel.font = .app(.body)
titleLabel.textColor = AppColor.textSecondary
titleLabel.textAlignment = .center
titleLabel.numberOfLines = 2
contentView.addSubview(cardView)
cardView.addSubview(contentStackView)
iconContainerView.addSubview(iconView)
contentStackView.addArrangedSubview(iconContainerView)
contentStackView.addArrangedSubview(titleLabel)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
contentStackView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.leading.trailing.equalToSuperview().inset(AppSpacing.xs)
}
iconContainerView.snp.makeConstraints { make in
make.width.height.equalTo(40)
}
iconView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.height.equalTo(24)
}
}
}
/// supplementary view
final class HomeSectionHeaderView: UICollectionReusableView {
static let reuseIdentifier = "HomeSectionHeaderView"
private let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
titleLabel.font = .app(.title)
titleLabel.textColor = AppColor.textPrimary
addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.leading.trailing.bottom.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(title: String) {
titleLabel.text = title
}
}