Files
suixinkan_uikit/suixinkan/UI/DroneDock/DroneMaterialComponents.swift
T
lujiuyin b95b251de1 feat: 完善机巢模拟调试与素材交付交互
增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
2026-10-30 09:59:11 +08:00

569 lines
29 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import SnapKit
import UIKit
/// 缩略图上的选择圆圈,显式绘制白色勾选以免透出背景图片。
@MainActor
enum DroneMaterialSelectionIcon {
/// 使用固定配色绘制选择状态,避免按钮重新应用系统 tint。
static func image(selected: Bool, tint: UIColor, opacity: CGFloat = 1) -> UIImage {
UIGraphicsImageRenderer(size: CGSize(width: 24, height: 24)).image { context in
context.cgContext.setAlpha(opacity)
let circle = UIBezierPath(ovalIn: CGRect(x: 1, y: 1, width: 22, height: 22))
tint.set()
if selected {
circle.fill()
UIColor.white.setStroke()
let check = UIBezierPath()
check.move(to: CGPoint(x: 6.5, y: 12))
check.addLine(to: CGPoint(x: 10.5, y: 16))
check.addLine(to: CGPoint(x: 17.5, y: 7.5))
check.lineWidth = 2.2
check.lineCapStyle = .round
check.lineJoinStyle = .round
check.stroke()
} else {
circle.lineWidth = 1.6
circle.stroke()
}
}.withRenderingMode(.alwaysOriginal)
}
}
/// 素材库的订单摘要,保留拍摄履约与素材处理相互独立的表达。
@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.image = UIImage(systemName: allSelected ? "checkmark.circle.fill" : "circle")
config.imagePadding = 6
config.contentInsets = .zero
config.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 15)
let foreground = enabled ? DroneDockStyle.primary : UIColor(hex: 0xC2C9D4)
config.baseForegroundColor = foreground
config.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var attributes = incoming
attributes.font = .systemFont(ofSize: 12)
attributes.foregroundColor = foreground
return attributes
}
config.imageColorTransformer = UIConfigurationColorTransformer { _ in foreground }
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.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)
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 : selected ? DroneDockStyle.primary : UIColor.white
selectionButton.setImage(DroneMaterialSelectionIcon.image(selected: selected || completed, tint: tint), for: .normal)
selectionButton.setImage(DroneMaterialSelectionIcon.image(selected: selected || completed, tint: tint, opacity: 0.6), for: .disabled)
selectionButton.imageView?.layer.shadowColor = UIColor.black.cgColor
selectionButton.imageView?.layer.shadowOpacity = 0.22
selectionButton.imageView?.layer.shadowRadius = 2
selectionButton.imageView?.layer.shadowOffset = .zero
}
@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?() }
}