Files
suixinkan_uikit/suixinkan/UI/Home/Views/HomeCollectionCells.swift
汉秋 715393e78c Refactor home to single collection view and add all-functions customization.
Replace scroll/stack layout with one UICollectionView, fix grid column math and Diffable item IDs so location report and quick actions render, and add the customizable all-functions page with persistence and tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 09:57:41 +08:00

194 lines
5.1 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 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 = UIImage(systemName: menu.iconName)
titleLabel.text = menu.title
}
private func setupUI() {
contentView.backgroundColor = .clear
cardView.backgroundColor = .white
cardView.layer.cornerRadius = AppRadius.md
cardView.clipsToBounds = true
iconView.tintColor = AppColor.primary
iconView.contentMode = .scaleAspectFit
titleLabel.font = .app(.body)
titleLabel.textColor = AppColor.textSecondary
titleLabel.textAlignment = .center
titleLabel.numberOfLines = 2
contentView.addSubview(cardView)
cardView.addSubview(iconView)
cardView.addSubview(titleLabel)
cardView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
iconView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(AppSpacing.sm)
make.centerX.equalToSuperview()
make.width.height.equalTo(24)
}
titleLabel.snp.makeConstraints { make in
make.top.equalTo(iconView.snp.bottom).offset(AppSpacing.sm)
make.leading.trailing.equalToSuperview().inset(AppSpacing.xxs)
make.bottom.lessThanOrEqualToSuperview().inset(AppSpacing.xs)
}
}
}
/// 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
}
}