feat: 统一机巢加载体验并对齐到达态界面
工作台、准备页、任务首次读取和景区空境库复用应用通用 Loading;到达态按 Web 展示,保留倒计时及手动开拍权限。新增图传几何诊断,不改变 Fit 渲染或设备连接行为。 验证:App 与测试包无签名 build-for-testing 编译通过,git diff --check 通过。iPhone 11 当前 unavailable,真机回归待设备重连后执行。
This commit is contained in:
@@ -2,7 +2,7 @@ import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 正式机巢首页:朱工提供设备,张工提供订单与今日统计。
|
||||
final class DroneDockHomeViewController: BaseViewController {
|
||||
final class DroneDockHomeViewController: GlobalLoadingPageViewController {
|
||||
/// 与演示数据源隔离的首页状态。
|
||||
let viewModel: DroneDockHomeViewModel
|
||||
private let paymentControllerFactory: (() -> UIViewController)?
|
||||
@@ -117,6 +117,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
loadMoreTask?.cancel()
|
||||
isLoadingOrdersPage = false
|
||||
isRefreshing = true
|
||||
setPageLoading(viewModel.response == nil && viewModel.ordersResponse == nil)
|
||||
refreshTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
let isInitialLoad = self.viewModel.response == nil && self.viewModel.ordersResponse == nil
|
||||
@@ -124,6 +125,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
await self.viewModel.refresh()
|
||||
guard !Task.isCancelled else { return }
|
||||
self.isRefreshing = false
|
||||
self.setPageLoading(false)
|
||||
self.collectionView.refreshControl?.endRefreshing()
|
||||
self.applySnapshot(animated: true) { [weak self] in
|
||||
if isInitialLoad, let self {
|
||||
|
||||
@@ -3,7 +3,7 @@ import UIKit
|
||||
|
||||
/// 展示准备信息并提交召唤;业务成功后携同一任务 ID 进入真实拍摄任务页。
|
||||
@MainActor
|
||||
final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
final class DroneDockRemotePreparationViewController: GlobalLoadingPageViewController {
|
||||
/// 当前订单、准备信息及任务创建状态。
|
||||
let viewModel: DroneDockPreparationViewModel
|
||||
|
||||
@@ -162,6 +162,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
startPlaneStatusPolling()
|
||||
guard !isRefreshing else { return }
|
||||
isRefreshing = true
|
||||
setPageLoading(viewModel.projectInfo == nil)
|
||||
refreshTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
let isInitialLoad = self.viewModel.projectInfo == nil
|
||||
@@ -169,6 +170,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
await self.viewModel.refresh()
|
||||
guard !Task.isCancelled else { return }
|
||||
self.isRefreshing = false
|
||||
self.setPageLoading(false)
|
||||
self.refreshControl.endRefreshing()
|
||||
self.applySnapshot(animated: true) { [weak self] in
|
||||
guard let self else { return }
|
||||
|
||||
@@ -3,7 +3,7 @@ import UIKit
|
||||
|
||||
/// 拍摄任务页:前台优先订阅快照、异常时 HTTP 兜底;自动开启图传,飞控仍由用户操作。
|
||||
@MainActor
|
||||
final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController {
|
||||
/// 入口传入的固定任务身份及只读状态,供导航协调和页面测试检查。
|
||||
let viewModel: DroneDockShootingTaskViewModel
|
||||
/// 图传使用独立状态,刷新与播放不会影响任务阶段或固定布局。
|
||||
@@ -287,11 +287,14 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
telemetry.rainText, telemetry.signalText, telemetry.satelliteText],
|
||||
isStale: viewModel.isTelemetryStale, accessibilityPrefix: "drone.task.remote.metric", preservingStaleValues: true)
|
||||
let presentation = viewModel.presentation
|
||||
setPageLoading(viewModel.response == nil && loading && presentation.phase != .navigating)
|
||||
let value = loading && viewModel.response == nil && presentation.phase != .navigating ? DroneDockTaskPresentation(
|
||||
phase: .loading, title: "正在获取任务状态", message: "正在读取当前拍摄任务",
|
||||
deviceStatus: "—", action: .none, actionTitle: nil, isActionEnabled: false) : presentation
|
||||
statusView.apply(value, isRefreshing: loading, isPrimaryActionLoading: value.action == .resume
|
||||
&& (submittingCommands.contains(.resume) || viewModel.isCommandLoading(.resume)))
|
||||
let primaryActionLoading = value.action == .resume
|
||||
&& (submittingCommands.contains(.resume) || viewModel.isCommandLoading(.resume))
|
||||
|| value.action == .start && (isStartingAction || viewModel.isStartingShooting)
|
||||
statusView.apply(value, isRefreshing: loading, isPrimaryActionLoading: primaryActionLoading)
|
||||
updateArrivalCountdown()
|
||||
safetyView.apply(model: viewModel, isSimulation: simulationRecordsProvider != nil,
|
||||
isInteractive: isPageVisible && isApplicationActive && !loading,
|
||||
|
||||
@@ -232,6 +232,12 @@ final class DroneDockTaskLiveView: UIView {
|
||||
onDiagnosticEvent?(isNewSession ? "live.receiver.start_requested" : "live.receiver.rooms_updated", [
|
||||
"receiver_session": sessionID.uuidString,
|
||||
"rooms": requestedRTC.map { ["role": $0.role, "room_id": $0.roomID] }])
|
||||
rtcPlayer.setGeometryHandler { [weak self] geometry in
|
||||
guard let self, self.activeSessionID == sessionID else { return }
|
||||
var fields = geometry.diagnosticFields
|
||||
fields["receiver_session"] = sessionID.uuidString
|
||||
self.onDiagnosticEvent?("live.geometry", fields)
|
||||
}
|
||||
rtcPlayer.start(requestedRTC, in: rtcView) { [weak self] event in
|
||||
guard let self, self.activeSessionID == sessionID else { return }
|
||||
self.onPlaybackEvent?(event, sessionID)
|
||||
@@ -261,6 +267,7 @@ final class DroneDockTaskLiveView: UIView {
|
||||
"rooms": activeRTC.map { ["role": $0.role, "room_id": $0.roomID] }])
|
||||
activeSessionID = nil
|
||||
activeRTC = []
|
||||
rtcPlayer.setGeometryHandler(nil)
|
||||
rtcPlayer.stop()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 已到达待开拍面板:蓝色到达提示、分级文案及整行开拍按钮,倒计时只参与显示。
|
||||
@MainActor
|
||||
final class DroneDockTaskReadyView: UIView {
|
||||
/// 将已允许的主操作交给任务页面,组件自身不请求状态或发送开拍指令。
|
||||
var onPrimaryAction: (() -> Void)?
|
||||
/// 当前排版比例,固定区域内不使用 transform 缩小点击范围。
|
||||
private(set) var effectiveScale: CGFloat = 1
|
||||
/// 固定区域较矮时收紧文字、图标和间距。
|
||||
private(set) var usesCompactLayout = false
|
||||
|
||||
private let content = UIView()
|
||||
private let header = UIView()
|
||||
private let iconBackground = UIView()
|
||||
private let icon = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
|
||||
private let titleLabel = DroneDockStyle.label(size: 23, weight: .semibold, color: UIColor(hex: 0x101523))
|
||||
private let promptLabel = DroneDockStyle.label(size: 18, weight: .medium, color: UIColor(hex: 0x101523))
|
||||
private let messageLabel = DroneDockStyle.label(size: 14, color: UIColor(hex: 0x6A79A0))
|
||||
private let actionButton = UIButton(type: .system)
|
||||
private let activityIndicator = UIActivityIndicatorView(style: .medium)
|
||||
private var presentation: DroneDockTaskPresentation?
|
||||
private var countdownSeconds: Int?
|
||||
private var identifiersActive = false
|
||||
private var isPrimaryActionLoading = false
|
||||
private var headerHeight: Constraint?
|
||||
private var iconSize: Constraint?
|
||||
private var textLeading: Constraint?
|
||||
private var titleHeight: Constraint?
|
||||
private var promptTop: Constraint?
|
||||
private var promptHeight: Constraint?
|
||||
private var messageTop: Constraint?
|
||||
private var messageHeight: Constraint?
|
||||
private var actionTop: Constraint?
|
||||
private var actionHeight: Constraint?
|
||||
|
||||
/// 创建与任务页固定状态区域配合的待开拍面板。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 保留展示模型中的真实限制说明和主操作许可,加载时仅显示对应按钮动画。
|
||||
func apply(_ presentation: DroneDockTaskPresentation, isRefreshing: Bool, isPrimaryActionLoading: Bool) {
|
||||
self.presentation = presentation
|
||||
self.isPrimaryActionLoading = isPrimaryActionLoading
|
||||
titleLabel.text = presentation.title
|
||||
messageLabel.text = presentation.message
|
||||
actionButton.isHidden = presentation.action == .none || DroneDockHomeMetric.usableText(presentation.actionTitle) == nil
|
||||
actionButton.isEnabled = presentation.isActionEnabled && !actionButton.isHidden && !isRefreshing && !isPrimaryActionLoading
|
||||
actionButton.configuration?.image = UIImage(systemName: presentation.action == .refresh ? "arrow.clockwise" : "camera")
|
||||
countdownSeconds = presentation.action == .start ? presentation.countdownSeconds.map { max(0, $0) } : nil
|
||||
updateActionTitle()
|
||||
if isPrimaryActionLoading { activityIndicator.startAnimating() }
|
||||
else { activityIndicator.stopAnimating() }
|
||||
actionButton.accessibilityValue = isPrimaryActionLoading ? "处理中" : nil
|
||||
setIdentifiersActive(identifiersActive)
|
||||
actionButton.setNeedsUpdateConfiguration()
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
/// 更新已有按钮的数字,不改变权限、尺寸或触发任何业务回调。
|
||||
func updateCountdown(seconds: Int?) {
|
||||
countdownSeconds = presentation?.action == .start ? seconds.map { max(0, $0) } : nil
|
||||
updateActionTitle()
|
||||
}
|
||||
|
||||
/// 仅当前可见面板暴露公共标识,隐藏时清除数字及加载动画。
|
||||
func setIdentifiersActive(_ active: Bool) {
|
||||
identifiersActive = active
|
||||
if !active {
|
||||
activityIndicator.stopAnimating()
|
||||
updateCountdown(seconds: nil)
|
||||
}
|
||||
titleLabel.accessibilityIdentifier = active ? "drone.task.remote.statusTitle" : nil
|
||||
promptLabel.accessibilityIdentifier = active ? "drone.task.remote.readyPrompt" : nil
|
||||
messageLabel.accessibilityIdentifier = active ? "drone.task.remote.statusMessage" : nil
|
||||
actionButton.accessibilityIdentifier = active
|
||||
? (presentation?.action == .refresh ? "drone.task.remote.refresh" : "drone.task.remote.primary") : nil
|
||||
activityIndicator.accessibilityIdentifier = active ? "drone.task.remote.primary.loading" : nil
|
||||
}
|
||||
|
||||
/// 在固定区域内压缩排版,始终保留至少 44 点的主按钮。
|
||||
override func layoutSubviews() {
|
||||
updateContentLayout()
|
||||
super.layoutSubviews()
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
accessibilityIdentifier = "drone.task.remote.ready"
|
||||
backgroundColor = .white
|
||||
addSubview(content)
|
||||
[header, actionButton].forEach(content.addSubview)
|
||||
[iconBackground, titleLabel, promptLabel, messageLabel].forEach(header.addSubview)
|
||||
iconBackground.addSubview(icon)
|
||||
iconBackground.accessibilityIdentifier = "drone.task.remote.readyIcon"
|
||||
iconBackground.backgroundColor = UIColor(hex: 0xE2EDFF)
|
||||
iconBackground.layer.cornerRadius = 20.5
|
||||
icon.tintColor = UIColor(hex: 0x0671FF)
|
||||
icon.contentMode = .scaleAspectFit
|
||||
titleLabel.accessibilityTraits = .header
|
||||
titleLabel.numberOfLines = 1
|
||||
promptLabel.text = "是否开始拍摄?"
|
||||
promptLabel.numberOfLines = 1
|
||||
messageLabel.numberOfLines = 2
|
||||
messageLabel.lineBreakMode = .byTruncatingTail
|
||||
var configuration = UIButton.Configuration.filled()
|
||||
configuration.imagePadding = 12
|
||||
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 24, weight: .regular)
|
||||
configuration.background.cornerRadius = 8
|
||||
configuration.cornerStyle = .fixed
|
||||
configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8)
|
||||
actionButton.configuration = configuration
|
||||
actionButton.configurationUpdateHandler = { [weak self] button in
|
||||
guard let self, var configuration = button.configuration else { return }
|
||||
let foreground = UIColor.white
|
||||
configuration.background.backgroundColor = UIColor(hex: 0x0671FF)
|
||||
.withAlphaComponent(button.isEnabled || self.isPrimaryActionLoading ? 1 : 0.35)
|
||||
configuration.baseForegroundColor = foreground
|
||||
configuration.imageColorTransformer = UIConfigurationColorTransformer { _ in foreground }
|
||||
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
||||
var result = attributes
|
||||
result.font = .monospacedDigitSystemFont(ofSize: self.usesCompactLayout ? 16 : 18, weight: .semibold)
|
||||
result.foregroundColor = foreground
|
||||
return result
|
||||
}
|
||||
button.configuration = configuration
|
||||
}
|
||||
actionButton.addTarget(self, action: #selector(primaryTapped), for: .touchUpInside)
|
||||
activityIndicator.color = .white
|
||||
activityIndicator.hidesWhenStopped = true
|
||||
activityIndicator.isUserInteractionEnabled = false
|
||||
actionButton.addSubview(activityIndicator)
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
content.snp.makeConstraints { make in
|
||||
make.leading.trailing.equalToSuperview().inset(18)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
header.snp.makeConstraints { make in
|
||||
make.top.leading.trailing.equalToSuperview()
|
||||
headerHeight = make.height.equalTo(86).constraint
|
||||
}
|
||||
iconBackground.snp.makeConstraints { make in
|
||||
make.top.leading.equalToSuperview()
|
||||
iconSize = make.size.equalTo(41).constraint
|
||||
}
|
||||
icon.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.size.equalTo(iconBackground.snp.width).multipliedBy(24.0 / 41.0)
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.trailing.equalToSuperview()
|
||||
textLeading = make.leading.equalTo(iconBackground.snp.trailing).offset(12).constraint
|
||||
titleHeight = make.height.equalTo(30).constraint
|
||||
}
|
||||
promptLabel.snp.makeConstraints { make in
|
||||
promptTop = make.top.equalTo(titleLabel.snp.bottom).offset(4).constraint
|
||||
make.leading.trailing.equalTo(titleLabel)
|
||||
promptHeight = make.height.equalTo(26).constraint
|
||||
}
|
||||
messageLabel.snp.makeConstraints { make in
|
||||
messageTop = make.top.equalTo(promptLabel.snp.bottom).offset(3).constraint
|
||||
make.leading.trailing.equalTo(titleLabel)
|
||||
messageHeight = make.height.equalTo(23).constraint
|
||||
}
|
||||
actionButton.snp.makeConstraints { make in
|
||||
actionTop = make.top.equalTo(header.snp.bottom).offset(10).constraint
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
actionHeight = make.height.equalTo(50).constraint
|
||||
}
|
||||
activityIndicator.snp.makeConstraints { make in
|
||||
make.centerY.equalToSuperview()
|
||||
make.trailing.equalToSuperview().inset(12)
|
||||
make.size.equalTo(20)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateActionTitle() {
|
||||
guard let presentation else { return }
|
||||
var title = DroneDockHomeMetric.usableText(presentation.actionTitle)
|
||||
if let seconds = countdownSeconds, let base = title { title = "\(base)(\(seconds)s)" }
|
||||
UIView.performWithoutAnimation {
|
||||
actionButton.setTitle(title, for: .normal)
|
||||
actionButton.configuration?.title = title
|
||||
actionButton.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateContentLayout() {
|
||||
guard let presentation, bounds.width > 0, bounds.height > 0 else { return }
|
||||
let wasCompact = usesCompactLayout
|
||||
usesCompactLayout = bounds.height < 190
|
||||
let compact = usesCompactLayout
|
||||
let extreme = bounds.height < 120
|
||||
let diameter: CGFloat = extreme ? 24 : compact ? 32 : 41
|
||||
let iconGap: CGFloat = extreme ? 8 : compact ? 10 : 12
|
||||
let titleSize: CGFloat = extreme ? 17 : compact ? 20 : 23
|
||||
let promptSize: CGFloat = extreme ? 15 : compact ? 17 : 18
|
||||
let messageSize: CGFloat = compact ? 13 : 14
|
||||
let buttonHeight: CGFloat = compact ? 44 : 50
|
||||
let buttonGap: CGFloat = extreme ? 6 : 10
|
||||
let available = max(1, bounds.height - (extreme ? 8 : 12))
|
||||
titleLabel.font = .systemFont(ofSize: titleSize, weight: .semibold)
|
||||
promptLabel.font = .systemFont(ofSize: promptSize, weight: .medium)
|
||||
messageLabel.font = .systemFont(ofSize: messageSize)
|
||||
let title = max(ceil(titleLabel.font.lineHeight), compact ? 0 : 30)
|
||||
var prompt = max(ceil(promptLabel.font.lineHeight), compact ? 0 : 26)
|
||||
var firstGap: CGFloat = compact ? 2 : 4
|
||||
let secondGap: CGFloat = 3
|
||||
let textWidth = max(1, bounds.width - 36 - diameter - iconGap)
|
||||
let paragraph = NSMutableParagraphStyle()
|
||||
paragraph.minimumLineHeight = messageSize * 1.6
|
||||
paragraph.maximumLineHeight = messageSize * 1.6
|
||||
let attributes: [NSAttributedString.Key: Any] = [
|
||||
.font: messageLabel.font as Any, .foregroundColor: UIColor(hex: 0x6A79A0), .paragraphStyle: paragraph
|
||||
]
|
||||
messageLabel.attributedText = NSAttributedString(string: presentation.message, attributes: attributes)
|
||||
let measured = (presentation.message as NSString).boundingRect(
|
||||
with: CGSize(width: textWidth, height: .greatestFiniteMagnitude),
|
||||
options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: attributes, context: nil).height
|
||||
var lines = extreme || presentation.message.isEmpty ? 0 : 2
|
||||
var body = lines == 0 ? 0 : ceil(min(measured, paragraph.maximumLineHeight * CGFloat(lines)))
|
||||
while title + firstGap + prompt + (lines > 0 ? secondGap + body : 0) + buttonGap + buttonHeight > available, lines > 0 {
|
||||
lines -= 1
|
||||
body = lines == 0 ? 0 : ceil(min(measured, paragraph.maximumLineHeight * CGFloat(lines)))
|
||||
}
|
||||
if title + firstGap + prompt + buttonGap + buttonHeight > available {
|
||||
prompt = 0
|
||||
firstGap = 0
|
||||
}
|
||||
promptLabel.isHidden = prompt == 0
|
||||
messageLabel.isHidden = lines == 0
|
||||
messageLabel.numberOfLines = max(1, lines)
|
||||
effectiveScale = compact ? 0.8 : 1
|
||||
headerHeight?.update(offset: max(diameter, title + firstGap + prompt + (lines > 0 ? secondGap + body : 0)))
|
||||
iconSize?.update(offset: diameter)
|
||||
iconBackground.layer.cornerRadius = diameter / 2
|
||||
textLeading?.update(offset: iconGap)
|
||||
titleHeight?.update(offset: title)
|
||||
promptTop?.update(offset: firstGap)
|
||||
promptHeight?.update(offset: prompt)
|
||||
messageTop?.update(offset: lines > 0 ? secondGap : 0)
|
||||
messageHeight?.update(offset: body)
|
||||
actionTop?.update(offset: buttonGap)
|
||||
actionHeight?.update(offset: buttonHeight)
|
||||
if wasCompact != usesCompactLayout { actionButton.setNeedsUpdateConfiguration() }
|
||||
}
|
||||
|
||||
@objc private func primaryTapped() {
|
||||
guard !isHidden, actionButton.isEnabled, !actionButton.isHidden else { return }
|
||||
onPrimaryAction?()
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
private let failureView = DroneDockTaskFailureView()
|
||||
private let completedView = DroneDockTaskCompletedView()
|
||||
private let shootingView = DroneDockTaskShootingView()
|
||||
private let readyView = DroneDockTaskReadyView()
|
||||
private let controlStateView = DroneDockTaskControlStateView()
|
||||
private var presentation: DroneDockTaskPresentation?
|
||||
private var countdownSeconds: Int?
|
||||
@@ -87,17 +88,26 @@ final class DroneDockTaskStatusView: UIView {
|
||||
let isFailure = presentation.phase == .failed
|
||||
let isCompleted = [.postShootUploading, .completed].contains(presentation.phase)
|
||||
let isShooting = presentation.phase == .shooting
|
||||
let isReady = presentation.phase == .ready
|
||||
let isControlState = [.paused, .returning, .returned].contains(presentation.phase)
|
||||
contentStack.isHidden = isFailure || isCompleted || isShooting || isControlState
|
||||
contentStack.isHidden = isFailure || isCompleted || isShooting || isReady || isControlState
|
||||
failureView.isHidden = !isFailure
|
||||
completedView.isHidden = !isCompleted
|
||||
shootingView.isHidden = !isShooting
|
||||
readyView.isHidden = !isReady
|
||||
controlStateView.isHidden = !isControlState
|
||||
completedView.setIdentifiersActive(isCompleted)
|
||||
shootingView.setIdentifiersActive(isShooting)
|
||||
readyView.setIdentifiersActive(isReady)
|
||||
controlStateView.setIdentifiersActive(isControlState)
|
||||
titleLabel.accessibilityIdentifier = isCompleted || isShooting || isControlState ? nil : "drone.task.remote.statusTitle"
|
||||
messageLabel.accessibilityIdentifier = isCompleted || isShooting || isControlState ? nil : "drone.task.remote.statusMessage"
|
||||
titleLabel.accessibilityIdentifier = isCompleted || isShooting || isReady || isControlState ? nil : "drone.task.remote.statusTitle"
|
||||
messageLabel.accessibilityIdentifier = isCompleted || isShooting || isReady || isControlState ? nil : "drone.task.remote.statusMessage"
|
||||
if isReady {
|
||||
primaryButton.accessibilityIdentifier = nil
|
||||
readyView.apply(presentation, isRefreshing: isRefreshing, isPrimaryActionLoading: isPrimaryActionLoading)
|
||||
setNeedsLayout()
|
||||
return
|
||||
}
|
||||
if isControlState {
|
||||
primaryButton.accessibilityIdentifier = nil
|
||||
controlStateView.apply(presentation, isRefreshing: isRefreshing, isPrimaryActionLoading: isPrimaryActionLoading)
|
||||
@@ -144,6 +154,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
? seconds.map { max(0, $0) } : nil
|
||||
guard value != countdownSeconds else { return }
|
||||
countdownSeconds = value
|
||||
readyView.updateCountdown(seconds: value)
|
||||
updatePrimaryButtonTitle()
|
||||
}
|
||||
|
||||
@@ -166,6 +177,13 @@ final class DroneDockTaskStatusView: UIView {
|
||||
|
||||
/// 尺寸改变时仅重排内部内容,保留至少 44 点操作区域,不使用 transform 缩放。
|
||||
override func layoutSubviews() {
|
||||
if presentation?.phase == .ready {
|
||||
super.layoutSubviews()
|
||||
readyView.layoutIfNeeded()
|
||||
effectiveScale = readyView.effectiveScale
|
||||
usesCompactLayout = readyView.usesCompactLayout
|
||||
return
|
||||
}
|
||||
if let phase = presentation?.phase, [.paused, .returning, .returned].contains(phase) {
|
||||
super.layoutSubviews()
|
||||
controlStateView.layoutIfNeeded()
|
||||
@@ -200,6 +218,9 @@ final class DroneDockTaskStatusView: UIView {
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = .white
|
||||
addSubview(readyView)
|
||||
readyView.isHidden = true
|
||||
readyView.onPrimaryAction = { [weak self] in self?.onPrimaryAction?() }
|
||||
addSubview(controlStateView)
|
||||
controlStateView.isHidden = true
|
||||
controlStateView.onPrimaryAction = { [weak self] in self?.onPrimaryAction?() }
|
||||
@@ -243,6 +264,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
readyView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
controlStateView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
shootingView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
completedView.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
|
||||
@@ -4,6 +4,8 @@ import UIKit
|
||||
/// 接收端最小能力,隔离测试无需初始化 SDK 或使用真实凭证。
|
||||
@MainActor
|
||||
protocol DroneDockRTCReceivingEngine: AnyObject {
|
||||
/// 仅用于诊断的 SDK 版本;无 SDK 替身可保持未知。
|
||||
var sdkVersion: String? { get }
|
||||
/// 创建一个独立接收房间并转交事件。
|
||||
func makeRoom(_ id: String, onEvent: @escaping @Sendable (DroneDockVolcEvent) -> Void) -> (any DroneDockRTCReceivingRoom)?
|
||||
/// 按 SDK 提供的流 ID 绑定或解绑画布。
|
||||
@@ -12,6 +14,10 @@ protocol DroneDockRTCReceivingEngine: AnyObject {
|
||||
func destroy()
|
||||
}
|
||||
|
||||
extension DroneDockRTCReceivingEngine {
|
||||
var sdkVersion: String? { nil }
|
||||
}
|
||||
|
||||
/// 单路只收视频的房间;不提供发布、采集或设备控制能力。
|
||||
@MainActor
|
||||
protocol DroneDockRTCReceivingRoom: AnyObject {
|
||||
@@ -31,6 +37,9 @@ final class DroneDockVolcEngineAdapter: DroneDockRTCReceivingEngine {
|
||||
private let engine: ByteRTCEngine
|
||||
private let delegate: DroneDockVolcDelegate
|
||||
|
||||
/// 查询版本不会创建额外引擎或加入房间。
|
||||
var sdkVersion: String? { ByteRTCEngine.getSDKVersion() }
|
||||
|
||||
private init(engine: ByteRTCEngine, delegate: DroneDockVolcDelegate) {
|
||||
self.engine = engine
|
||||
self.delegate = delegate
|
||||
|
||||
@@ -4,6 +4,8 @@ import UIKit
|
||||
/// 可替换的双路图传播放器;测试注入内存替身,不初始化 RTC 或连接设备。
|
||||
@MainActor
|
||||
protocol DroneDockLivePlaying: AnyObject {
|
||||
/// 设置只读几何事件出口;不触发播放、连接或任务状态刷新。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?)
|
||||
/// 同一播放会话可增补或更新凭证,不重建未变化的房间。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
onEvent: @escaping @MainActor (DroneDockLivePlaybackEvent) -> Void)
|
||||
@@ -11,11 +13,21 @@ protocol DroneDockLivePlaying: AnyObject {
|
||||
func stop()
|
||||
}
|
||||
|
||||
extension DroneDockLivePlaying {
|
||||
/// 旧播放器替身无需实现诊断能力。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {}
|
||||
}
|
||||
|
||||
/// 真实 SDK 入口始终执行编译期禁飞保护,没有运行时放行参数。
|
||||
@MainActor
|
||||
final class DroneDockVolcLivePlayer: DroneDockLivePlaying {
|
||||
private let receiver = DroneDockLiveReceiver(makeEngine: DroneDockVolcEngineAdapter.make)
|
||||
|
||||
/// 几何事件与业务播放事件分离,不改变播放状态机。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {
|
||||
receiver.setGeometryHandler(handler)
|
||||
}
|
||||
|
||||
/// Release 通过接收器播放;Debug 在创建 SDK 之前拒绝连接。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
onEvent: @escaping @MainActor (DroneDockLivePlaybackEvent) -> Void) {
|
||||
@@ -51,6 +63,12 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
private var failedRoles: Set<String> = []
|
||||
private var generation = UUID()
|
||||
private var onEvent: (@MainActor (DroneDockLivePlaybackEvent) -> Void)?
|
||||
private var onGeometry: (@MainActor (DroneDockLiveGeometry) -> Void)?
|
||||
|
||||
/// 复用调用方的任务诊断会话,不在接收器中另建日志通道。
|
||||
func setGeometryHandler(_ handler: (@MainActor (DroneDockLiveGeometry) -> Void)?) {
|
||||
onGeometry = handler
|
||||
}
|
||||
|
||||
/// 加入只收视频的房间;同一来源只更新 Token,避免后台重查导致画面闪断。
|
||||
func start(_ configurations: [DroneDockVolcLiveConfiguration], in view: UIView,
|
||||
@@ -201,6 +219,8 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
_ = engine?.setVideoView(nil, streamID: id)
|
||||
_ = source.room.subscribeVideo(id, subscribe: false)
|
||||
source.streamID = nil
|
||||
source.frameGeometry = nil
|
||||
source.reportedFirstFrame = false
|
||||
markReady(false, source: source)
|
||||
return
|
||||
}
|
||||
@@ -209,9 +229,13 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
let render = engine?.setVideoView(source.view, streamID: id)
|
||||
let subscribe = source.room.subscribeVideo(id, subscribe: true)
|
||||
if render != 0 || subscribe != 0 { sourceFailed(source.configuration.role, message: "图传订阅失败(\(render ?? -1)/\(subscribe)),请重试") }
|
||||
case .frame(let id, let roomID):
|
||||
case .frame(let id, let roomID, let geometry):
|
||||
guard let source = source(in: roomID), source.streamID == id else { return }
|
||||
if let geometry { updateFrameGeometry(geometry, source: source, isFirstFrame: true) }
|
||||
markReady(true, source: source)
|
||||
case .videoSizeChanged(let id, let roomID, let geometry):
|
||||
guard let source = source(in: roomID), source.streamID == id else { return }
|
||||
updateFrameGeometry(geometry, source: source, isFirstFrame: false)
|
||||
case .videoState(let id, let roomID, let state):
|
||||
guard let source = source(in: roomID), source.streamID == id else { return }
|
||||
switch state {
|
||||
@@ -236,6 +260,27 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
sources.values.first { $0.configuration.roomID == roomID }
|
||||
}
|
||||
|
||||
private func updateFrameGeometry(_ geometry: DroneDockVideoFrameGeometry,
|
||||
source: DroneDockVolcSource, isFirstFrame: Bool) {
|
||||
let changed = source.frameGeometry != geometry
|
||||
source.frameGeometry = geometry
|
||||
if isFirstFrame, !source.reportedFirstFrame {
|
||||
source.reportedFirstFrame = true
|
||||
emitGeometry(source, trigger: "first_frame")
|
||||
} else if changed {
|
||||
emitGeometry(source, trigger: "video_size_changed")
|
||||
}
|
||||
}
|
||||
|
||||
private func emitGeometry(_ source: DroneDockVolcSource, trigger: String) {
|
||||
guard let streamID = source.streamID, let container else { return }
|
||||
onGeometry?(DroneDockLiveGeometry(trigger: trigger, role: source.configuration.role,
|
||||
roomID: source.configuration.roomID, streamID: streamID, frame: source.frameGeometry,
|
||||
containerWidth: Double(source.view.bounds.width), containerHeight: Double(source.view.bounds.height),
|
||||
hostWidth: Double(container.bounds.width), hostHeight: Double(container.bounds.height),
|
||||
isSelected: selection.selectedRole == source.configuration.role, sdkVersion: engine?.sdkVersion))
|
||||
}
|
||||
|
||||
private func markReady(_ ready: Bool, source: DroneDockVolcSource) {
|
||||
selection.setReady(ready, role: source.configuration.role)
|
||||
if ready {
|
||||
@@ -267,6 +312,7 @@ final class DroneDockLiveReceiver: DroneDockLivePlaying {
|
||||
if let role, let view = sources[role]?.view { container?.bringSubviewToFront(view) }
|
||||
guard displayedRole != role else { return }
|
||||
displayedRole = role
|
||||
if let role, let source = sources[role] { emitGeometry(source, trigger: "source_changed") }
|
||||
onEvent?(.sourceChanged(role))
|
||||
}
|
||||
}
|
||||
@@ -279,6 +325,8 @@ private final class DroneDockVolcSource {
|
||||
let room: any DroneDockRTCReceivingRoom
|
||||
let view: UIView
|
||||
var streamID: String?
|
||||
var frameGeometry: DroneDockVideoFrameGeometry?
|
||||
var reportedFirstFrame = false
|
||||
var timeoutTask: Task<Void, Never>?
|
||||
var expiryTask: Task<Void, Never>?
|
||||
|
||||
@@ -290,7 +338,8 @@ private final class DroneDockVolcSource {
|
||||
/// SDK 工作线程只转交值类型事件;事件带房间和流身份以隔离两路回调。
|
||||
enum DroneDockVolcEvent: Sendable {
|
||||
case published(String, String, Bool)
|
||||
case frame(String, String)
|
||||
case frame(String, String, DroneDockVideoFrameGeometry? = nil)
|
||||
case videoSizeChanged(String, String, DroneDockVideoFrameGeometry)
|
||||
case videoState(String, String, ByteRTCRemoteVideoState)
|
||||
case roomFailed(String, Int)
|
||||
case connectionLost
|
||||
@@ -313,7 +362,17 @@ final class DroneDockVolcDelegate: NSObject, ByteRTCEngineDelegate, ByteRTCRoomD
|
||||
func rtcEngine(_ engine: ByteRTCEngine, onFirstRemoteVideoFrameDecoded streamId: String,
|
||||
info: ByteRTCStreamInfo, withFrameInfo frameInfo: ByteRTCVideoFrameInfo) {
|
||||
// 未展示的画布也能解码,不能依赖被隐藏视图的 rendered 回调判断首帧。
|
||||
emit(.frame(streamId, info.roomId))
|
||||
emit(.frame(streamId, info.roomId, Self.geometry(frameInfo)))
|
||||
}
|
||||
|
||||
func rtcEngine(_ engine: ByteRTCEngine, onRemoteVideoSizeChanged streamId: String,
|
||||
info: ByteRTCStreamInfo, withFrameInfo frameInfo: ByteRTCVideoFrameInfo) {
|
||||
emit(.videoSizeChanged(streamId, info.roomId, Self.geometry(frameInfo)))
|
||||
}
|
||||
|
||||
private static func geometry(_ frameInfo: ByteRTCVideoFrameInfo) -> DroneDockVideoFrameGeometry {
|
||||
DroneDockVideoFrameGeometry(width: frameInfo.width, height: frameInfo.height,
|
||||
rotation: frameInfo.rotation.rawValue)
|
||||
}
|
||||
|
||||
func rtcEngine(_ engine: ByteRTCEngine, onRemoteVideoStateChanged streamId: String, info: ByteRTCStreamInfo,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import UIKit
|
||||
|
||||
/// 将页面的阻塞读取接入应用通用 Loading,离页或后台仅释放本页令牌。
|
||||
@MainActor
|
||||
class GlobalLoadingPageViewController: BaseViewController {
|
||||
private var requestsPageLoading = false
|
||||
private var pageIsVisible = false
|
||||
private var applicationIsActive = UIApplication.shared.applicationState == .active
|
||||
private var pageLoadingToken: UUID?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(loadingApplicationWillResignActive),
|
||||
name: UIApplication.willResignActiveNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(loadingApplicationDidBecomeActive),
|
||||
name: UIApplication.didBecomeActiveNotification, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
pageIsVisible = true
|
||||
applicationIsActive = UIApplication.shared.applicationState == .active
|
||||
updatePageLoading()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
pageIsVisible = false
|
||||
updatePageLoading()
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let token = pageLoadingToken {
|
||||
Task { @MainActor in GlobalLoadingManager.shared.endRequest(token) }
|
||||
}
|
||||
}
|
||||
|
||||
/// 仅首次无可用内容或需要等待的页面读取使用;轮询、分页及按钮进度保持局部反馈。
|
||||
func setPageLoading(_ isLoading: Bool) {
|
||||
requestsPageLoading = isLoading
|
||||
updatePageLoading()
|
||||
}
|
||||
|
||||
@objc private func loadingApplicationWillResignActive() {
|
||||
applicationIsActive = false
|
||||
updatePageLoading()
|
||||
}
|
||||
|
||||
@objc private func loadingApplicationDidBecomeActive() {
|
||||
applicationIsActive = true
|
||||
updatePageLoading()
|
||||
}
|
||||
|
||||
private func updatePageLoading() {
|
||||
if requestsPageLoading && pageIsVisible && applicationIsActive {
|
||||
if pageLoadingToken == nil { pageLoadingToken = GlobalLoadingManager.shared.beginRequest() }
|
||||
} else if let token = pageLoadingToken {
|
||||
pageLoadingToken = nil
|
||||
GlobalLoadingManager.shared.endRequest(token)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import UIKit
|
||||
|
||||
/// 独立景区空镜库页面,提供筛选、分组预览、选择与前台下载演示,不依赖机巢订单。
|
||||
@MainActor
|
||||
final class ScenicMaterialsViewController: BaseViewController {
|
||||
final class ScenicMaterialsViewController: GlobalLoadingPageViewController {
|
||||
/// 当前景区的素材与本地选择、下载状态。
|
||||
let viewModel: ScenicMaterialsViewModel
|
||||
|
||||
@@ -55,11 +55,13 @@ final class ScenicMaterialsViewController: BaseViewController {
|
||||
let session = AppStore.shared.session
|
||||
guard session.accountType == .storeUser, session.userId == viewModel.context.userID,
|
||||
String(session.currentScenicId) == viewModel.context.scenicID else {
|
||||
setPageLoading(false)
|
||||
refreshControl.endRefreshing()
|
||||
showToast("请使用门店账号并重新进入当前景区素材库")
|
||||
return
|
||||
}
|
||||
let api = ScenicMaterialsAPI(client: NetworkServices.shared.apiClient)
|
||||
setPageLoading(!refreshControl.isRefreshing)
|
||||
emptyTitle.text = "正在加载素材"
|
||||
emptyMessage.text = "请稍候"
|
||||
retryButton.isHidden = true
|
||||
@@ -69,6 +71,7 @@ final class ScenicMaterialsViewController: BaseViewController {
|
||||
guard let self else { return }
|
||||
await self.viewModel.loadRemoteSessions(api: api)
|
||||
guard !Task.isCancelled else { return }
|
||||
self.setPageLoading(false)
|
||||
self.refreshControl.endRefreshing()
|
||||
self.refreshDisplay()
|
||||
}
|
||||
@@ -212,6 +215,7 @@ final class ScenicMaterialsViewController: BaseViewController {
|
||||
/// 仅在确认离开页面后作废异步工作,取消返回手势继续保留原来的加载及下载。
|
||||
private func finishLeaving() {
|
||||
loadTask?.cancel()
|
||||
setPageLoading(false)
|
||||
isLoadingNextPage = false
|
||||
viewModel.cancelRemoteLoad()
|
||||
authorizationTask?.cancel()
|
||||
|
||||
Reference in New Issue
Block a user