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]
|
||||
}
|
||||
let close = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .plain, target: self, action: #selector(closeSheetTapped))
|
||||
close.accessibilityLabel = "关闭成片交付"
|
||||
close.accessibilityIdentifier = "drone.delivery.sheet.close"
|
||||
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>()
|
||||
snapshot.appendSections([.order])
|
||||
snapshot.appendItems([.order, .intro], toSection: .order)
|
||||
if viewModel.detail != nil && !isRefreshing {
|
||||
snapshot.appendSections([.order])
|
||||
snapshot.appendItems([.order], toSection: .order)
|
||||
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) }
|
||||
}
|
||||
}
|
||||
snapshot.appendSections([.state])
|
||||
snapshot.appendItems([.state], toSection: .state)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user