540 lines
28 KiB
Swift
540 lines
28 KiB
Swift
import SnapKit
|
||
import UIKit
|
||
|
||
/// 素材库的订单摘要,保留拍摄履约与素材处理相互独立的表达。
|
||
@MainActor
|
||
final class DroneMaterialOrderCell: UICollectionViewCell {
|
||
private let customerLabel = DroneDockStyle.label(size: 18, weight: .semibold)
|
||
private let statusLabel = DroneDockStatusLabel()
|
||
private let numberLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||
private let countLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
let titleRow = UIStackView(arrangedSubviews: [customerLabel, statusLabel, UIView()])
|
||
titleRow.axis = .horizontal
|
||
titleRow.alignment = .center
|
||
titleRow.spacing = 9
|
||
let stack = UIStackView(arrangedSubviews: [titleRow, numberLabel, countLabel])
|
||
stack.axis = .vertical
|
||
stack.spacing = 9
|
||
contentView.addSubview(stack)
|
||
stack.snp.makeConstraints { make in
|
||
make.leading.trailing.equalToSuperview()
|
||
make.top.equalToSuperview().offset(16)
|
||
make.bottom.equalToSuperview().inset(18)
|
||
}
|
||
isAccessibilityElement = true
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 显示本次入口订单的脱敏信息与拍摄次数。
|
||
func apply(order: DroneShootingOrder?) {
|
||
guard let order else {
|
||
customerLabel.text = "订单信息暂不可用"
|
||
statusLabel.isHidden = true
|
||
numberLabel.text = "请返回订单列表重新进入"
|
||
countLabel.text = nil
|
||
accessibilityLabel = "订单信息暂不可用,请返回订单列表重新进入"
|
||
return
|
||
}
|
||
customerLabel.text = order.customerName
|
||
statusLabel.isHidden = false
|
||
statusLabel.apply(title: order.fulfillmentState.title, tone: order.fulfillmentState.tone)
|
||
numberLabel.text = order.orderNumber
|
||
countLabel.text = "含\(order.totalShootingCount)次拍摄 · 已拍摄\(order.successfulShootingCount)次 · 剩余\(order.remainingShootingCount)次"
|
||
accessibilityLabel = [order.customerName, order.fulfillmentState.title, order.orderNumber, countLabel.text].compactMap { $0 }.joined(separator: ",")
|
||
}
|
||
}
|
||
|
||
/// 可横向浏览的点位筛选标签,下载期间保留现有筛选并禁用交互。
|
||
@MainActor
|
||
final class DroneMaterialFilterCell: UICollectionViewCell {
|
||
private let titleLabel = DroneDockStyle.label(size: 13, weight: .medium)
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
contentView.layer.cornerRadius = 7
|
||
contentView.layer.cornerCurve = .continuous
|
||
contentView.layer.borderWidth = 1
|
||
titleLabel.textAlignment = .center
|
||
contentView.addSubview(titleLabel)
|
||
titleLabel.snp.makeConstraints { make in make.edges.equalToSuperview().inset(5) }
|
||
isAccessibilityElement = true
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 映射筛选名称、选中态与交互许可。
|
||
func apply(title: String, id: String?, selected: Bool, locked: Bool) {
|
||
titleLabel.text = title
|
||
titleLabel.textColor = selected ? DroneDockStyle.primary : UIColor(hex: 0x677183)
|
||
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.09) : .white
|
||
contentView.layer.borderColor = (selected ? UIColor.clear : DroneDockStyle.border).cgColor
|
||
contentView.alpha = locked ? 0.5 : 1
|
||
accessibilityIdentifier = "drone.materials.filter.\(id ?? "all")"
|
||
accessibilityLabel = title
|
||
var traits: UIAccessibilityTraits = .button
|
||
if selected { traits.insert(.selected) }
|
||
if locked { traits.insert(.notEnabled) }
|
||
accessibilityTraits = traits
|
||
}
|
||
}
|
||
|
||
/// 点位限定入口的只读提示,不将当前任务点位伪装成可切换筛选。
|
||
@MainActor
|
||
final class DroneMaterialPointContextCell: UICollectionViewCell {
|
||
private let icon = UIImageView(image: UIImage(systemName: "mappin.circle.fill"))
|
||
private let titleLabel = DroneDockStyle.label(size: 14, weight: .semibold)
|
||
private let detailLabel = DroneDockStyle.label("仅显示当前打卡点素材", size: 11, color: DroneDockStyle.secondary)
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
icon.tintColor = DroneDockStyle.primary
|
||
[icon, titleLabel, detailLabel].forEach(contentView.addSubview)
|
||
icon.snp.makeConstraints { make in make.leading.centerY.equalToSuperview(); make.size.equalTo(16) }
|
||
titleLabel.snp.makeConstraints { make in
|
||
make.leading.equalTo(icon.snp.trailing).offset(6)
|
||
make.centerY.equalToSuperview()
|
||
make.trailing.lessThanOrEqualTo(detailLabel.snp.leading).offset(-8)
|
||
}
|
||
detailLabel.snp.makeConstraints { make in make.trailing.centerY.equalToSuperview() }
|
||
isAccessibilityElement = true
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 展示限定点位的名称。
|
||
func apply(title: String) {
|
||
titleLabel.text = title
|
||
accessibilityLabel = "\(title),仅显示当前打卡点素材"
|
||
}
|
||
}
|
||
|
||
/// 素材分组上方的数量与全选控制,数量由当前可见记录提供。
|
||
@MainActor
|
||
final class DroneMaterialSelectionCell: UICollectionViewCell {
|
||
/// 点击后由控制器调用 ViewModel 的全选操作。
|
||
var onSelectAllTap: (() -> Void)?
|
||
private let countLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||
private let selectAllButton = UIButton(type: .system)
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
selectAllButton.titleLabel?.font = .systemFont(ofSize: 12)
|
||
selectAllButton.tintColor = DroneDockStyle.primary
|
||
selectAllButton.accessibilityIdentifier = "drone.materials.selectAll"
|
||
selectAllButton.addTarget(self, action: #selector(selectAllTapped), for: .touchUpInside)
|
||
let divider = UIView()
|
||
divider.backgroundColor = DroneDockStyle.border
|
||
[countLabel, selectAllButton, divider].forEach(contentView.addSubview)
|
||
countLabel.snp.makeConstraints { make in make.leading.centerY.equalToSuperview().offset(-2) }
|
||
selectAllButton.snp.makeConstraints { make in
|
||
make.trailing.equalToSuperview()
|
||
make.centerY.equalTo(countLabel)
|
||
make.leading.greaterThanOrEqualTo(countLabel.snp.trailing).offset(8)
|
||
make.height.equalTo(44)
|
||
}
|
||
divider.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) }
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 全选只面向当前可下载项,上传中与失败素材不会计入。
|
||
func apply(recordCount: Int, allSelected: Bool, enabled: Bool) {
|
||
countLabel.text = "\(recordCount)次拍摄 · 最新在前"
|
||
var config = UIButton.Configuration.plain()
|
||
config.title = "全选可下载"
|
||
config.imagePadding = 6
|
||
config.contentInsets = .zero
|
||
let foreground = enabled ? MaterialSelectionIcon.primary : UIColor(hex: 0xC2C9D4)
|
||
config.image = MaterialSelectionIcon.orderImage(selected: allSelected, size: 19,
|
||
tint: foreground, includesBackground: false)
|
||
config.baseForegroundColor = foreground
|
||
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
||
var attributes = incoming
|
||
attributes.font = .systemFont(ofSize: 12)
|
||
attributes.foregroundColor = foreground
|
||
return attributes
|
||
}
|
||
selectAllButton.configuration = config
|
||
selectAllButton.isEnabled = enabled
|
||
selectAllButton.accessibilityLabel = "全选可下载"
|
||
selectAllButton.accessibilityTraits = allSelected ? [.button, .selected] : .button
|
||
}
|
||
|
||
@objc private func selectAllTapped() { onSelectAllTap?() }
|
||
}
|
||
|
||
/// 每条拍摄记录的点位、航线、时间与独立的交付入口。
|
||
@MainActor
|
||
final class DroneMaterialRecordHeaderView: UICollectionReusableView {
|
||
/// 交付入口向上层请求对应点位的成片上传。
|
||
var onDeliveryTap: (() -> Void)?
|
||
private let titleLabel = DroneDockStyle.label(size: 17, weight: .semibold)
|
||
private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||
private let deliveryButton = UIButton(type: .system)
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
deliveryButton.titleLabel?.font = .systemFont(ofSize: 12)
|
||
var config = UIButton.Configuration.plain()
|
||
config.title = "交付成片"
|
||
config.image = UIImage(systemName: "play.rectangle")
|
||
config.imagePadding = 5
|
||
config.contentInsets = .zero
|
||
config.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 13)
|
||
config.baseForegroundColor = DroneDockStyle.primary
|
||
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
||
var attributes = incoming
|
||
attributes.font = .systemFont(ofSize: 12)
|
||
attributes.foregroundColor = DroneDockStyle.primary
|
||
return attributes
|
||
}
|
||
deliveryButton.configuration = config
|
||
deliveryButton.tintColor = DroneDockStyle.primary
|
||
deliveryButton.addTarget(self, action: #selector(deliveryTapped), for: .touchUpInside)
|
||
[titleLabel, detailLabel, deliveryButton].forEach(addSubview)
|
||
titleLabel.snp.makeConstraints { make in
|
||
make.leading.equalToSuperview()
|
||
make.top.equalToSuperview().offset(20)
|
||
make.trailing.lessThanOrEqualTo(deliveryButton.snp.leading).offset(-12)
|
||
}
|
||
deliveryButton.snp.makeConstraints { make in
|
||
make.trailing.equalToSuperview()
|
||
make.centerY.equalTo(titleLabel)
|
||
make.height.equalTo(44)
|
||
}
|
||
detailLabel.snp.makeConstraints { make in
|
||
make.leading.trailing.equalToSuperview()
|
||
make.top.equalTo(titleLabel.snp.bottom).offset(9)
|
||
make.bottom.lessThanOrEqualToSuperview().inset(10)
|
||
}
|
||
titleLabel.accessibilityTraits = .header
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 使用完整拍摄记录身份绑定交付入口,避免仅按同名点位匹配。
|
||
func apply(record: DroneMaterialRecord) {
|
||
titleLabel.text = record.pointName
|
||
detailLabel.text = record.summary
|
||
deliveryButton.accessibilityLabel = "\(record.pointName)交付成片,记录\(record.sequenceNumber)"
|
||
deliveryButton.accessibilityIdentifier = "drone.materials.delivery.\(record.id)"
|
||
}
|
||
|
||
@objc private func deliveryTapped() { onDeliveryTap?() }
|
||
}
|
||
|
||
/// 两列素材网格单元;缩略图预览与右上角多选按钮互不替代。
|
||
@MainActor
|
||
final class DroneMaterialCell: UICollectionViewCell {
|
||
/// 点击就绪缩略图时请求预览。
|
||
var onPreviewTap: (() -> Void)?
|
||
/// 点击右上角选择控件时仅改变选择。
|
||
var onSelectionTap: (() -> Void)?
|
||
private let thumbnail = UIImageView()
|
||
private let previewButton = UIButton(type: .custom)
|
||
private let selectionButton = UIButton(type: .custom)
|
||
private let placeholderIcon = UIImageView()
|
||
private let videoBadge = UILabel()
|
||
private let nameLabel = DroneDockStyle.label(size: 13, weight: .medium)
|
||
private let statusLabel = DroneDockStyle.label(size: 12)
|
||
private let retryUploadButton = UIButton(type: .system)
|
||
private let nameRow = UIStackView()
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
thumbnail.contentMode = .scaleAspectFill
|
||
thumbnail.clipsToBounds = true
|
||
thumbnail.layer.cornerRadius = 6
|
||
thumbnail.layer.cornerCurve = .continuous
|
||
thumbnail.backgroundColor = UIColor(hex: 0xE9EDF5)
|
||
thumbnail.layer.borderWidth = 2
|
||
placeholderIcon.contentMode = .scaleAspectFit
|
||
placeholderIcon.tintColor = UIColor(hex: 0x9CA6B6)
|
||
videoBadge.font = .systemFont(ofSize: 10, weight: .medium)
|
||
videoBadge.textColor = .white
|
||
videoBadge.backgroundColor = UIColor.black.withAlphaComponent(0.48)
|
||
videoBadge.layer.cornerRadius = 3
|
||
videoBadge.clipsToBounds = true
|
||
videoBadge.textAlignment = .center
|
||
videoBadge.text = "视频"
|
||
selectionButton.imageView?.contentMode = .scaleAspectFit
|
||
selectionButton.contentHorizontalAlignment = .right
|
||
selectionButton.contentVerticalAlignment = .top
|
||
selectionButton.addTarget(self, action: #selector(selectionTapped), for: .touchUpInside)
|
||
previewButton.addTarget(self, action: #selector(previewTapped), for: .touchUpInside)
|
||
retryUploadButton.setTitle("重试上传", for: .normal)
|
||
retryUploadButton.titleLabel?.font = .systemFont(ofSize: 11)
|
||
retryUploadButton.isEnabled = false
|
||
retryUploadButton.setTitleColor(DroneDockStyle.primary.withAlphaComponent(0.55), for: .disabled)
|
||
retryUploadButton.accessibilityHint = "当前演示不执行上传重试"
|
||
nameRow.axis = .horizontal
|
||
nameRow.alignment = .center
|
||
nameRow.spacing = 6
|
||
nameRow.addArrangedSubview(nameLabel)
|
||
nameRow.addArrangedSubview(retryUploadButton)
|
||
retryUploadButton.setContentHuggingPriority(.required, for: .horizontal)
|
||
retryUploadButton.setContentCompressionResistancePriority(UILayoutPriority(999), for: .horizontal)
|
||
retryUploadButton.snp.makeConstraints { make in make.height.equalTo(16) }
|
||
[thumbnail, placeholderIcon, previewButton, videoBadge, selectionButton, nameRow, statusLabel].forEach(contentView.addSubview)
|
||
thumbnail.snp.makeConstraints { make in
|
||
make.leading.trailing.top.equalToSuperview()
|
||
make.height.equalTo(thumbnail.snp.width).multipliedBy(9.0 / 16.0)
|
||
}
|
||
previewButton.snp.makeConstraints { make in make.edges.equalTo(thumbnail) }
|
||
placeholderIcon.snp.makeConstraints { make in make.center.equalTo(thumbnail); make.size.equalTo(29) }
|
||
videoBadge.snp.makeConstraints { make in
|
||
make.leading.equalTo(thumbnail).offset(6)
|
||
make.bottom.equalTo(thumbnail).inset(6)
|
||
make.width.equalTo(32)
|
||
make.height.equalTo(18)
|
||
}
|
||
selectionButton.snp.makeConstraints { make in
|
||
make.top.trailing.equalTo(thumbnail).inset(6)
|
||
make.size.equalTo(44)
|
||
}
|
||
nameRow.snp.makeConstraints { make in
|
||
make.leading.trailing.equalToSuperview()
|
||
make.top.equalTo(thumbnail.snp.bottom).offset(7)
|
||
}
|
||
statusLabel.snp.makeConstraints { make in
|
||
make.leading.trailing.equalToSuperview()
|
||
make.top.equalTo(nameRow.snp.bottom).offset(4)
|
||
make.bottom.lessThanOrEqualToSuperview().inset(5)
|
||
}
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 上传未就绪时显示占位且禁选,演示完成也不会标记为本机已保存。
|
||
func apply(material: DroneMaterial, selected: Bool, selectionEnabled: Bool, completed: Bool) {
|
||
nameLabel.text = material.title
|
||
statusLabel.text = material.statusTitle
|
||
statusLabel.textColor = DroneDockStyle.color(for: material.statusTone)
|
||
thumbnail.image = material.canPreview ? UIImage(named: material.previewAssetName) : nil
|
||
thumbnail.layer.borderColor = selected ? DroneDockStyle.primary.cgColor : UIColor.clear.cgColor
|
||
placeholderIcon.isHidden = material.canPreview
|
||
placeholderIcon.image = UIImage(systemName: material.uploadState == .failed ? "xmark.circle" : "play.fill")
|
||
placeholderIcon.tintColor = material.uploadState == .failed ? DroneDockStyle.color(for: .red) : UIColor(hex: 0x9CA6B6)
|
||
retryUploadButton.isHidden = material.uploadState != .failed
|
||
retryUploadButton.accessibilityIdentifier = "drone.materials.retryUpload.\(material.id)"
|
||
videoBadge.isHidden = material.kind != .video || !material.canPreview
|
||
previewButton.isEnabled = material.canPreview
|
||
previewButton.accessibilityIdentifier = "drone.materials.preview.\(material.id)"
|
||
previewButton.accessibilityLabel = "预览\(material.title)"
|
||
selectionButton.isHidden = material.uploadState != .ready
|
||
selectionButton.isEnabled = selectionEnabled && !completed
|
||
selectionButton.accessibilityIdentifier = "drone.materials.select.\(material.id)"
|
||
selectionButton.accessibilityLabel = completed ? "\(material.title),演示完成,未写入相册" : "选择\(material.title)"
|
||
selectionButton.accessibilityTraits = selected || completed ? [.button, .selected] : .button
|
||
let tint = completed ? DroneDockStyle.success : MaterialSelectionIcon.primary
|
||
selectionButton.setImage(MaterialSelectionIcon.orderImage(selected: selected || completed, size: 22,
|
||
tint: tint, includesBackground: true), for: .normal)
|
||
selectionButton.setImage(MaterialSelectionIcon.orderImage(selected: selected || completed, size: 22,
|
||
tint: tint, includesBackground: true, opacity: 0.6), for: .disabled)
|
||
}
|
||
|
||
@objc private func previewTapped() { onPreviewTap?() }
|
||
@objc private func selectionTapped() { onSelectionTap?() }
|
||
}
|
||
|
||
/// 分组之间轻量的分隔线。
|
||
@MainActor
|
||
final class DroneMaterialSeparatorView: UICollectionReusableView {
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
let line = UIView()
|
||
line.backgroundColor = DroneDockStyle.border
|
||
addSubview(line)
|
||
line.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) }
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
}
|
||
|
||
/// 列表加载、为空与失败时的就地说明,保留顶部订单与刷新入口。
|
||
@MainActor
|
||
final class DroneMaterialMessageCell: UICollectionViewCell {
|
||
private let icon = UIImageView()
|
||
private let titleLabel = DroneDockStyle.label(size: 16, weight: .medium)
|
||
private let detailLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
icon.tintColor = DroneDockStyle.secondary
|
||
icon.contentMode = .scaleAspectFit
|
||
titleLabel.textAlignment = .center
|
||
detailLabel.textAlignment = .center
|
||
detailLabel.numberOfLines = 0
|
||
let stack = UIStackView(arrangedSubviews: [icon, titleLabel, detailLabel])
|
||
stack.axis = .vertical
|
||
stack.alignment = .center
|
||
stack.spacing = 13
|
||
contentView.addSubview(stack)
|
||
stack.snp.makeConstraints { make in make.centerY.equalToSuperview().offset(-12); make.leading.trailing.equalToSuperview().inset(12) }
|
||
icon.snp.makeConstraints { make in make.size.equalTo(38) }
|
||
isAccessibilityElement = true
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 通过明确文案区分上传等待、空记录与加载异常。
|
||
func apply(title: String, detail: String, symbol: String) {
|
||
titleLabel.text = title
|
||
detailLabel.text = detail
|
||
icon.image = UIImage(systemName: symbol)
|
||
accessibilityLabel = "\(title),\(detail)"
|
||
}
|
||
}
|
||
|
||
/// 固定底栏以同一组件呈现选择、批次进度、暂停与完成结果。
|
||
@MainActor
|
||
final class DroneMaterialsFooterView: UIView {
|
||
/// 执行当前状态对应的主要操作。
|
||
var onPrimaryTap: (() -> Void)?
|
||
/// 返回选择状态或请求预留的交付入口。
|
||
var onSecondaryTap: (() -> Void)?
|
||
private let titleLabel = DroneDockStyle.label(size: 13, weight: .medium)
|
||
private let trailingLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||
private let resultIcon = UIImageView()
|
||
private let titleRow = UIStackView()
|
||
private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||
private let progressView = UIProgressView(progressViewStyle: .default)
|
||
private let primaryButton = UIButton(type: .system)
|
||
private let secondaryButton = UIButton(type: .system)
|
||
private let stack = UIStackView()
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
backgroundColor = .white
|
||
let divider = UIView()
|
||
divider.backgroundColor = DroneDockStyle.border
|
||
stack.axis = .vertical
|
||
stack.spacing = 10
|
||
titleLabel.numberOfLines = 2
|
||
titleLabel.accessibilityIdentifier = "drone.materials.footer.title"
|
||
trailingLabel.accessibilityIdentifier = "drone.materials.footer.trailing"
|
||
trailingLabel.textAlignment = .right
|
||
trailingLabel.setContentHuggingPriority(.required, for: .horizontal)
|
||
trailingLabel.setContentCompressionResistancePriority(UILayoutPriority(999), for: .horizontal)
|
||
resultIcon.contentMode = .scaleAspectFit
|
||
resultIcon.accessibilityIdentifier = "drone.materials.footer.resultIcon"
|
||
titleRow.axis = .horizontal
|
||
titleRow.alignment = .center
|
||
titleRow.spacing = 8
|
||
[resultIcon, titleLabel, trailingLabel].forEach(titleRow.addArrangedSubview)
|
||
detailLabel.numberOfLines = 2
|
||
detailLabel.accessibilityIdentifier = "drone.materials.footer.detail"
|
||
progressView.progressTintColor = DroneDockStyle.primary
|
||
progressView.trackTintColor = UIColor(hex: 0xE8EDF7)
|
||
progressView.accessibilityLabel = "本次素材下载保存进度"
|
||
primaryButton.titleLabel?.font = .systemFont(ofSize: 15, weight: .medium)
|
||
primaryButton.layer.cornerRadius = 7
|
||
primaryButton.layer.cornerCurve = .continuous
|
||
primaryButton.tintColor = .white
|
||
primaryButton.setTitleColor(.white, for: .normal)
|
||
primaryButton.setTitleColor(UIColor.white.withAlphaComponent(0.85), for: .disabled)
|
||
secondaryButton.titleLabel?.font = .systemFont(ofSize: 12)
|
||
secondaryButton.tintColor = DroneDockStyle.secondary
|
||
primaryButton.addTarget(self, action: #selector(primaryTapped), for: .touchUpInside)
|
||
secondaryButton.addTarget(self, action: #selector(secondaryTapped), for: .touchUpInside)
|
||
[titleRow, progressView, detailLabel, primaryButton, secondaryButton].forEach(stack.addArrangedSubview)
|
||
addSubview(divider)
|
||
addSubview(stack)
|
||
divider.snp.makeConstraints { make in make.leading.trailing.top.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) }
|
||
stack.snp.makeConstraints { make in
|
||
make.top.equalToSuperview().offset(12)
|
||
make.leading.trailing.equalToSuperview().inset(16)
|
||
make.bottom.equalTo(safeAreaLayoutGuide).inset(10)
|
||
}
|
||
primaryButton.snp.makeConstraints { make in make.height.equalTo(44) }
|
||
secondaryButton.snp.makeConstraints { make in make.height.equalTo(44).priority(999) }
|
||
resultIcon.snp.makeConstraints { make in make.width.height.equalTo(21).priority(999) }
|
||
progressView.snp.makeConstraints { make in make.height.equalTo(3).priority(999) }
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 只接受显示值,按钮语义和下载状态由控制器及 ViewModel 决定。
|
||
func apply(title: String, detail: String, primaryTitle: String, primarySymbol: String,
|
||
enabled: Bool, identifier: String, progress: Double?, secondaryTitle: String? = nil,
|
||
tone: DroneDockStatusTone = .gray, trailingText: String? = nil,
|
||
resultSymbol: String? = nil, secondaryOutlined: Bool = false, secondaryEnabled: Bool = true) {
|
||
titleLabel.text = title
|
||
titleLabel.textColor = DroneDockStyle.text
|
||
titleLabel.font = .systemFont(ofSize: 13, weight: resultSymbol == nil ? .regular : .semibold)
|
||
trailingLabel.text = trailingText
|
||
trailingLabel.isHidden = trailingText == nil
|
||
trailingLabel.textColor = progress == nil ? DroneDockStyle.secondary : DroneDockStyle.primary
|
||
resultIcon.image = resultSymbol.flatMap(UIImage.init(systemName:))
|
||
resultIcon.isHidden = resultSymbol == nil
|
||
resultIcon.tintColor = DroneDockStyle.color(for: tone)
|
||
detailLabel.text = detail
|
||
detailLabel.isHidden = detail.isEmpty
|
||
progressView.isHidden = progress == nil
|
||
progressView.setProgress(Float(progress ?? 0), animated: true)
|
||
var config = UIButton.Configuration.plain()
|
||
config.title = primaryTitle
|
||
config.image = UIImage(systemName: primarySymbol)
|
||
config.imagePadding = 7
|
||
config.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12)
|
||
config.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 16)
|
||
let primaryForeground: UIColor = enabled || progress == nil ? .white : DroneDockStyle.primary
|
||
let primaryBackground = enabled ? DroneDockStyle.primary : UIColor(hex: 0xCEDBFC)
|
||
config.cornerStyle = .fixed
|
||
config.background.cornerRadius = 7
|
||
config.background.backgroundColor = primaryBackground
|
||
config.background.backgroundColorTransformer = UIConfigurationColorTransformer { _ in primaryBackground }
|
||
config.baseForegroundColor = primaryForeground
|
||
config.imageColorTransformer = UIConfigurationColorTransformer { _ in primaryForeground }
|
||
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
||
var attributes = incoming
|
||
attributes.font = .systemFont(ofSize: 15, weight: .medium)
|
||
attributes.foregroundColor = primaryForeground
|
||
return attributes
|
||
}
|
||
primaryButton.configuration = config
|
||
primaryButton.isEnabled = enabled
|
||
primaryButton.backgroundColor = .clear
|
||
primaryButton.accessibilityIdentifier = identifier
|
||
var secondary = UIButton.Configuration.plain()
|
||
secondary.title = secondaryTitle
|
||
secondary.image = secondaryOutlined ? UIImage(systemName: "play.rectangle") : nil
|
||
secondary.imagePadding = 6
|
||
secondary.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 14)
|
||
let secondaryForeground = secondaryOutlined ? DroneDockStyle.primary : DroneDockStyle.secondary
|
||
secondary.cornerStyle = .fixed
|
||
secondary.background.cornerRadius = 7
|
||
secondary.baseForegroundColor = secondaryForeground
|
||
secondary.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
||
var attributes = incoming
|
||
attributes.font = .systemFont(ofSize: 12)
|
||
attributes.foregroundColor = secondaryForeground
|
||
return attributes
|
||
}
|
||
secondaryButton.configuration = secondary
|
||
secondaryButton.tintColor = secondaryOutlined ? DroneDockStyle.primary : DroneDockStyle.secondary
|
||
secondaryButton.layer.cornerRadius = 7
|
||
secondaryButton.layer.borderWidth = secondaryOutlined ? 1 : 0
|
||
secondaryButton.layer.borderColor = DroneDockStyle.primary.cgColor
|
||
secondaryButton.isHidden = secondaryTitle == nil
|
||
secondaryButton.isEnabled = secondaryEnabled
|
||
secondaryButton.accessibilityIdentifier = secondaryOutlined ? "drone.materials.completedDelivery" : "drone.materials.continueSelecting"
|
||
}
|
||
|
||
@objc private func primaryTapped() { onPrimaryTap?() }
|
||
@objc private func secondaryTapped() { onSecondaryTap?() }
|
||
}
|