Redesign nearby transfer and cloud delivery screens
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 云端交付顶部的游客摘要,订单身份由页面读取真实数据后传入。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryCustomerCell: UICollectionViewCell {
|
||||
private let customer = DroneDockDeliveryCustomerView(showsCard: false)
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
contentView.addSubview(customer)
|
||||
customer.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 只展示当前订单的游客与尾号,不生成业务示例数据。
|
||||
func apply(title: String, orderNumber: String?) {
|
||||
customer.apply(title: title, orderNumber: orderNumber)
|
||||
accessibilityIdentifier = "drone.delivery.order"
|
||||
}
|
||||
}
|
||||
|
||||
/// 云端上传的短标题与用途说明,与任务选择和提交权限分离。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryIntroCell: UICollectionViewCell {
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
let title = DroneDockStyle.label("交付你的精彩成片", size: 25, weight: .bold, color: DroneDockDeliveryDesign.text)
|
||||
title.accessibilityIdentifier = "drone.delivery.intro.title"
|
||||
title.numberOfLines = 0
|
||||
let detail = DroneDockStyle.label("将视频保存到当前拍摄任务,供游客查看", size: 13, color: DroneDockDeliveryDesign.secondary)
|
||||
detail.numberOfLines = 0
|
||||
let stack = UIStackView(arrangedSubviews: [title, detail])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 7
|
||||
contentView.addSubview(stack)
|
||||
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 5, left: 0, bottom: 8, right: 0)) }
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
}
|
||||
|
||||
/// 素材任务入口的只读任务卡;已关联的目标不会被设计成可切换选项。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryBoundTaskCell: UICollectionViewCell {
|
||||
private let heading = DroneDockStyle.label("当前拍摄任务", size: 15, weight: .semibold, color: DroneDockDeliveryDesign.text)
|
||||
private let badge = UILabel()
|
||||
private let icon = UIImageView(image: UIImage(systemName: "mappin.circle"))
|
||||
private let titleLabel = DroneDockStyle.label(size: 17, weight: .semibold, color: DroneDockDeliveryDesign.text)
|
||||
private let detailsLabel = DroneDockStyle.label(size: 12, color: DroneDockDeliveryDesign.secondary)
|
||||
private let filmLabel = DroneDockStyle.label(size: 12, color: DroneDockDeliveryDesign.secondary)
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
DroneDockDeliveryDesign.card(to: contentView, cornerRadius: 16)
|
||||
badge.text = "已关联"
|
||||
badge.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
badge.textColor = DroneDockDeliveryDesign.primary
|
||||
badge.textAlignment = .center
|
||||
badge.backgroundColor = UIColor(hex: 0xE5EFFF)
|
||||
badge.layer.cornerRadius = 12
|
||||
badge.clipsToBounds = true
|
||||
badge.setContentCompressionResistancePriority(.required, for: .horizontal)
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.accessibilityIdentifier = "drone.delivery.boundTask.title"
|
||||
detailsLabel.numberOfLines = 0
|
||||
filmLabel.numberOfLines = 0
|
||||
filmLabel.isHidden = true
|
||||
icon.tintColor = DroneDockDeliveryDesign.primary
|
||||
icon.contentMode = .scaleAspectFit
|
||||
let headingRow = UIStackView(arrangedSubviews: [heading, badge])
|
||||
headingRow.alignment = .center
|
||||
headingRow.spacing = 12
|
||||
badge.snp.makeConstraints { $0.width.equalTo(62); $0.height.equalTo(25) }
|
||||
let text = UIStackView(arrangedSubviews: [titleLabel, detailsLabel, filmLabel])
|
||||
text.axis = .vertical
|
||||
text.spacing = 7
|
||||
let body = UIStackView(arrangedSubviews: [icon, text])
|
||||
body.alignment = .top
|
||||
body.spacing = 12
|
||||
icon.snp.makeConstraints { $0.width.height.equalTo(25) }
|
||||
let stack = UIStackView(arrangedSubviews: [headingRow, body])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 15
|
||||
contentView.addSubview(stack)
|
||||
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(16) }
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 长点位名完整换行,已有成片的替换提示在卡片内保留。
|
||||
func apply(task: DroneDockMaterialTask?) {
|
||||
if let task {
|
||||
heading.text = "当前拍摄任务"
|
||||
badge.isHidden = false
|
||||
titleLabel.text = Self.text(task.spotName, fallback: "当前点位")
|
||||
let number = task.sequence.map { String(format: "%02d", $0) }
|
||||
let record = number.map { "拍摄记录 \($0)" } ?? "当前拍摄记录"
|
||||
detailsLabel.text = "\(record) · \(Self.text(task.airLineName, fallback: "航线待确认"))\n\(Self.text(task.createdAt, fallback: "时间待确认"))"
|
||||
filmLabel.text = task.film.map { "已有成片:\(Self.text($0.fileName, fallback: "视频成片"))\n上传新视频前会请你确认替换" }
|
||||
filmLabel.isHidden = task.film == nil
|
||||
accessibilityIdentifier = "drone.delivery.boundTask.\(task.id)"
|
||||
} else {
|
||||
heading.text = "当前拍摄任务"
|
||||
badge.isHidden = true
|
||||
titleLabel.text = "原拍摄任务暂不可用"
|
||||
detailsLabel.text = "请返回素材库刷新后,从对应任务重新进入"
|
||||
filmLabel.isHidden = true
|
||||
accessibilityIdentifier = "drone.delivery.boundTask.unavailable"
|
||||
}
|
||||
}
|
||||
|
||||
private static func text(_ value: String?, fallback: String) -> String {
|
||||
DroneDockHomeMetric.usableText(value) ?? fallback
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import AVFoundation
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 云端上传与面对面闪传共用的展示颜色和卡片外观,不参与交付业务。
|
||||
@MainActor
|
||||
enum DroneDockDeliveryDesign {
|
||||
static let background = UIColor(hex: 0xF5F7FB)
|
||||
static let primary = UIColor(hex: 0x066BFF)
|
||||
static let text = UIColor(hex: 0x172033)
|
||||
static let secondary = UIColor(hex: 0x7B879C)
|
||||
static let border = UIColor(hex: 0xE7ECF4)
|
||||
|
||||
/// 应用两页一致的白色卡片与细边框,尺寸和内容布局由调用方决定。
|
||||
static func card(to view: UIView, cornerRadius: CGFloat = 14) {
|
||||
view.backgroundColor = .white
|
||||
view.layer.cornerRadius = cornerRadius
|
||||
view.layer.cornerCurve = .continuous
|
||||
view.layer.borderWidth = 1
|
||||
view.layer.borderColor = border.cgColor
|
||||
}
|
||||
}
|
||||
|
||||
/// 交付对象摘要:中性系统头像、真实游客标题及可选订单尾号。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryCustomerView: UIView {
|
||||
private let avatar = UIView()
|
||||
private let avatarIcon = UIImageView(image: UIImage(systemName: "person.fill"))
|
||||
private let titleLabel = DroneDockStyle.label(size: 16, weight: .semibold, color: DroneDockDeliveryDesign.text)
|
||||
private let orderLabel = DroneDockStyle.label(size: 13, color: DroneDockDeliveryDesign.secondary)
|
||||
private let labels = UIStackView()
|
||||
private let row = UIStackView()
|
||||
|
||||
/// 默认显示白卡;两种交付入口使用相同内容与自适应高度。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
/// 云端上传可选择透明背景,面对面闪传默认保留白色摘要卡。
|
||||
convenience init(showsCard: Bool = true) {
|
||||
self.init(frame: .zero)
|
||||
if !showsCard {
|
||||
backgroundColor = .clear
|
||||
layer.borderWidth = 0
|
||||
row.snp.updateConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)) }
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 直接展示调用方的游客标题;订单缺失时隐藏尾号行,不补造号码。
|
||||
func apply(title: String, orderNumber: String?) {
|
||||
titleLabel.text = title
|
||||
let number = orderNumber?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
orderLabel.text = number.flatMap { $0.isEmpty ? nil : "订单尾号 \($0.suffix(4))" }
|
||||
orderLabel.isHidden = orderLabel.text == nil
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
DroneDockDeliveryDesign.card(to: self)
|
||||
accessibilityIdentifier = "drone.delivery.customer"
|
||||
avatar.backgroundColor = UIColor(hex: 0xE8EEF7)
|
||||
avatar.layer.cornerRadius = 24
|
||||
avatarIcon.tintColor = UIColor(hex: 0x91A7C2)
|
||||
avatarIcon.contentMode = .scaleAspectFit
|
||||
avatarIcon.isAccessibilityElement = false
|
||||
avatar.addSubview(avatarIcon)
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.lineBreakMode = .byWordWrapping
|
||||
titleLabel.accessibilityIdentifier = "drone.delivery.customer.title"
|
||||
orderLabel.accessibilityIdentifier = "drone.delivery.customer.order"
|
||||
orderLabel.isHidden = true
|
||||
labels.axis = .vertical
|
||||
labels.spacing = 5
|
||||
labels.addArrangedSubview(titleLabel)
|
||||
labels.addArrangedSubview(orderLabel)
|
||||
row.axis = .horizontal
|
||||
row.alignment = .center
|
||||
row.spacing = 12
|
||||
row.addArrangedSubview(avatar)
|
||||
row.addArrangedSubview(labels)
|
||||
addSubview(row)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
row.snp.makeConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 14, left: 16, bottom: 14, right: 16)) }
|
||||
avatar.snp.makeConstraints { $0.size.equalTo(48) }
|
||||
avatarIcon.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.size.equalTo(25)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 从当前选中的本地视频异步生成封面;不加载网络图片,不包含播放按钮或固定比例。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryVideoThumbnailView: UIView {
|
||||
private let imageView = UIImageView()
|
||||
private let placeholder = UIImageView(image: UIImage(systemName: "video.fill"))
|
||||
private var representedID: UUID?
|
||||
private var generator: AVAssetImageGenerator?
|
||||
private var thumbnailTask: Task<Void, Never>?
|
||||
|
||||
/// 默认圆角封面,外部页面决定大小、比例及预览操作。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
deinit { thumbnailTask?.cancel() }
|
||||
|
||||
/// 同一视频身份只生成一次;更换或移除时取消生成并立即清除旧封面。
|
||||
func apply(video: DroneDockDeliveryVideo?) {
|
||||
guard representedID != video?.id else { return }
|
||||
representedID = video?.id
|
||||
thumbnailTask?.cancel()
|
||||
thumbnailTask = nil
|
||||
generator?.cancelAllCGImageGeneration()
|
||||
generator = nil
|
||||
imageView.image = nil
|
||||
placeholder.isHidden = false
|
||||
accessibilityLabel = video == nil ? "未选择视频" : "视频封面暂不可用"
|
||||
guard let video, video.url.isFileURL else { return }
|
||||
let generator = AVAssetImageGenerator(asset: AVURLAsset(url: video.url))
|
||||
generator.appliesPreferredTrackTransform = true
|
||||
generator.maximumSize = CGSize(width: 960, height: 540)
|
||||
self.generator = generator
|
||||
thumbnailTask = Task { @MainActor [weak self] in
|
||||
let image = try? await generator.image(at: .zero).image
|
||||
guard let self, !Task.isCancelled, self.representedID == video.id else { return }
|
||||
self.generator = nil
|
||||
self.thumbnailTask = nil
|
||||
guard let image else { return }
|
||||
self.imageView.image = UIImage(cgImage: image)
|
||||
self.placeholder.isHidden = true
|
||||
self.accessibilityLabel = "所选视频封面"
|
||||
}
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = UIColor(hex: 0xE8EEF7)
|
||||
layer.cornerRadius = 10
|
||||
layer.cornerCurve = .continuous
|
||||
clipsToBounds = true
|
||||
isAccessibilityElement = true
|
||||
accessibilityIdentifier = "drone.delivery.thumbnail"
|
||||
accessibilityLabel = "未选择视频"
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
imageView.accessibilityIdentifier = "drone.delivery.thumbnail.image"
|
||||
placeholder.tintColor = UIColor(hex: 0x91A7C2)
|
||||
placeholder.contentMode = .scaleAspectFit
|
||||
placeholder.accessibilityIdentifier = "drone.delivery.thumbnail.placeholder"
|
||||
[imageView, placeholder].forEach(addSubview)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
imageView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
placeholder.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.size.equalTo(30)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ enum DroneDockDeliveryEntry {
|
||||
methods.onClose = { [weak navigation] in navigation?.dismiss(animated: true) }
|
||||
methods.onNearbyTransfer = { [weak navigation, weak methods] in
|
||||
guard let navigation, let methods, navigation.topViewController === methods else { return }
|
||||
let nearby = DroneDockNearbyTransferViewController(customerTitle: order.touristTitle)
|
||||
let nearby = DroneDockNearbyTransferViewController(customerTitle: order.touristTitle, orderNumber: order.orderNumber)
|
||||
nearby.onClose = { [weak navigation] in navigation?.dismiss(animated: true) }
|
||||
navigation.isModalInPresentation = true
|
||||
navigation.sheetPresentationController?.animateChanges {
|
||||
|
||||
@@ -2,73 +2,90 @@ import AVFoundation
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 固定操作区上方的单视频摘要,展示真实本地封面并提供预览、更换与移除。
|
||||
/// 固定上传操作区上方的大视频预览,使用真实本地封面并保留更换和移除。
|
||||
@MainActor
|
||||
final class DroneDockDeliverySelectedVideoView: UIView {
|
||||
private let thumbnail = UIImageView()
|
||||
private let content = UIView()
|
||||
private let heading = DroneDockStyle.label("已选视频", size: 15, weight: .semibold, color: DroneDockDeliveryDesign.text)
|
||||
private let thumbnail = DroneDockDeliveryVideoThumbnailView()
|
||||
private let previewButton = UIButton(type: .custom)
|
||||
private let nameLabel = DroneDockStyle.label(size: 14, weight: .semibold)
|
||||
private let sizeLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||||
private let nameLabel = DroneDockStyle.label(size: 15, weight: .semibold, color: DroneDockDeliveryDesign.text)
|
||||
private let sizeLabel = DroneDockStyle.label(size: 12, color: DroneDockDeliveryDesign.secondary)
|
||||
private let replaceButton = UIButton(type: .system)
|
||||
private let removeButton = UIButton(type: .system)
|
||||
private var preview: (() -> Void)?
|
||||
private var replace: (() -> Void)?
|
||||
private var remove: (() -> Void)?
|
||||
private var representedID: UUID?
|
||||
private var thumbnailTask: Task<Void, Never>?
|
||||
private var durationText: String?
|
||||
private var metadataTask: Task<Void, Never>?
|
||||
|
||||
/// 创建固定高度的本地视频摘要;没有封面时保留中性视频图标。
|
||||
/// 创建可随屏幕高度收紧的预览卡,按钮均保留至少44点触控范围。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
backgroundColor = .white
|
||||
layer.cornerRadius = 9
|
||||
layer.borderWidth = 1
|
||||
layer.borderColor = UIColor(hex: 0xE4EAF2).cgColor
|
||||
DroneDockDeliveryDesign.card(to: self, cornerRadius: 16)
|
||||
clipsToBounds = true
|
||||
accessibilityIdentifier = "drone.delivery.selectedVideo"
|
||||
thumbnail.backgroundColor = UIColor(hex: 0xE8EFF8)
|
||||
thumbnail.tintColor = UIColor(hex: 0x8091AA)
|
||||
thumbnail.contentMode = .scaleAspectFill
|
||||
thumbnail.clipsToBounds = true
|
||||
thumbnail.layer.cornerRadius = 7
|
||||
previewButton.setImage(UIImage(systemName: "play.circle.fill"), for: .normal)
|
||||
previewButton.tintColor = .white
|
||||
thumbnail.layer.cornerRadius = 10
|
||||
thumbnail.isAccessibilityElement = false
|
||||
thumbnail.accessibilityIdentifier = "drone.delivery.selectedVideo.cover"
|
||||
previewButton.setImage(UIImage(systemName: "play.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 19, weight: .semibold)), for: .normal)
|
||||
previewButton.tintColor = DroneDockDeliveryDesign.text
|
||||
previewButton.backgroundColor = .white
|
||||
previewButton.layer.cornerRadius = 24
|
||||
previewButton.accessibilityIdentifier = "drone.delivery.preview"
|
||||
previewButton.accessibilityLabel = "预览所选视频"
|
||||
previewButton.addTarget(self, action: #selector(previewTapped), for: .touchUpInside)
|
||||
nameLabel.numberOfLines = 2
|
||||
nameLabel.lineBreakMode = .byTruncatingMiddle
|
||||
nameLabel.accessibilityIdentifier = "drone.delivery.selectedVideo.name"
|
||||
replaceButton.setTitle("更换", for: .normal)
|
||||
replaceButton.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
|
||||
replaceButton.setTitle("重新选择", for: .normal)
|
||||
replaceButton.setTitleColor(DroneDockDeliveryDesign.primary, for: .normal)
|
||||
replaceButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
replaceButton.accessibilityIdentifier = "drone.delivery.chooseVideo"
|
||||
replaceButton.addTarget(self, action: #selector(replaceTapped), for: .touchUpInside)
|
||||
removeButton.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
|
||||
removeButton.tintColor = DroneDockStyle.secondary
|
||||
removeButton.setTitle("移除", for: .normal)
|
||||
removeButton.setTitleColor(DroneDockDeliveryDesign.secondary, for: .normal)
|
||||
removeButton.titleLabel?.font = .systemFont(ofSize: 14)
|
||||
removeButton.accessibilityLabel = "移除所选视频"
|
||||
removeButton.accessibilityIdentifier = "drone.delivery.removeVideo"
|
||||
removeButton.addTarget(self, action: #selector(removeTapped), for: .touchUpInside)
|
||||
[thumbnail, previewButton, nameLabel, sizeLabel, replaceButton, removeButton].forEach(addSubview)
|
||||
thumbnail.snp.makeConstraints { make in make.leading.equalToSuperview().offset(12); make.centerY.equalToSuperview(); make.size.equalTo(CGSize(width: 80, height: 54)) }
|
||||
previewButton.snp.makeConstraints { $0.edges.equalTo(thumbnail) }
|
||||
removeButton.snp.makeConstraints { make in make.top.trailing.equalToSuperview(); make.size.equalTo(44) }
|
||||
replaceButton.snp.makeConstraints { make in make.trailing.bottom.equalToSuperview().inset(6); make.width.equalTo(50); make.height.equalTo(44) }
|
||||
addSubview(content)
|
||||
content.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
make.bottom.equalToSuperview().priority(999)
|
||||
make.height.greaterThanOrEqualTo(200)
|
||||
}
|
||||
[heading, thumbnail, nameLabel, sizeLabel, replaceButton, removeButton].forEach(content.addSubview)
|
||||
thumbnail.addSubview(previewButton)
|
||||
heading.snp.makeConstraints { make in make.top.equalToSuperview().offset(16); make.leading.equalToSuperview().offset(16) }
|
||||
replaceButton.snp.makeConstraints { make in make.top.equalToSuperview().offset(2); make.trailing.equalToSuperview().inset(8); make.height.equalTo(44); make.width.equalTo(86) }
|
||||
thumbnail.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(44)
|
||||
make.leading.trailing.equalToSuperview().inset(12)
|
||||
make.bottom.equalTo(nameLabel.snp.top).offset(-9)
|
||||
make.height.greaterThanOrEqualTo(70)
|
||||
}
|
||||
previewButton.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(48) }
|
||||
removeButton.snp.makeConstraints { make in make.top.equalTo(nameLabel).offset(-5); make.trailing.equalToSuperview().inset(6); make.size.equalTo(48) }
|
||||
nameLabel.snp.makeConstraints { make in
|
||||
make.leading.equalTo(thumbnail.snp.trailing).offset(10)
|
||||
make.leading.equalToSuperview().offset(16)
|
||||
make.trailing.equalTo(removeButton.snp.leading).offset(-4)
|
||||
make.top.equalToSuperview().offset(16)
|
||||
make.height.equalTo(36)
|
||||
}
|
||||
sizeLabel.snp.makeConstraints { make in
|
||||
make.leading.equalTo(nameLabel)
|
||||
make.trailing.lessThanOrEqualTo(replaceButton.snp.leading).offset(-4)
|
||||
make.top.equalTo(nameLabel.snp.bottom).offset(5)
|
||||
make.bottom.lessThanOrEqualToSuperview().inset(12).priority(999)
|
||||
make.trailing.lessThanOrEqualTo(removeButton.snp.leading).offset(-4)
|
||||
make.top.equalTo(nameLabel.snp.bottom).offset(2)
|
||||
make.height.equalTo(16)
|
||||
make.bottom.equalToSuperview().inset(12)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
deinit { thumbnailTask?.cancel() }
|
||||
deinit { metadataTask?.cancel() }
|
||||
|
||||
/// 选择只更新摘要,不发起上传;异步封面按视频身份丢弃迟到结果。
|
||||
func apply(video: DroneDockDeliveryVideo?, enabled: Bool,
|
||||
@@ -76,28 +93,33 @@ final class DroneDockDeliverySelectedVideoView: UIView {
|
||||
self.preview = preview
|
||||
self.replace = replace
|
||||
self.remove = remove
|
||||
let changed = representedID != video?.id
|
||||
if changed { durationText = nil }
|
||||
nameLabel.text = video?.fileName
|
||||
sizeLabel.text = video.map { ByteCountFormatter.string(fromByteCount: Int64($0.fileSize), countStyle: .file) }
|
||||
updateFileMetadata(video)
|
||||
[previewButton, replaceButton, removeButton].forEach { $0.isEnabled = enabled && video != nil }
|
||||
guard representedID != video?.id else { return }
|
||||
thumbnail.apply(video: video)
|
||||
guard changed else { return }
|
||||
representedID = video?.id
|
||||
thumbnailTask?.cancel()
|
||||
thumbnail.image = UIImage(systemName: "video.fill")
|
||||
thumbnail.contentMode = .scaleAspectFit
|
||||
guard let video else { return }
|
||||
thumbnailTask = Task { @MainActor [weak self] in
|
||||
let image = await Task.detached(priority: .utility) { Self.makeThumbnail(url: video.url) }.value
|
||||
guard let self, !Task.isCancelled, self.representedID == video.id, let image else { return }
|
||||
self.thumbnail.image = UIImage(cgImage: image)
|
||||
self.thumbnail.contentMode = .scaleAspectFill
|
||||
metadataTask?.cancel()
|
||||
guard let video, video.url.isFileURL else { return }
|
||||
metadataTask = Task { @MainActor [weak self] in
|
||||
let duration = try? await AVURLAsset(url: video.url).load(.duration)
|
||||
guard let self, !Task.isCancelled, self.representedID == video.id,
|
||||
let seconds = duration?.seconds, seconds.isFinite, seconds > 0,
|
||||
seconds < Double(Int.max / 2) else { return }
|
||||
let whole = Int(seconds.rounded())
|
||||
let time = String(format: "%02d:%02d", whole / 60, whole % 60)
|
||||
self.durationText = time
|
||||
self.updateFileMetadata(video)
|
||||
}
|
||||
}
|
||||
|
||||
private nonisolated static func makeThumbnail(url: URL) -> CGImage? {
|
||||
let generator = AVAssetImageGenerator(asset: AVURLAsset(url: url))
|
||||
generator.appliesPreferredTrackTransform = true
|
||||
generator.maximumSize = CGSize(width: 240, height: 135)
|
||||
return try? generator.copyCGImage(at: .zero, actualTime: nil)
|
||||
private func updateFileMetadata(_ video: DroneDockDeliveryVideo?) {
|
||||
sizeLabel.text = video.map { video in
|
||||
[ByteCountFormatter.string(fromByteCount: Int64(video.fileSize), countStyle: .file), durationText]
|
||||
.compactMap { $0 }.joined(separator: " · ")
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func previewTapped() { preview?() }
|
||||
|
||||
@@ -26,15 +26,18 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
private let footer = UIView()
|
||||
private let stateLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||||
private let progressView = UIProgressView(progressViewStyle: .default)
|
||||
private let footerNote = DroneDockStyle.label("保存成功后,游客可在小程序相册查看", size: 11, color: DroneDockDeliveryDesign.secondary)
|
||||
private let submitButton = UIButton(type: .system)
|
||||
private let selectedVideoView = DroneDockDeliverySelectedVideoView()
|
||||
private var selectedVideoHeight: Constraint?
|
||||
private var selectedVideoBottom: Constraint?
|
||||
private var progressHeight: Constraint?
|
||||
private var displayedVideoHeight: CGFloat = 0
|
||||
|
||||
/// 点位横向排列,其余信息按步骤向下展示。
|
||||
private enum Section: Hashable { case order, points, tasks, state }
|
||||
/// 身份稳定的 Diffable 项目,上传进度不改变选择。
|
||||
private enum Item: Hashable { case order, point(Int), task(Int), boundTask, choosePoint, emptyTasks, state }
|
||||
private enum Item: Hashable { case order, intro, point(Int), task(Int), boundTask, choosePoint, emptyTasks, state }
|
||||
|
||||
/// 注入上传状态、真实保存回调和可测试的视频选择入口。
|
||||
init(viewModel: DroneDockDeliveryViewModel, onDidSave: (() -> Void)? = nil,
|
||||
@@ -62,47 +65,78 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
override func setupNavigationBar() {
|
||||
title = "云端上传"
|
||||
navigationItem.backButtonDisplayMode = .minimal
|
||||
let back = UIBarButtonItem(title: onCloseSheet == nil ? "返回" : "交付方式", style: .plain, target: self, action: #selector(backTapped))
|
||||
let appearance = UINavigationBarAppearance()
|
||||
appearance.configureWithOpaqueBackground()
|
||||
appearance.backgroundColor = DroneDockDeliveryDesign.background
|
||||
appearance.shadowColor = .clear
|
||||
appearance.titleTextAttributes = [.foregroundColor: DroneDockDeliveryDesign.text, .font: UIFont.systemFont(ofSize: 18, weight: .semibold)]
|
||||
navigationItem.standardAppearance = appearance
|
||||
navigationItem.scrollEdgeAppearance = appearance
|
||||
navigationController?.navigationBar.tintColor = DroneDockDeliveryDesign.text
|
||||
let back = UIBarButtonItem(image: UIImage(systemName: "chevron.left"), style: .plain, target: self, action: #selector(backTapped))
|
||||
back.accessibilityLabel = onCloseSheet == nil ? "返回" : "返回交付方式"
|
||||
back.accessibilityIdentifier = "drone.delivery.back"
|
||||
navigationItem.leftBarButtonItem = back
|
||||
let refresh = UIBarButtonItem(title: "刷新", style: .plain, target: self, action: #selector(refreshTapped))
|
||||
refresh.accessibilityIdentifier = "drone.delivery.refresh"
|
||||
navigationItem.rightBarButtonItem = refresh
|
||||
if onCloseSheet != nil {
|
||||
let close = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .plain, target: self, action: #selector(closeSheetTapped))
|
||||
close.accessibilityLabel = "关闭成片交付"
|
||||
close.accessibilityIdentifier = "drone.delivery.sheet.close"
|
||||
navigationItem.rightBarButtonItems = [close, refresh]
|
||||
}
|
||||
navigationItem.rightBarButtonItem = close
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = .white
|
||||
view.backgroundColor = DroneDockDeliveryDesign.background
|
||||
collectionView.backgroundColor = .clear
|
||||
collectionView.alwaysBounceVertical = true
|
||||
collectionView.accessibilityIdentifier = "drone.delivery.remote.list"
|
||||
collectionView.delegate = self
|
||||
collectionView.register(DroneMaterialFilterCell.self, forCellWithReuseIdentifier: "point")
|
||||
collectionView.register(DroneDockDeliveryTextCell.self, forCellWithReuseIdentifier: "text")
|
||||
collectionView.register(DroneDockDeliveryCustomerCell.self, forCellWithReuseIdentifier: "customer")
|
||||
collectionView.register(DroneDockDeliveryIntroCell.self, forCellWithReuseIdentifier: "intro")
|
||||
collectionView.register(DroneDockDeliveryBoundTaskCell.self, forCellWithReuseIdentifier: "boundTask")
|
||||
let refresh = UIRefreshControl()
|
||||
refresh.addTarget(self, action: #selector(refreshTapped), for: .valueChanged)
|
||||
collectionView.refreshControl = refresh
|
||||
footer.backgroundColor = .white
|
||||
stateLabel.numberOfLines = 0
|
||||
stateLabel.accessibilityIdentifier = "drone.delivery.progressText"
|
||||
progressView.progressTintColor = DroneDockStyle.primary
|
||||
progressView.progressTintColor = DroneDockDeliveryDesign.primary
|
||||
progressView.accessibilityIdentifier = "drone.delivery.progress"
|
||||
submitButton.setTitleColor(.white, for: .normal)
|
||||
submitButton.setTitleColor(UIColor(hex: 0x066BFF), for: .disabled)
|
||||
submitButton.titleLabel?.font = .systemFont(ofSize: 15, weight: .semibold)
|
||||
submitButton.layer.cornerRadius = 9
|
||||
var configuration = UIButton.Configuration.filled()
|
||||
configuration.imagePadding = 10
|
||||
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 20, weight: .medium)
|
||||
configuration.cornerStyle = .fixed
|
||||
configuration.background.cornerRadius = 12
|
||||
configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 14, bottom: 0, trailing: 14)
|
||||
submitButton.configuration = configuration
|
||||
submitButton.configurationUpdateHandler = { button in
|
||||
guard var configuration = button.configuration else { return }
|
||||
let foreground = button.isEnabled || configuration.showsActivityIndicator ? UIColor.white : DroneDockDeliveryDesign.primary.withAlphaComponent(0.55)
|
||||
configuration.background.backgroundColor = button.isEnabled || configuration.showsActivityIndicator
|
||||
? DroneDockDeliveryDesign.primary : UIColor(hex: 0xE5EFFF)
|
||||
configuration.baseForegroundColor = foreground
|
||||
configuration.imageColorTransformer = UIConfigurationColorTransformer { _ in foreground }
|
||||
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
||||
var result = attributes
|
||||
result.font = .systemFont(ofSize: 17, weight: .semibold)
|
||||
result.foregroundColor = foreground
|
||||
return result
|
||||
}
|
||||
button.configuration = configuration
|
||||
}
|
||||
submitButton.accessibilityIdentifier = "drone.delivery.submit"
|
||||
submitButton.addTarget(self, action: #selector(submitTapped), for: .touchUpInside)
|
||||
view.addSubview(collectionView)
|
||||
view.addSubview(selectedVideoView)
|
||||
selectedVideoView.isHidden = true
|
||||
view.addSubview(footer)
|
||||
[stateLabel, progressView, submitButton].forEach(footer.addSubview)
|
||||
footerNote.numberOfLines = 0
|
||||
footerNote.textAlignment = .center
|
||||
[stateLabel, progressView, submitButton, footerNote].forEach(footer.addSubview)
|
||||
let divider = UIView()
|
||||
divider.backgroundColor = DroneDockDeliveryDesign.border
|
||||
footer.addSubview(divider)
|
||||
divider.snp.makeConstraints { make in make.top.leading.trailing.equalToSuperview(); make.height.equalTo(0.5) }
|
||||
configureDataSource()
|
||||
applySnapshot(animated: false)
|
||||
}
|
||||
@@ -114,19 +148,32 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
make.bottom.equalTo(selectedVideoView.snp.top)
|
||||
}
|
||||
selectedVideoView.snp.makeConstraints { make in
|
||||
make.leading.trailing.equalToSuperview().inset(18)
|
||||
make.leading.trailing.equalToSuperview().inset(20)
|
||||
selectedVideoBottom = make.bottom.equalTo(footer.snp.top).constraint
|
||||
selectedVideoHeight = make.height.equalTo(0).constraint
|
||||
}
|
||||
footer.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview() }
|
||||
stateLabel.snp.makeConstraints { make in make.top.equalToSuperview().offset(12); make.leading.trailing.equalToSuperview().inset(20) }
|
||||
progressView.snp.makeConstraints { make in make.top.equalTo(stateLabel.snp.bottom).offset(8); make.leading.trailing.equalTo(stateLabel); make.height.equalTo(3) }
|
||||
submitButton.snp.makeConstraints { make in
|
||||
make.top.equalTo(progressView.snp.bottom).offset(12)
|
||||
make.leading.trailing.equalToSuperview().inset(18)
|
||||
make.height.equalTo(44)
|
||||
make.bottom.equalTo(footer.safeAreaLayoutGuide).offset(-12)
|
||||
stateLabel.snp.makeConstraints { make in make.top.equalToSuperview().offset(10); make.leading.trailing.equalToSuperview().inset(20) }
|
||||
progressView.snp.makeConstraints { make in
|
||||
make.top.equalTo(stateLabel.snp.bottom).offset(4)
|
||||
make.leading.trailing.equalTo(stateLabel)
|
||||
progressHeight = make.height.equalTo(0).constraint
|
||||
}
|
||||
submitButton.snp.makeConstraints { make in
|
||||
make.top.equalTo(progressView.snp.bottom).offset(8)
|
||||
make.leading.trailing.equalToSuperview().inset(20)
|
||||
make.height.equalTo(52)
|
||||
}
|
||||
footerNote.snp.makeConstraints { make in
|
||||
make.top.equalTo(submitButton.snp.bottom).offset(8)
|
||||
make.leading.trailing.equalTo(submitButton)
|
||||
make.bottom.equalTo(footer.safeAreaLayoutGuide).offset(-8)
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
updateSelectedVideoLayout()
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
@@ -159,6 +206,18 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
private func configureDataSource() {
|
||||
dataSource = UICollectionViewDiffableDataSource<Section, Item>(collectionView: collectionView) { [weak self] list, path, item in
|
||||
guard let self else { return nil }
|
||||
if item == .order {
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "customer", for: path) as! DroneDockDeliveryCustomerCell
|
||||
let order = self.viewModel.detail?.order ?? self.viewModel.order
|
||||
cell.apply(title: order.touristTitle, orderNumber: order.orderNumber)
|
||||
return cell
|
||||
}
|
||||
if item == .intro { return list.dequeueReusableCell(withReuseIdentifier: "intro", for: path) }
|
||||
if item == .boundTask {
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "boundTask", for: path) as! DroneDockDeliveryBoundTaskCell
|
||||
cell.apply(task: self.viewModel.selectedTask)
|
||||
return cell
|
||||
}
|
||||
if case .point(let id) = item {
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "point", for: path) as! DroneMaterialFilterCell
|
||||
let title = self.viewModel.spots.first { $0.id == id }.map { Self.text($0.name, fallback: "点位 \(id)") } ?? "点位 \(id)"
|
||||
@@ -174,21 +233,8 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
|
||||
private func configureText(_ cell: DroneDockDeliveryTextCell, item: Item) {
|
||||
switch item {
|
||||
case .order:
|
||||
guard let order = viewModel.detail?.order else { return }
|
||||
cell.apply(title: order.touristTitle, body: "\(order.orderNumberText)\n\(order.packageTitle) · \(order.progressTitle)", id: "drone.delivery.order")
|
||||
case .choosePoint:
|
||||
cell.apply(title: "选择点位与拍摄任务", body: "每个拍摄任务可交付一个视频成片", id: "drone.delivery.chooseTask")
|
||||
case .boundTask:
|
||||
if let task = viewModel.selectedTask {
|
||||
let record = task.sequence.map { "记录\($0)" } ?? "当前拍摄任务"
|
||||
let film = task.film.map { "已有成片:\(Self.text($0.fileName, fallback: "视频成片"))\n上传新视频前会请你确认替换" } ?? "当前任务尚未交付成片"
|
||||
cell.apply(title: Self.text(task.spotName, fallback: "当前点位"),
|
||||
body: "\(record) · \(Self.text(task.airLineName, fallback: "航线待确认"))\n\(Self.text(task.createdAt, fallback: "时间待确认"))\n\(film)",
|
||||
id: "drone.delivery.boundTask.\(task.id)")
|
||||
} else {
|
||||
cell.apply(title: "原拍摄任务暂不可用", body: "请返回素材库刷新后,从对应任务重新进入", id: "drone.delivery.boundTask.unavailable")
|
||||
}
|
||||
case .task(let id):
|
||||
guard let task = viewModel.tasks.first(where: { $0.id == id }) else { return }
|
||||
let number = task.sequence.map(String.init) ?? String(task.id)
|
||||
@@ -209,7 +255,7 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
cell.apply(title: success, body: viewModel.refreshWarning ?? "成片已保存,可返回素材库查看", id: "drone.delivery.success")
|
||||
} else if !viewModel.canUpload {
|
||||
cell.apply(title: "当前订单暂不可上传成片", body: "请确认订单已付款且已有有效拍摄任务,刷新后重试", id: "drone.delivery.unavailable")
|
||||
} else { cell.apply(title: "上传说明", body: "每次选择一个视频成片,保存成功后游客可在小程序相册查看", id: "drone.delivery.hint") }
|
||||
} else { cell.apply(title: "上传说明", body: "选择一段本地视频,预览确认后再上传", id: "drone.delivery.hint") }
|
||||
default: break
|
||||
}
|
||||
}
|
||||
@@ -237,7 +283,7 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
let section = NSCollectionLayoutSection(group: group)
|
||||
section.contentInsets = .init(top: 0, leading: 16, bottom: 12, trailing: 16)
|
||||
section.contentInsets = .init(top: 0, leading: 20, bottom: 12, trailing: 20)
|
||||
section.orthogonalScrollingBehavior = .continuous
|
||||
return section
|
||||
}
|
||||
@@ -245,7 +291,7 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: points ? .fractionalHeight(1) : .estimated(100)))
|
||||
let group = NSCollectionLayoutGroup.vertical(layoutSize: size, subitems: [item])
|
||||
let section = NSCollectionLayoutSection(group: group)
|
||||
section.contentInsets = .init(top: 0, leading: 16, bottom: 12, trailing: 16)
|
||||
section.contentInsets = .init(top: 0, leading: 20, bottom: 12, trailing: 20)
|
||||
section.interGroupSpacing = 10
|
||||
if points { section.orthogonalScrollingBehavior = .continuous }
|
||||
return section
|
||||
@@ -255,9 +301,9 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
private func applySnapshot(animated: Bool) {
|
||||
guard dataSource != nil else { return }
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||
if viewModel.detail != nil && !isRefreshing {
|
||||
snapshot.appendSections([.order])
|
||||
snapshot.appendItems([.order], toSection: .order)
|
||||
snapshot.appendItems([.order, .intro], toSection: .order)
|
||||
if viewModel.detail != nil && !isRefreshing {
|
||||
if viewModel.isTaskScoped {
|
||||
snapshot.appendSections([.tasks])
|
||||
snapshot.appendItems([.boundTask], toSection: .tasks)
|
||||
@@ -270,8 +316,11 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
} else if viewModel.tasks.isEmpty { snapshot.appendItems([.emptyTasks], toSection: .tasks) }
|
||||
}
|
||||
}
|
||||
if isRefreshing || viewModel.isLoading || viewModel.loadErrorMessage != nil || pickerError != nil
|
||||
|| viewModel.submissionErrorMessage != nil || viewModel.successMessage != nil || !viewModel.canUpload {
|
||||
snapshot.appendSections([.state])
|
||||
snapshot.appendItems([.state], toSection: .state)
|
||||
}
|
||||
let previous = Set(dataSource.snapshot().itemIdentifiers)
|
||||
snapshot.reconfigureItems(snapshot.itemIdentifiers.filter { previous.contains($0) })
|
||||
collectionView.collectionViewLayout.invalidateLayout()
|
||||
@@ -288,26 +337,40 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
case .uploading: status = "正在上传视频 \(viewModel.progress)%"
|
||||
case .saving: status = "视频上传完成,正在保存成片…"
|
||||
case .succeeded: status = "成片交付成功"
|
||||
case .idle: status = isPicking ? "正在准备视频文件…" : viewModel.uploadedFileURL != nil ? "视频已上传,可重试保存成片" : viewModel.video != nil ? "已选择 1 个视频,点击下方按钮上传" : "请选择一个视频成片,选中后再上传"
|
||||
case .idle: status = isPicking ? "正在准备视频文件…" : viewModel.uploadedFileURL != nil ? "视频已上传,可重试保存成片" : viewModel.video != nil ? "已选择 1 个视频,预览确认后上传" : "请选择一个视频成片,选中后再上传"
|
||||
}
|
||||
stateLabel.text = status
|
||||
progressView.isHidden = !working
|
||||
progressHeight?.update(offset: working ? 3 : 0)
|
||||
progressView.progress = Float(viewModel.progress) / 100
|
||||
let title = viewModel.successMessage != nil ? "交付成功" : viewModel.video == nil ? "去相册选视频" : "上传所选视频"
|
||||
submitButton.setTitle(isPicking ? "正在准备视频…" : working ? "处理中…" : title, for: .normal)
|
||||
submitButton.configuration?.title = submitButton.title(for: .normal)
|
||||
submitButton.configuration?.image = UIImage(systemName: viewModel.video == nil ? "photo.on.rectangle" : "square.and.arrow.up")
|
||||
submitButton.configuration?.showsActivityIndicator = working || isPicking
|
||||
submitButton.isEnabled = (viewModel.video == nil ? viewModel.canChooseVideo : viewModel.canSubmit) && !locked
|
||||
submitButton.backgroundColor = submitButton.isEnabled ? UIColor(hex: 0x066BFF) : UIColor(hex: 0xE8F1FF)
|
||||
submitButton.setNeedsUpdateConfiguration()
|
||||
selectedVideoView.isHidden = viewModel.video == nil
|
||||
selectedVideoHeight?.update(offset: viewModel.video == nil ? 0 : 98)
|
||||
selectedVideoBottom?.update(offset: viewModel.video == nil ? 0 : -12)
|
||||
selectedVideoBottom?.update(offset: viewModel.video == nil ? 0 : -16)
|
||||
updateSelectedVideoLayout()
|
||||
selectedVideoView.apply(video: viewModel.video, enabled: viewModel.canChooseVideo && !locked,
|
||||
preview: { [weak self] in self?.previewVideo() },
|
||||
replace: { [weak self] in self?.chooseVideo(fromFiles: false) },
|
||||
remove: { [weak self] in self?.removeVideo() })
|
||||
navigationItem.rightBarButtonItems?.first { $0.accessibilityIdentifier == "drone.delivery.refresh" }?.isEnabled = !working && !isPicking && !isRefreshing
|
||||
collectionView.refreshControl?.isEnabled = !working && !isPicking && !isRefreshing
|
||||
navigationController?.interactivePopGestureRecognizer?.isEnabled = !working && !isStartingSubmission && !isPicking && (previousGestureEnabled ?? true)
|
||||
}
|
||||
|
||||
private func updateSelectedVideoLayout() {
|
||||
guard isViewLoaded else { return }
|
||||
let naturalHeight = max(1, view.bounds.width - 64) * 9 / 16 + 119
|
||||
let available = max(220, view.safeAreaLayoutGuide.layoutFrame.height * 0.44)
|
||||
let height = viewModel.video == nil ? 0 : min(naturalHeight, available)
|
||||
guard abs(displayedVideoHeight - height) > 0.5 else { return }
|
||||
displayedVideoHeight = height
|
||||
selectedVideoHeight?.update(offset: height)
|
||||
}
|
||||
|
||||
private func refresh() {
|
||||
guard !viewModel.isSubmitting, !isStartingSubmission, !isPicking else { collectionView.refreshControl?.endRefreshing(); return }
|
||||
operationTask?.cancel()
|
||||
@@ -434,7 +497,12 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
}
|
||||
|
||||
@objc private func closeSheetTapped() {
|
||||
requestExit { [weak self] in self?.onCloseSheet?() }
|
||||
requestExit { [weak self] in
|
||||
guard let self else { return }
|
||||
if let onCloseSheet = self.onCloseSheet { onCloseSheet() }
|
||||
else if (self.navigationController?.viewControllers.count ?? 0) > 1 { self.navigationController?.popViewController(animated: true) }
|
||||
else { self.dismiss(animated: true) }
|
||||
}
|
||||
}
|
||||
|
||||
private func requestExit(_ exit: @escaping () -> Void) {
|
||||
@@ -499,7 +567,7 @@ private final class DroneDockDeliveryTextCell: UICollectionViewCell {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
DroneDockStyle.applyCard(to: contentView)
|
||||
DroneDockDeliveryDesign.card(to: contentView, cornerRadius: 16)
|
||||
titleLabel.numberOfLines = 0
|
||||
detailLabel.numberOfLines = 0
|
||||
let stack = UIStackView(arrangedSubviews: [titleLabel, detailLabel, actionButton])
|
||||
|
||||
@@ -11,6 +11,7 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
var onClose: (() -> Void)?
|
||||
|
||||
private let customerTitle: String
|
||||
private let orderNumber: String?
|
||||
private let videoPicker: (@MainActor () async throws -> DroneDockDeliveryVideo?)?
|
||||
private var operationTask: Task<Void, Never>?
|
||||
private var metadataTask: Task<Void, Never>?
|
||||
@@ -26,12 +27,19 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
private var previousGestureEnabled: Bool?
|
||||
private let scrollView = UIScrollView()
|
||||
private let content = UIStackView()
|
||||
private let customerLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
|
||||
private let customerView = DroneDockDeliveryCustomerView()
|
||||
private let thumbnail = DroneDockDeliveryVideoThumbnailView()
|
||||
private let footerContent = UIStackView()
|
||||
private let statusDot = UIView()
|
||||
private let receiveTitle = DroneDockStyle.label("扫码接收视频", size: 25, weight: .bold)
|
||||
private let emptyCodeView = UIImageView(image: UIImage(systemName: "qrcode.viewfinder"))
|
||||
private let codeFrame = DroneDockNearbyQRCodeFrameView()
|
||||
private var primaryHeight: Constraint?
|
||||
private let fileLabel = DroneDockStyle.label("尚未选择视频", size: 16, weight: .semibold)
|
||||
private let fileDetailLabel = DroneDockStyle.label("选择一段已在本机的视频", size: 12, color: DroneDockStyle.secondary)
|
||||
private let chooseButton = UIButton(type: .system)
|
||||
private let previewButton = UIButton(type: .system)
|
||||
private let statusLabel = DroneDockStyle.label("准备闪传", size: 18, weight: .semibold)
|
||||
private let statusLabel = DroneDockStyle.label("准备闪传", size: 14, weight: .semibold)
|
||||
private let statusDetailLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
|
||||
private let qrContainer = UIView()
|
||||
private let qrView = UIImageView()
|
||||
@@ -41,12 +49,13 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
private let progressLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||||
private let footer = UIView()
|
||||
private let primaryButton = UIButton(type: .system)
|
||||
private let footerLabel = DroneDockStyle.label("无需互联网 · 请双方保持连接同一 Wi-Fi", size: 11, color: DroneDockStyle.secondary)
|
||||
private let footerLabel = DroneDockStyle.label("仅发送所选视频,无需上传云端", size: 12, color: DroneDockStyle.secondary)
|
||||
|
||||
/// 注入本地服务和测试视频选择器;默认使用禁止云端取片的本地相册选择器。
|
||||
init(customerTitle: String, viewModel: DroneDockNearbyTransferViewModel = DroneDockNearbyTransferViewModel(),
|
||||
init(customerTitle: String, orderNumber: String? = nil, viewModel: DroneDockNearbyTransferViewModel = DroneDockNearbyTransferViewModel(),
|
||||
videoPicker: (@MainActor () async throws -> DroneDockDeliveryVideo?)? = nil) {
|
||||
self.customerTitle = customerTitle
|
||||
self.orderNumber = orderNumber
|
||||
self.viewModel = viewModel
|
||||
self.videoPicker = videoPicker
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
@@ -67,81 +76,81 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "面对面闪传"
|
||||
let back = UIBarButtonItem(title: "交付方式", style: .plain, target: self, action: #selector(backTapped))
|
||||
let appearance = UINavigationBarAppearance()
|
||||
appearance.configureWithOpaqueBackground()
|
||||
appearance.backgroundColor = DroneDockDeliveryDesign.background
|
||||
appearance.shadowColor = .clear
|
||||
appearance.titleTextAttributes = [.foregroundColor: DroneDockDeliveryDesign.text,
|
||||
.font: UIFont.systemFont(ofSize: 19, weight: .semibold)]
|
||||
navigationItem.standardAppearance = appearance
|
||||
navigationItem.scrollEdgeAppearance = appearance
|
||||
navigationItem.compactAppearance = appearance
|
||||
let back = UIBarButtonItem(image: UIImage(systemName: "chevron.left"), style: .plain, target: self, action: #selector(backTapped))
|
||||
back.accessibilityLabel = "返回交付方式"
|
||||
back.tintColor = DroneDockDeliveryDesign.text
|
||||
back.accessibilityIdentifier = "drone.nearby.back"
|
||||
navigationItem.leftBarButtonItem = back
|
||||
let close = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .plain, target: self, action: #selector(closeTapped))
|
||||
close.tintColor = DroneDockDeliveryDesign.text
|
||||
close.accessibilityLabel = "关闭面对面闪传"
|
||||
close.accessibilityIdentifier = "drone.nearby.close"
|
||||
navigationItem.rightBarButtonItem = close
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = DroneDockStyle.background
|
||||
view.backgroundColor = DroneDockDeliveryDesign.background
|
||||
scrollView.alwaysBounceVertical = true
|
||||
scrollView.showsVerticalScrollIndicator = false
|
||||
scrollView.accessibilityIdentifier = "drone.nearby.content"
|
||||
content.axis = .vertical
|
||||
content.spacing = 14
|
||||
customerLabel.text = customerTitle
|
||||
customerLabel.numberOfLines = 0
|
||||
content.addArrangedSubview(customerLabel)
|
||||
let networkTitle = DroneDockStyle.label("1 连接同一 Wi-Fi", size: 15, weight: .semibold)
|
||||
let networkDetail = DroneDockStyle.label("请商家和游客连接同一 Wi-Fi。没有现场 Wi-Fi 时,可手动连接同一手机热点。", size: 13, color: DroneDockStyle.secondary)
|
||||
networkDetail.numberOfLines = 0
|
||||
content.addArrangedSubview(card([networkTitle, networkDetail]))
|
||||
let videoTitle = DroneDockStyle.label("2 选择本地视频", size: 15, weight: .semibold)
|
||||
fileLabel.numberOfLines = 2
|
||||
fileLabel.accessibilityIdentifier = "drone.nearby.fileName"
|
||||
fileDetailLabel.numberOfLines = 0
|
||||
fileDetailLabel.accessibilityIdentifier = "drone.nearby.fileDetail"
|
||||
chooseButton.setTitle("选择视频", for: .normal)
|
||||
chooseButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .semibold)
|
||||
chooseButton.accessibilityIdentifier = "drone.nearby.chooseVideo"
|
||||
previewButton.setTitle("预览", for: .normal)
|
||||
previewButton.setImage(UIImage(systemName: "play.circle"), for: .normal)
|
||||
previewButton.accessibilityIdentifier = "drone.nearby.preview"
|
||||
let videoActions = UIStackView(arrangedSubviews: [chooseButton, previewButton])
|
||||
videoActions.spacing = 18
|
||||
videoActions.distribution = .fillEqually
|
||||
videoActions.snp.makeConstraints { $0.height.equalTo(44) }
|
||||
content.addArrangedSubview(card([videoTitle, fileLabel, fileDetailLabel, videoActions]))
|
||||
let sessionTitle = DroneDockStyle.label("3 游客扫码接收", size: 15, weight: .semibold)
|
||||
statusLabel.textColor = DroneDockStyle.primary
|
||||
statusLabel.accessibilityIdentifier = "drone.nearby.status"
|
||||
statusDetailLabel.numberOfLines = 0
|
||||
statusDetailLabel.accessibilityIdentifier = "drone.nearby.statusDetail"
|
||||
qrView.contentMode = .scaleAspectFit
|
||||
qrView.accessibilityIdentifier = "drone.nearby.qr"
|
||||
qrView.isAccessibilityElement = true
|
||||
qrView.accessibilityLabel = "请游客用系统相机扫描此二维码"
|
||||
qrContainer.addSubview(qrView)
|
||||
qrContainer.snp.makeConstraints { $0.height.equalTo(212) }
|
||||
qrView.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(204) }
|
||||
addressButton.titleLabel?.font = .monospacedSystemFont(ofSize: 11, weight: .regular)
|
||||
addressButton.titleLabel?.numberOfLines = 2
|
||||
addressButton.accessibilityIdentifier = "drone.nearby.copyAddress"
|
||||
addressButton.setTitle("复制接收地址", for: .normal)
|
||||
addressButton.snp.makeConstraints { $0.height.greaterThanOrEqualTo(44) }
|
||||
expiryLabel.textAlignment = .center
|
||||
expiryLabel.numberOfLines = 0
|
||||
expiryLabel.accessibilityIdentifier = "drone.nearby.expiry"
|
||||
progressView.progressTintColor = DroneDockStyle.primary
|
||||
progressView.accessibilityIdentifier = "drone.nearby.progress"
|
||||
progressLabel.textAlignment = .center
|
||||
progressLabel.accessibilityIdentifier = "drone.nearby.progressText"
|
||||
content.addArrangedSubview(card([sessionTitle, statusLabel, statusDetailLabel, qrContainer, addressButton, expiryLabel, progressView, progressLabel]))
|
||||
content.spacing = 10
|
||||
customerView.apply(title: customerTitle, orderNumber: orderNumber)
|
||||
customerView.accessibilityIdentifier = "drone.nearby.customer"
|
||||
DroneDockDeliveryDesign.card(to: customerView)
|
||||
content.addArrangedSubview(customerView)
|
||||
content.addArrangedSubview(makeNetworkHint())
|
||||
content.addArrangedSubview(makeVideoCard())
|
||||
content.addArrangedSubview(makeReceiveCard())
|
||||
|
||||
footer.backgroundColor = .white
|
||||
footer.accessibilityIdentifier = "drone.nearby.footer"
|
||||
let separator = UIView()
|
||||
separator.backgroundColor = DroneDockDeliveryDesign.border
|
||||
footer.addSubview(separator)
|
||||
separator.snp.makeConstraints { make in make.top.leading.trailing.equalToSuperview(); make.height.equalTo(0.5) }
|
||||
footerContent.axis = .vertical
|
||||
footerContent.spacing = 6
|
||||
footer.addSubview(footerContent)
|
||||
[addressButton, primaryButton, footerLabel].forEach(footerContent.addArrangedSubview)
|
||||
var configuration = UIButton.Configuration.filled()
|
||||
configuration.title = "复制接收地址"
|
||||
configuration.image = UIImage(systemName: "link")
|
||||
configuration.imagePadding = 8
|
||||
configuration.preferredSymbolConfigurationForImage = .init(pointSize: 20, weight: .medium)
|
||||
configuration.baseForegroundColor = .white
|
||||
configuration.background.backgroundColor = DroneDockDeliveryDesign.primary
|
||||
configuration.background.cornerRadius = 12
|
||||
configuration.cornerStyle = .fixed
|
||||
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
||||
var result = attributes
|
||||
result.font = .systemFont(ofSize: 17, weight: .semibold)
|
||||
return result
|
||||
}
|
||||
addressButton.configuration = configuration
|
||||
addressButton.accessibilityIdentifier = "drone.nearby.copyAddress"
|
||||
addressButton.snp.makeConstraints { $0.height.equalTo(48).priority(999) }
|
||||
primaryButton.layer.cornerRadius = 12
|
||||
primaryButton.titleLabel?.font = .systemFont(ofSize: 16, weight: .semibold)
|
||||
primaryButton.setTitleColor(.white, for: .normal)
|
||||
primaryButton.setTitleColor(DroneDockStyle.secondary, for: .disabled)
|
||||
primaryButton.setTitleColor(DroneDockDeliveryDesign.secondary, for: .disabled)
|
||||
primaryButton.accessibilityIdentifier = "drone.nearby.primary"
|
||||
primaryButton.snp.makeConstraints { primaryHeight = $0.height.equalTo(48).constraint }
|
||||
footerLabel.textAlignment = .center
|
||||
footerLabel.numberOfLines = 0
|
||||
footerLabel.textColor = DroneDockDeliveryDesign.secondary
|
||||
view.addSubview(scrollView)
|
||||
scrollView.addSubview(content)
|
||||
view.addSubview(footer)
|
||||
[primaryButton, footerLabel].forEach(footer.addSubview)
|
||||
render()
|
||||
}
|
||||
|
||||
@@ -152,20 +161,134 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
make.bottom.equalTo(footer.snp.top)
|
||||
}
|
||||
content.snp.makeConstraints { make in
|
||||
make.edges.equalTo(scrollView.contentLayoutGuide).inset(16)
|
||||
make.width.equalTo(scrollView.frameLayoutGuide).offset(-32)
|
||||
make.edges.equalTo(scrollView.contentLayoutGuide).inset(UIEdgeInsets(top: 12, left: 20, bottom: 12, right: 20))
|
||||
make.width.equalTo(scrollView.frameLayoutGuide).offset(-40)
|
||||
}
|
||||
footer.snp.makeConstraints { $0.leading.trailing.bottom.equalToSuperview() }
|
||||
primaryButton.snp.makeConstraints { make in
|
||||
footerContent.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(12)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
make.height.equalTo(48)
|
||||
make.leading.trailing.equalToSuperview().inset(20)
|
||||
make.bottom.equalTo(footer.safeAreaLayoutGuide).offset(-8)
|
||||
}
|
||||
footerLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(primaryButton.snp.bottom).offset(9)
|
||||
make.leading.trailing.equalTo(primaryButton)
|
||||
make.bottom.equalTo(footer.safeAreaLayoutGuide).offset(-10)
|
||||
}
|
||||
|
||||
private func makeNetworkHint() -> UIView {
|
||||
let hint = UIView()
|
||||
hint.backgroundColor = DroneDockDeliveryDesign.primary.withAlphaComponent(0.08)
|
||||
hint.layer.cornerRadius = 14
|
||||
hint.accessibilityIdentifier = "drone.nearby.networkHint"
|
||||
let icon = UIImageView(image: UIImage(systemName: "wifi"))
|
||||
icon.tintColor = DroneDockDeliveryDesign.primary
|
||||
icon.contentMode = .scaleAspectFit
|
||||
let divider = UIView()
|
||||
divider.backgroundColor = DroneDockDeliveryDesign.primary.withAlphaComponent(0.16)
|
||||
let title = DroneDockStyle.label("双方连接同一 Wi-Fi 或手机热点", size: 14, weight: .semibold,
|
||||
color: DroneDockDeliveryDesign.text)
|
||||
title.numberOfLines = 0
|
||||
let detail = DroneDockStyle.label("无需互联网,传输时请保持本页亮屏", size: 12, color: DroneDockDeliveryDesign.secondary)
|
||||
detail.numberOfLines = 0
|
||||
let labels = UIStackView(arrangedSubviews: [title, detail])
|
||||
labels.axis = .vertical
|
||||
labels.spacing = 4
|
||||
[icon, divider, labels].forEach(hint.addSubview)
|
||||
icon.snp.makeConstraints { make in make.leading.equalToSuperview().offset(16); make.centerY.equalToSuperview(); make.size.equalTo(30) }
|
||||
divider.snp.makeConstraints { make in make.leading.equalTo(icon.snp.trailing).offset(12); make.centerY.equalToSuperview(); make.width.equalTo(1); make.height.equalTo(34) }
|
||||
labels.snp.makeConstraints { make in
|
||||
make.leading.equalTo(divider.snp.trailing).offset(12)
|
||||
make.trailing.equalToSuperview().inset(14)
|
||||
make.top.bottom.equalToSuperview().inset(10)
|
||||
}
|
||||
return hint
|
||||
}
|
||||
|
||||
private func makeVideoCard() -> UIView {
|
||||
let title = DroneDockStyle.label("本次发送", size: 16, weight: .semibold, color: DroneDockDeliveryDesign.text)
|
||||
chooseButton.setTitle("选择视频", for: .normal)
|
||||
chooseButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .semibold)
|
||||
chooseButton.tintColor = DroneDockDeliveryDesign.primary
|
||||
chooseButton.accessibilityIdentifier = "drone.nearby.chooseVideo"
|
||||
chooseButton.snp.makeConstraints { make in make.height.equalTo(44); make.width.greaterThanOrEqualTo(72).priority(999) }
|
||||
let heading = UIStackView(arrangedSubviews: [title, UIView(), chooseButton])
|
||||
heading.alignment = .center
|
||||
heading.spacing = 6
|
||||
fileLabel.numberOfLines = 2
|
||||
fileLabel.textColor = DroneDockDeliveryDesign.text
|
||||
fileLabel.accessibilityIdentifier = "drone.nearby.fileName"
|
||||
fileDetailLabel.numberOfLines = 0
|
||||
fileDetailLabel.textColor = DroneDockDeliveryDesign.secondary
|
||||
fileDetailLabel.accessibilityIdentifier = "drone.nearby.fileDetail"
|
||||
let labels = UIStackView(arrangedSubviews: [fileLabel, fileDetailLabel])
|
||||
labels.axis = .vertical
|
||||
labels.spacing = 5
|
||||
let video = UIView()
|
||||
thumbnail.accessibilityIdentifier = "drone.nearby.videoThumbnail"
|
||||
video.addSubview(thumbnail)
|
||||
video.addSubview(labels)
|
||||
previewButton.setImage(UIImage(systemName: "play.circle.fill"), for: .normal)
|
||||
previewButton.tintColor = .white
|
||||
previewButton.setPreferredSymbolConfiguration(.init(pointSize: 28), forImageIn: .normal)
|
||||
previewButton.accessibilityLabel = "预览本次发送的视频"
|
||||
previewButton.accessibilityIdentifier = "drone.nearby.preview"
|
||||
video.addSubview(previewButton)
|
||||
thumbnail.snp.makeConstraints { make in make.leading.top.bottom.equalToSuperview(); make.width.equalTo(104); make.height.equalTo(62) }
|
||||
previewButton.snp.makeConstraints { $0.edges.equalTo(thumbnail) }
|
||||
labels.snp.makeConstraints { make in
|
||||
make.leading.equalTo(thumbnail.snp.trailing).offset(12)
|
||||
make.trailing.equalToSuperview()
|
||||
make.centerY.equalTo(thumbnail)
|
||||
make.top.greaterThanOrEqualToSuperview()
|
||||
make.bottom.lessThanOrEqualToSuperview()
|
||||
}
|
||||
let result = card([heading, video], spacing: 8)
|
||||
result.accessibilityIdentifier = "drone.nearby.videoCard"
|
||||
return result
|
||||
}
|
||||
|
||||
private func makeReceiveCard() -> UIView {
|
||||
statusDot.backgroundColor = DroneDockDeliveryDesign.primary
|
||||
statusDot.layer.cornerRadius = 4
|
||||
statusDot.snp.makeConstraints { $0.size.equalTo(8) }
|
||||
statusLabel.textColor = DroneDockDeliveryDesign.secondary
|
||||
statusLabel.numberOfLines = 0
|
||||
statusLabel.accessibilityIdentifier = "drone.nearby.status"
|
||||
let status = UIStackView(arrangedSubviews: [statusDot, statusLabel])
|
||||
status.spacing = 8
|
||||
status.alignment = .center
|
||||
let statusRow = UIView()
|
||||
statusRow.addSubview(status)
|
||||
status.snp.makeConstraints { make in make.centerX.top.bottom.equalToSuperview(); make.leading.greaterThanOrEqualToSuperview(); make.trailing.lessThanOrEqualToSuperview() }
|
||||
receiveTitle.textColor = DroneDockDeliveryDesign.text
|
||||
receiveTitle.textAlignment = .center
|
||||
receiveTitle.accessibilityIdentifier = "drone.nearby.receiveTitle"
|
||||
statusDetailLabel.numberOfLines = 0
|
||||
statusDetailLabel.textAlignment = .center
|
||||
statusDetailLabel.textColor = DroneDockDeliveryDesign.secondary
|
||||
statusDetailLabel.accessibilityIdentifier = "drone.nearby.statusDetail"
|
||||
qrView.contentMode = .scaleAspectFit
|
||||
qrView.accessibilityIdentifier = "drone.nearby.qr"
|
||||
qrView.isAccessibilityElement = true
|
||||
qrView.accessibilityLabel = "请游客用系统相机扫描此二维码"
|
||||
qrContainer.addSubview(codeFrame)
|
||||
qrContainer.addSubview(qrView)
|
||||
qrContainer.snp.makeConstraints { $0.height.equalTo(220).priority(999) }
|
||||
codeFrame.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(220) }
|
||||
qrView.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalTo(196) }
|
||||
emptyCodeView.contentMode = .scaleAspectFit
|
||||
emptyCodeView.tintColor = DroneDockDeliveryDesign.primary.withAlphaComponent(0.4)
|
||||
emptyCodeView.snp.makeConstraints { $0.height.equalTo(72).priority(999) }
|
||||
emptyCodeView.accessibilityIdentifier = "drone.nearby.emptyCode"
|
||||
expiryLabel.textAlignment = .center
|
||||
expiryLabel.font = .systemFont(ofSize: 13)
|
||||
expiryLabel.textColor = DroneDockDeliveryDesign.secondary
|
||||
expiryLabel.numberOfLines = 0
|
||||
expiryLabel.accessibilityIdentifier = "drone.nearby.expiry"
|
||||
progressView.progressTintColor = DroneDockDeliveryDesign.primary
|
||||
progressView.accessibilityIdentifier = "drone.nearby.progress"
|
||||
progressLabel.textAlignment = .center
|
||||
progressLabel.accessibilityIdentifier = "drone.nearby.progressText"
|
||||
let result = card([statusRow, receiveTitle, statusDetailLabel, emptyCodeView, qrContainer, expiryLabel, progressView, progressLabel], spacing: 8)
|
||||
result.accessibilityIdentifier = "drone.nearby.receiveCard"
|
||||
return result
|
||||
}
|
||||
|
||||
override func bindActions() {
|
||||
@@ -221,20 +344,19 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
revealedSessionID = sessionID
|
||||
// 只在新接收码生成后定位一次;下载进度和游客连接事件不抢走用户的滚动位置。
|
||||
let target = qrContainer.convert(qrContainer.bounds, to: scrollView)
|
||||
.union(addressButton.convert(addressButton.bounds, to: scrollView))
|
||||
.union(expiryLabel.convert(expiryLabel.bounds, to: scrollView))
|
||||
.insetBy(dx: 0, dy: -8)
|
||||
scrollView.scrollRectToVisible(target, animated: !UIAccessibility.isReduceMotionEnabled)
|
||||
}
|
||||
|
||||
private func card(_ views: [UIView]) -> UIView {
|
||||
private func card(_ views: [UIView], spacing: CGFloat = 10) -> UIView {
|
||||
let container = UIView()
|
||||
DroneDockStyle.applyCard(to: container)
|
||||
DroneDockDeliveryDesign.card(to: container)
|
||||
let stack = UIStackView(arrangedSubviews: views)
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 10
|
||||
stack.spacing = spacing
|
||||
container.addSubview(stack)
|
||||
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(16) }
|
||||
stack.snp.makeConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)) }
|
||||
return container
|
||||
}
|
||||
|
||||
@@ -251,8 +373,10 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
previousGestureEnabled = nil
|
||||
}
|
||||
chooseButton.isEnabled = state.canChooseVideo && !isPicking
|
||||
chooseButton.setTitle(isPicking ? "正在准备视频…" : state.video == nil ? "选择视频" : "重新选择", for: .normal)
|
||||
previewButton.isHidden = state.video == nil
|
||||
chooseButton.isHidden = state.isActive
|
||||
chooseButton.setTitle(isPicking ? "正在准备视频…" : state.video == nil ? "选择视频" : "更换", for: .normal)
|
||||
previewButton.isHidden = state.video == nil || state.isActive
|
||||
thumbnail.apply(video: state.video)
|
||||
previewButton.isEnabled = !isPicking && !state.isActive
|
||||
fileLabel.text = state.video?.fileName ?? "尚未选择视频"
|
||||
if let video = state.video {
|
||||
@@ -270,7 +394,7 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
statusDetailLabel.text = "请保持本页打开,正在检查本地连接。"
|
||||
case .waiting:
|
||||
statusLabel.text = "等待游客扫码"
|
||||
statusDetailLabel.text = "请游客先连接同一 Wi-Fi,再用系统相机扫码。传输期间请保持本页亮屏。"
|
||||
statusDetailLabel.text = "使用系统相机扫码,在浏览器中下载"
|
||||
case .connected:
|
||||
statusLabel.text = "游客已打开接收页"
|
||||
statusDetailLabel.text = state.message ?? "请游客点击“下载视频”开始接收。"
|
||||
@@ -291,10 +415,15 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
statusDetailLabel.text = state.message
|
||||
}
|
||||
}
|
||||
statusLabel.textColor = state.phase == .sent ? DroneDockStyle.success : state.phase == .failed || state.phase == .interrupted || pickerError != nil ? DroneDockStyle.warning : DroneDockStyle.primary
|
||||
let tone = state.phase == .sent ? DroneDockStyle.success : state.phase == .failed || state.phase == .interrupted || pickerError != nil ? DroneDockStyle.warning : DroneDockDeliveryDesign.primary
|
||||
statusDot.backgroundColor = tone
|
||||
statusLabel.textColor = state.phase == .failed || state.phase == .interrupted || pickerError != nil ? tone : DroneDockDeliveryDesign.secondary
|
||||
let receiveURL = state.session?.url
|
||||
qrContainer.isHidden = receiveURL == nil
|
||||
emptyCodeView.isHidden = receiveURL != nil
|
||||
receiveTitle.text = receiveURL != nil ? "扫码接收视频" : "面对面,轻松接收"
|
||||
addressButton.isHidden = receiveURL == nil
|
||||
addressButton.isEnabled = receiveURL != nil
|
||||
expiryLabel.isHidden = receiveURL == nil
|
||||
if let receiveURL {
|
||||
if qrView.accessibilityValue != receiveURL.absoluteString {
|
||||
@@ -317,7 +446,10 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
progressLabel.text = "已发送 \(ByteCountFormatter.string(fromByteCount: state.bytesSent, countStyle: .file)) / \(ByteCountFormatter.string(fromByteCount: state.totalBytes, countStyle: .file))"
|
||||
primaryButton.setTitle(state.isActive ? "结束闪传" : state.phase == .ended || state.phase == .failed ? "重新生成接收码" : "生成接收二维码", for: .normal)
|
||||
primaryButton.isEnabled = !isPicking && (state.isActive || state.canStart)
|
||||
primaryButton.backgroundColor = primaryButton.isEnabled ? DroneDockStyle.primary : DroneDockStyle.border
|
||||
primaryButton.setTitleColor(state.isActive ? .systemRed : .white, for: .normal)
|
||||
primaryButton.backgroundColor = state.isActive ? .clear : primaryButton.isEnabled ? DroneDockDeliveryDesign.primary : DroneDockDeliveryDesign.border
|
||||
primaryHeight?.update(offset: state.isActive ? 44 : 48)
|
||||
footerLabel.isHidden = state.isActive
|
||||
if let sessionID = state.session?.id, sessionID != revealedSessionID {
|
||||
pendingRevealSessionID = sessionID
|
||||
} else if state.session == nil { pendingRevealSessionID = nil }
|
||||
@@ -462,3 +594,41 @@ final class DroneDockNearbyTransferViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 二维码外围的蓝色取景角,不覆盖二维码或改变扫码内容。
|
||||
@MainActor
|
||||
private final class DroneDockNearbyQRCodeFrameView: UIView {
|
||||
private let corners = CAShapeLayer()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
isUserInteractionEnabled = false
|
||||
corners.fillColor = UIColor.clear.cgColor
|
||||
corners.strokeColor = DroneDockDeliveryDesign.primary.cgColor
|
||||
corners.lineWidth = 3
|
||||
corners.lineCap = .round
|
||||
layer.addSublayer(corners)
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
corners.frame = bounds
|
||||
let path = UIBezierPath()
|
||||
let length: CGFloat = 23
|
||||
let radius: CGFloat = 10
|
||||
let inset: CGFloat = 2
|
||||
for (x, y, horizontal, vertical) in [(inset, inset, CGFloat(1), CGFloat(1)),
|
||||
(bounds.width - inset, inset, -1, 1),
|
||||
(inset, bounds.height - inset, 1, -1),
|
||||
(bounds.width - inset, bounds.height - inset, -1, -1)] {
|
||||
path.move(to: CGPoint(x: x, y: y + vertical * length))
|
||||
path.addLine(to: CGPoint(x: x, y: y + vertical * radius))
|
||||
path.addQuadCurve(to: CGPoint(x: x + horizontal * radius, y: y), controlPoint: CGPoint(x: x, y: y))
|
||||
path.addLine(to: CGPoint(x: x + horizontal * length, y: y))
|
||||
}
|
||||
corners.path = path.cgPath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import UIKit
|
||||
import XCTest
|
||||
@testable import suixinkan
|
||||
|
||||
/// 两种交付入口共享的摘要与真实本地封面,不访问网络或初始化 RTC。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryDesignTests: XCTestCase {
|
||||
/// 长游客标题随卡片增高,订单仅展示原号码末四位,不挤压或截断标题。
|
||||
func testLongCustomerTitleWrapsAndKeepsRealOrderSuffixVisible() throws {
|
||||
let view = DroneDockDeliveryCustomerView(showsCard: true)
|
||||
let title = "游客 南京牛首山佛顶塔观景平台来自同一旅行团队的亲友共同拍摄成片接收人"
|
||||
view.apply(title: title, orderNumber: " 261105175018 \n")
|
||||
layout(view, width: 320)
|
||||
let name = try label(view, "drone.delivery.customer.title")
|
||||
let order = try label(view, "drone.delivery.customer.order")
|
||||
XCTAssertEqual(name.text, title)
|
||||
XCTAssertEqual(name.numberOfLines, 0)
|
||||
XCTAssertGreaterThan(name.bounds.height, name.font.lineHeight)
|
||||
XCTAssertGreaterThanOrEqual(name.bounds.height + 1, name.sizeThatFits(CGSize(width: name.bounds.width, height: .greatestFiniteMagnitude)).height)
|
||||
XCTAssertEqual(order.text, "订单尾号 5018")
|
||||
XCTAssertFalse(order.isHidden)
|
||||
XCTAssertTrue(view.bounds.contains(name.convert(name.bounds, to: view)))
|
||||
XCTAssertTrue(view.bounds.contains(order.convert(order.bounds, to: view)))
|
||||
XCTAssertFalse(view.hasAmbiguousLayout)
|
||||
}
|
||||
|
||||
/// 透明摘要与外部卡片齐边;切换为缺失订单后隐藏原尾号,没有占位假号码。
|
||||
func testTransparentCustomerHidesMissingOrderAndUsesNoHorizontalInset() throws {
|
||||
let view = DroneDockDeliveryCustomerView(showsCard: false)
|
||||
view.apply(title: "游客 132****9413", orderNumber: "123")
|
||||
let order = try label(view, "drone.delivery.customer.order")
|
||||
XCTAssertEqual(order.text, "订单尾号 123", "短订单号只展示实际内容,不补零")
|
||||
for value: String? in [nil, "", " \n "] {
|
||||
view.apply(title: "游客 132****9413", orderNumber: value)
|
||||
layout(view, width: 320)
|
||||
XCTAssertTrue(order.isHidden)
|
||||
XCTAssertNil(order.text)
|
||||
}
|
||||
XCTAssertEqual(view.backgroundColor, .clear)
|
||||
XCTAssertEqual(view.layer.borderWidth, 0)
|
||||
let name = try label(view, "drone.delivery.customer.title")
|
||||
XCTAssertEqual(name.convert(.zero, to: view).x, 60, accuracy: 0.5, "48 点头像与 12 点间距,不重复增加外层内边距")
|
||||
XCTAssertEqual(view.bounds.height, 64, accuracy: 0.5)
|
||||
}
|
||||
|
||||
/// 封面必须来自本地视频;同一选择不重新生成,更换/移除立即清除且迟到结果不恢复旧图。
|
||||
func testBundledVideoThumbnailDeduplicatesAndRemovalDiscardsLateImage() async throws {
|
||||
let source = try XCTUnwrap(Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4")
|
||||
?? Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4", subdirectory: "DroneDock"))
|
||||
let size = try XCTUnwrap(source.resourceValues(forKeys: [.fileSizeKey]).fileSize)
|
||||
let video = DroneDockDeliveryVideo(url: source, fileName: source.lastPathComponent, fileSize: size)
|
||||
let view = DroneDockDeliveryVideoThumbnailView(frame: CGRect(x: 0, y: 0, width: 320, height: 180))
|
||||
let image = try imageView(view, "drone.delivery.thumbnail.image")
|
||||
let placeholder = try imageView(view, "drone.delivery.thumbnail.placeholder")
|
||||
XCTAssertNil(image.image)
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
view.apply(video: video)
|
||||
try await waitForImage(image)
|
||||
let firstImage = try XCTUnwrap(image.image)
|
||||
XCTAssertNotNil(firstImage.cgImage, "必须为实际视频帧,而不是系统符号或演示封面")
|
||||
XCTAssertTrue(placeholder.isHidden)
|
||||
for _ in 0..<3 { view.apply(video: video) }
|
||||
XCTAssertTrue(image.image === firstImage)
|
||||
let nextSelection = DroneDockDeliveryVideo(url: source, fileName: "另一选择.mp4", fileSize: size)
|
||||
view.apply(video: nextSelection)
|
||||
XCTAssertNil(image.image)
|
||||
view.apply(video: nil)
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
XCTAssertNil(image.image, "已取消的首帧不能覆盖移除后的空状态")
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
XCTAssertEqual(view.accessibilityLabel, "未选择视频")
|
||||
view.apply(video: nextSelection)
|
||||
try await waitForImage(image)
|
||||
XCTAssertTrue(placeholder.isHidden, "取消后重新选择仍可正常生成")
|
||||
view.apply(video: nil)
|
||||
XCTAssertNil(image.image)
|
||||
}
|
||||
|
||||
/// 非文件 URL 被直接拒绝,本地无视频内容也只展示中性占位,不以示例图替代。
|
||||
func testRemoteAndInvalidVideoKeepNeutralPlaceholder() async throws {
|
||||
let view = DroneDockDeliveryVideoThumbnailView(frame: .zero)
|
||||
let image = try imageView(view, "drone.delivery.thumbnail.image")
|
||||
let placeholder = try imageView(view, "drone.delivery.thumbnail.placeholder")
|
||||
view.apply(video: .init(url: try XCTUnwrap(URL(string: "https://invalid.test/not-requested.mp4")), fileName: "remote.mp4", fileSize: 100))
|
||||
XCTAssertNil(image.image)
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("\(UUID().uuidString).mp4")
|
||||
try Data("not a video".utf8).write(to: url)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
view.apply(video: .init(url: url, fileName: "invalid.mp4", fileSize: 11))
|
||||
try await Task.sleep(for: .milliseconds(200))
|
||||
XCTAssertNil(image.image)
|
||||
XCTAssertFalse(placeholder.isHidden)
|
||||
XCTAssertEqual(view.accessibilityLabel, "视频封面暂不可用")
|
||||
view.apply(video: nil)
|
||||
}
|
||||
|
||||
private func layout(_ view: UIView, width: CGFloat) {
|
||||
let size = view.systemLayoutSizeFitting(CGSize(width: width, height: UIView.layoutFittingCompressedSize.height),
|
||||
withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||
view.frame = CGRect(origin: .zero, size: CGSize(width: width, height: size.height))
|
||||
view.layoutIfNeeded()
|
||||
}
|
||||
|
||||
private func label(_ view: UIView, _ id: String) throws -> UILabel {
|
||||
try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == id } as? UILabel)
|
||||
}
|
||||
|
||||
private func imageView(_ view: UIView, _ id: String) throws -> UIImageView {
|
||||
try XCTUnwrap(descendants(view).first { $0.accessibilityIdentifier == id } as? UIImageView)
|
||||
}
|
||||
|
||||
private func descendants(_ view: UIView) -> [UIView] { [view] + view.subviews.flatMap(descendants) }
|
||||
|
||||
private func waitForImage(_ view: UIImageView, file: StaticString = #filePath, line: UInt = #line) async throws {
|
||||
for _ in 0..<300 {
|
||||
if view.image?.cgImage != nil { return }
|
||||
try await Task.sleep(for: .milliseconds(10))
|
||||
}
|
||||
XCTFail("本地测试视频未生成真实封面", file: file, line: line)
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,9 @@ final class DroneDockDeliveryViewTests: XCTestCase {
|
||||
try button(controller.view, "drone.delivery.submit").sendActions(for: .touchUpInside)
|
||||
try await settle(window) { controller.viewModel.phase == .uploading }
|
||||
let closeItem = try XCTUnwrap(controller.navigationItem.rightBarButtonItems?.first { $0.accessibilityIdentifier == "drone.delivery.sheet.close" })
|
||||
let refreshItem = try XCTUnwrap(controller.navigationItem.rightBarButtonItems?.first { $0.accessibilityIdentifier == "drone.delivery.refresh" })
|
||||
XCTAssertTrue(closeItem.isEnabled)
|
||||
XCTAssertFalse(refreshItem.isEnabled)
|
||||
XCTAssertNil(controller.navigationItem.rightBarButtonItems?.first { $0.accessibilityIdentifier == "drone.delivery.refresh" })
|
||||
XCTAssertFalse(try collection(controller).refreshControl?.isEnabled == true)
|
||||
UIApplication.shared.sendAction(try XCTUnwrap(closeItem.action), to: closeItem.target, from: closeItem, for: nil)
|
||||
try await settle(window) { controller.presentedViewController is UIAlertController && controller.presentedViewController?.transitionCoordinator == nil }
|
||||
let alert = try XCTUnwrap(controller.presentedViewController as? UIAlertController)
|
||||
@@ -146,6 +146,9 @@ final class DroneDockDeliveryViewTests: XCTestCase {
|
||||
defer { close(window) }
|
||||
try await settle(window) { controller.viewModel.selectedTaskID == 1 && !controller.viewModel.isLoading }
|
||||
XCTAssertNotNil(find(controller.view, "drone.delivery.boundTask.1"))
|
||||
XCTAssertTrue(texts(controller.view).contains("交付你的精彩成片"))
|
||||
XCTAssertTrue(texts(controller.view).contains("当前拍摄任务"))
|
||||
XCTAssertTrue(texts(controller.view).contains("已关联"))
|
||||
XCTAssertNil(find(controller.view, "drone.delivery.chooseTask"))
|
||||
XCTAssertNil(find(controller.view, "drone.delivery.point.201"))
|
||||
XCTAssertNil(find(controller.view, "drone.delivery.task.1"))
|
||||
@@ -161,6 +164,12 @@ final class DroneDockDeliveryViewTests: XCTestCase {
|
||||
XCTAssertEqual(controller.viewModel.selectedSpotID, 201)
|
||||
XCTAssertEqual(action.title(for: .normal), "上传所选视频")
|
||||
XCTAssertNotNil(find(controller.view, "drone.delivery.selectedVideo"))
|
||||
let cover = try XCTUnwrap(find(controller.view, "drone.delivery.selectedVideo.cover"))
|
||||
XCTAssertGreaterThan(cover.bounds.width, 200)
|
||||
XCTAssertGreaterThan(cover.bounds.height, 120)
|
||||
XCTAssertTrue(texts(controller.view).contains("已选视频"))
|
||||
XCTAssertTrue(texts(controller.view).contains("重新选择"))
|
||||
XCTAssertTrue(texts(controller.view).contains("移除"))
|
||||
assertVisibleAndHittable(try button(controller.view, "drone.delivery.preview"), in: window)
|
||||
assertVisibleAndHittable(try button(controller.view, "drone.delivery.chooseVideo"), in: window)
|
||||
XCTAssertEqual(fixture.uploader.count, 0)
|
||||
@@ -168,6 +177,37 @@ final class DroneDockDeliveryViewTests: XCTestCase {
|
||||
capture(window, "云端上传-绑定任务直接选择并预览")
|
||||
}
|
||||
|
||||
/// 窄屏顶部任务信息可以滚动,视频预览与底部上传操作始终留在屏幕内。
|
||||
func testSmallScreenKeepsSelectedVideoAndFooterActionsVisibleWhileTaskScrolls() async throws {
|
||||
let fixture = try DeliveryUIFixture()
|
||||
let pointName = "佛顶塔七楼西南角通往观景平台的超长拍摄打卡点"
|
||||
fixture.service.records[0]["scenic_spot_name"] = pointName
|
||||
let controller = fixture.controller(initialTaskID: 1)
|
||||
let window = show(controller, size: CGSize(width: 375, height: 667))
|
||||
defer { close(window) }
|
||||
try await settle(window) { controller.viewModel.selectedTaskID == 1 && !controller.viewModel.isLoading }
|
||||
let point = try XCTUnwrap(find(controller.view, "drone.delivery.boundTask.title") as? UILabel)
|
||||
XCTAssertEqual(point.text, pointName)
|
||||
XCTAssertEqual(point.numberOfLines, 0)
|
||||
XCTAssertGreaterThan(point.bounds.height, point.font.lineHeight * 1.5)
|
||||
XCTAssertLessThanOrEqual(point.sizeThatFits(CGSize(width: point.bounds.width, height: .greatestFiniteMagnitude)).height, point.bounds.height + 1)
|
||||
try await chooseVideo(controller, window: window)
|
||||
let list = try collection(controller)
|
||||
let card = try XCTUnwrap(find(controller.view, "drone.delivery.selectedVideo"))
|
||||
let frame = card.convert(card.bounds, to: window)
|
||||
XCTAssertTrue(window.bounds.contains(frame))
|
||||
XCTAssertGreaterThan(frame.height, 200)
|
||||
let controls = try ["drone.delivery.preview", "drone.delivery.chooseVideo", "drone.delivery.removeVideo", "drone.delivery.submit"].map { try button(controller.view, $0) }
|
||||
controls.forEach { assertVisibleAndHittable($0, in: window) }
|
||||
list.setContentOffset(CGPoint(x: 0, y: max(0, list.contentSize.height - list.bounds.height)), animated: false)
|
||||
window.layoutIfNeeded()
|
||||
XCTAssertEqual(card.convert(card.bounds, to: window), frame)
|
||||
controls.forEach { assertVisibleAndHittable($0, in: window) }
|
||||
XCTAssertEqual(fixture.uploader.count, 0)
|
||||
XCTAssertTrue(fixture.service.saved.isEmpty)
|
||||
capture(window, "云端上传-设计稿小屏固定预览与操作")
|
||||
}
|
||||
|
||||
/// 长文件名摘要固定在底栏上方,滚动列表不遮挡预览和上传,播放本地视频不触发上传。
|
||||
func testLongVideoPreviewStaysVisibleAboveFooterWithoutUploading() async throws {
|
||||
let fixture = try DeliveryUIFixture()
|
||||
@@ -478,11 +518,11 @@ final class DroneDockDeliveryViewTests: XCTestCase {
|
||||
private func hidden(_ view: UIView) -> Bool { view.isHidden || view.alpha < 0.01 || (view.superview.map(hidden) ?? false) }
|
||||
private func find(_ root: UIView, _ id: String) -> UIView? { descendants(root).first { $0.accessibilityIdentifier == id && !hidden($0) } }
|
||||
private func texts(_ root: UIView) -> [String] { descendants(root).compactMap { ($0 as? UILabel).flatMap { hidden($0) ? nil : $0.text } } }
|
||||
private func show(_ controller: UIViewController) -> UIWindow {
|
||||
private func show(_ controller: UIViewController, size: CGSize? = nil) -> UIWindow {
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first
|
||||
previousKeyWindow = scene?.windows.first { $0.isKeyWindow }
|
||||
let window = scene.map(UIWindow.init(windowScene:)) ?? UIWindow(frame: UIScreen.main.bounds)
|
||||
window.frame = scene?.coordinateSpace.bounds ?? UIScreen.main.bounds
|
||||
window.frame = size.map { CGRect(origin: .zero, size: $0) } ?? scene?.coordinateSpace.bounds ?? UIScreen.main.bounds
|
||||
window.overrideUserInterfaceStyle = .light
|
||||
window.rootViewController = UINavigationController(rootViewController: controller)
|
||||
window.makeKeyAndVisible(); window.layoutIfNeeded()
|
||||
@@ -552,7 +592,7 @@ private final class DeliveryUIService: DroneDockDeliveryServing {
|
||||
var holdSave = false
|
||||
var saved: [(task: Int, url: String, name: String)] = []
|
||||
private var saveContinuation: CheckedContinuation<Void, Never>?
|
||||
private var records: [[String: Any]]
|
||||
var records: [[String: Any]]
|
||||
private let allowed: Bool
|
||||
|
||||
init(empty: Bool, allowed: Bool, filmTask: Int?) throws {
|
||||
|
||||
@@ -8,13 +8,17 @@ final class DroneDockNearbyTransferViewTests: XCTestCase {
|
||||
/// 未选片时不能生成二维码,不自动打开本地监听。
|
||||
func testInitialPageDoesNotStartService() throws {
|
||||
let service = NearbyViewService()
|
||||
let controller = DroneDockNearbyTransferViewController(customerTitle: "测试游客", viewModel: .init(service: service))
|
||||
let controller = DroneDockNearbyTransferViewController(customerTitle: "测试游客", orderNumber: "TEST-5018", viewModel: .init(service: service))
|
||||
let window = show(controller)
|
||||
defer { close(window) }
|
||||
XCTAssertFalse(try button(controller.view, "drone.nearby.primary").isEnabled)
|
||||
XCTAssertEqual(service.startCount, 0)
|
||||
XCTAssertEqual(try label(controller.view, "drone.nearby.status").text, "准备闪传")
|
||||
XCTAssertNil(controller.viewModel.snapshot.session)
|
||||
XCTAssertTrue(texts(in: controller.view).contains("测试游客"))
|
||||
XCTAssertTrue(texts(in: controller.view).contains("订单尾号 5018"))
|
||||
XCTAssertTrue(texts(in: controller.view).contains("双方连接同一 Wi-Fi 或手机热点"))
|
||||
XCTAssertTrue(isHidden(try button(controller.view, "drone.nearby.copyAddress")))
|
||||
let choose = try button(controller.view, "drone.nearby.chooseVideo")
|
||||
let center = choose.convert(CGPoint(x: choose.bounds.midX, y: choose.bounds.midY), to: window)
|
||||
let hit = window.hitTest(center, with: nil)
|
||||
@@ -101,11 +105,20 @@ final class DroneDockNearbyTransferViewTests: XCTestCase {
|
||||
return model.snapshot.session != nil && scroll.contentOffset.y > 0
|
||||
&& scroll.bounds.contains(qr.convert(qr.bounds, to: scroll))
|
||||
&& scroll.bounds.contains(expiry.convert(expiry.bounds, to: scroll))
|
||||
&& scroll.bounds.contains(copy.convert(copy.bounds, to: scroll))
|
||||
&& controller.view.bounds.contains(copy.convert(copy.bounds, to: controller.view))
|
||||
}
|
||||
XCTAssertGreaterThan(scroll.contentOffset.y, 0)
|
||||
let footer = try XCTUnwrap(find(controller.view, "drone.nearby.footer"))
|
||||
XCTAssertTrue(copy.isDescendant(of: footer), "复制地址固定在页脚,不随内容滚走")
|
||||
XCTAssertEqual(copy.configuration?.title, "复制接收地址")
|
||||
XCTAssertTrue(copy.isEnabled)
|
||||
XCTAssertEqual(try button(controller.view, "drone.nearby.primary").title(for: .normal), "结束闪传")
|
||||
// 等待首次定位动画收尾,再模拟用户主动返回顶部。
|
||||
try await Task.sleep(for: .milliseconds(350))
|
||||
let center = copy.convert(CGPoint(x: copy.bounds.midX, y: copy.bounds.midY), to: window)
|
||||
let hit = window.hitTest(center, with: nil)
|
||||
XCTAssertTrue(hit === copy || hit?.isDescendant(of: copy) == true)
|
||||
capture(window, name: "面对面闪传-小屏接收码与固定操作-隔离替身")
|
||||
scroll.setContentOffset(.zero, animated: false)
|
||||
service.send(.sending(bytesSent: 2, totalBytes: 4))
|
||||
try await settle { try self.label(controller.view, "drone.nearby.status").text == "正在发送视频" }
|
||||
@@ -121,6 +134,90 @@ final class DroneDockNearbyTransferViewTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/// 会话期间固定复制入口不会结束传输,结束操作先确认,原视频不能被更换或预览。
|
||||
func testActiveFooterCopiesAddressAndRequiresStopConfirmation() async throws {
|
||||
let file = try XCTUnwrap(Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4")
|
||||
?? Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4", subdirectory: "DroneDock"))
|
||||
let fileSize = try XCTUnwrap(file.resourceValues(forKeys: [.fileSizeKey]).fileSize)
|
||||
let service = NearbyViewService()
|
||||
let model = DroneDockNearbyTransferViewModel(service: service)
|
||||
// 直接预选 Bundle 文件,不交给页面的临时选片文件清理流程。
|
||||
try model.selectVideo(.init(url: file, fileName: file.lastPathComponent, fileSize: fileSize))
|
||||
let controller = DroneDockNearbyTransferViewController(customerTitle: "测试游客132****9413", orderNumber: "TEST-5018", viewModel: model)
|
||||
let window = show(controller)
|
||||
defer { close(window) }
|
||||
XCTAssertEqual(service.startCount, 0, "选片本身不得开启本地监听")
|
||||
try button(controller.view, "drone.nearby.primary").sendActions(for: .touchUpInside)
|
||||
try await settle { try !self.button(controller.view, "drone.nearby.copyAddress").isHidden && model.snapshot.session != nil }
|
||||
let copy = try button(controller.view, "drone.nearby.copyAddress")
|
||||
let stop = try button(controller.view, "drone.nearby.primary")
|
||||
XCTAssertFalse(try button(controller.view, "drone.nearby.chooseVideo").isEnabled)
|
||||
let preview = try button(controller.view, "drone.nearby.preview")
|
||||
XCTAssertFalse(preview.isEnabled)
|
||||
XCTAssertTrue(isHidden(preview), "发送期间不向触摸或 VoiceOver 暴露预览操作")
|
||||
XCTAssertEqual(stop.currentTitleColor, .systemRed)
|
||||
XCTAssertEqual(stop.backgroundColor, .clear)
|
||||
let thumbnail = try XCTUnwrap(find(controller.view, "drone.nearby.videoThumbnail"))
|
||||
try await settle { thumbnail.accessibilityLabel == "所选视频封面" }
|
||||
window.layoutIfNeeded()
|
||||
try await Task.sleep(for: .milliseconds(350))
|
||||
window.layoutIfNeeded()
|
||||
let scroll = try XCTUnwrap(find(controller.view, "drone.nearby.content") as? UIScrollView)
|
||||
let qr = try XCTUnwrap(find(controller.view, "drone.nearby.qr"))
|
||||
let expiry = try XCTUnwrap(find(controller.view, "drone.nearby.expiry"))
|
||||
XCTAssertTrue(scroll.bounds.contains(qr.convert(qr.bounds, to: scroll)), "标准屏必须完整显示二维码")
|
||||
XCTAssertTrue(scroll.bounds.contains(expiry.convert(expiry.bounds, to: scroll)), "标准屏必须完整显示接收码有效期")
|
||||
XCTAssertEqual(qr.bounds.width, 196, accuracy: 0.5)
|
||||
XCTAssertEqual(qr.bounds.height, 196, accuracy: 0.5)
|
||||
XCTAssertTrue(controller.view.bounds.contains(copy.convert(copy.bounds, to: controller.view)))
|
||||
XCTAssertTrue(controller.view.bounds.contains(stop.convert(stop.bounds, to: controller.view)))
|
||||
let footer = try XCTUnwrap(find(controller.view, "drone.nearby.footer"))
|
||||
XCTAssertEqual(copy.convert(copy.bounds, to: footer).minX, 20, accuracy: 0.5)
|
||||
XCTAssertLessThanOrEqual(copy.convert(copy.bounds, to: footer).maxY, stop.convert(stop.bounds, to: footer).minY)
|
||||
capture(window, name: "面对面闪传-标准屏真实本地视频封面-隔离替身")
|
||||
copy.sendActions(for: .touchUpInside)
|
||||
try await settle { controller.presentedViewController is UIAlertController }
|
||||
XCTAssertEqual((controller.presentedViewController as? UIAlertController)?.title, "接收地址已复制")
|
||||
XCTAssertEqual(UIPasteboard.general.string, model.snapshot.session?.url.absoluteString)
|
||||
XCTAssertEqual(service.stopCount, 0)
|
||||
controller.dismiss(animated: false)
|
||||
try await settle { controller.presentedViewController == nil }
|
||||
stop.sendActions(for: .touchUpInside)
|
||||
try await settle { controller.presentedViewController is UIAlertController }
|
||||
let confirmation = try XCTUnwrap(controller.presentedViewController as? UIAlertController)
|
||||
XCTAssertEqual(confirmation.title, "结束本次闪传?")
|
||||
XCTAssertEqual(confirmation.actions.map(\.title), ["继续闪传", "结束闪传"])
|
||||
XCTAssertEqual(confirmation.actions.map(\.style), [.cancel, .destructive])
|
||||
XCTAssertNotNil(model.snapshot.session, "确认前不能撤销接收码")
|
||||
XCTAssertEqual(service.startCount, 1)
|
||||
XCTAssertEqual(service.stopCount, 0)
|
||||
controller.dismiss(animated: false)
|
||||
}
|
||||
|
||||
/// 启动失败不保留虚假二维码或复制入口,原视频和主动重试入口继续可用。
|
||||
func testStartFailureRestoresVideoSelectionAndGenerateAction() async throws {
|
||||
let directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
|
||||
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
||||
defer { try? FileManager.default.removeItem(at: directory) }
|
||||
let file = directory.appendingPathComponent("测试视频.mp4")
|
||||
try Data([1, 2, 3, 4]).write(to: file)
|
||||
let service = NearbyViewService(startError: DroneDockNearbyTransferError.noLocalNetwork)
|
||||
let model = DroneDockNearbyTransferViewModel(service: service)
|
||||
try model.selectVideo(.init(url: file, fileName: "测试视频.mp4", fileSize: 4))
|
||||
let controller = DroneDockNearbyTransferViewController(customerTitle: "测试游客", viewModel: model)
|
||||
let window = show(controller)
|
||||
defer { close(window) }
|
||||
try button(controller.view, "drone.nearby.primary").sendActions(for: .touchUpInside)
|
||||
try await settle { try self.label(controller.view, "drone.nearby.status").text == "暂时无法闪传" }
|
||||
XCTAssertEqual(try button(controller.view, "drone.nearby.primary").title(for: .normal), "重新生成接收码")
|
||||
XCTAssertTrue(try button(controller.view, "drone.nearby.primary").isEnabled)
|
||||
XCTAssertTrue(try button(controller.view, "drone.nearby.chooseVideo").isEnabled)
|
||||
XCTAssertTrue(isHidden(try button(controller.view, "drone.nearby.copyAddress")))
|
||||
XCTAssertNil((find(controller.view, "drone.nearby.qr") as? UIImageView)?.image)
|
||||
XCTAssertEqual(model.snapshot.video?.fileName, "测试视频.mp4")
|
||||
XCTAssertEqual(service.startCount, 1)
|
||||
}
|
||||
|
||||
private func show(_ controller: UIViewController) -> UIWindow {
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first!
|
||||
let window = UIWindow(windowScene: scene)
|
||||
@@ -154,6 +251,25 @@ final class DroneDockNearbyTransferViewTests: XCTestCase {
|
||||
try XCTUnwrap(find(view, identifier) as? UILabel)
|
||||
}
|
||||
|
||||
private func isHidden(_ view: UIView) -> Bool {
|
||||
view.isHidden || view.alpha < 0.01 || (view.superview.map(isHidden) ?? false)
|
||||
}
|
||||
|
||||
private func texts(in view: UIView) -> [String] {
|
||||
(isHidden(view) ? [] : (view as? UILabel)?.text.map { [$0] } ?? []) + view.subviews.flatMap { texts(in: $0) }
|
||||
}
|
||||
|
||||
private func capture(_ window: UIWindow, name: String) {
|
||||
window.layoutIfNeeded()
|
||||
let image = UIGraphicsImageRenderer(bounds: window.bounds).image { _ in
|
||||
window.drawHierarchy(in: window.bounds, afterScreenUpdates: true)
|
||||
}
|
||||
let attachment = XCTAttachment(image: image)
|
||||
attachment.name = name
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
|
||||
private func settle(_ condition: () throws -> Bool) async throws {
|
||||
for _ in 0..<100 {
|
||||
if try condition() { return }
|
||||
@@ -169,11 +285,15 @@ private final class NearbyViewService: DroneDockNearbyTransferServing, @unchecke
|
||||
private var handler: (@Sendable (DroneDockNearbyTransferEvent) -> Void)?
|
||||
private var starts = 0
|
||||
private var stops = 0
|
||||
private let startError: Error?
|
||||
var startCount: Int { locked { starts } }
|
||||
var stopCount: Int { locked { stops } }
|
||||
|
||||
init(startError: Error? = nil) { self.startError = startError }
|
||||
|
||||
func start(video: DroneDockDeliveryVideo, onEvent: @escaping @Sendable (DroneDockNearbyTransferEvent) -> Void) async throws -> DroneDockNearbyTransferSession {
|
||||
locked { starts += 1; handler = onEvent }
|
||||
if let startError { throw startError }
|
||||
return .init(id: UUID(), url: URL(string: "http://192.168.0.2:8000/s/local-test")!, expiresAt: Date().addingTimeInterval(600))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user