feat: 完善机巢图传、拍摄阶段与任务交互
- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放 - 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时 - 补充准备页电量与前往回执,进入任务时移除准备页路由 - 对齐拍摄中和拍摄完成原型布局,移除详情按钮 - 补充隔离测试、接口记录与项目约定 验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
@@ -43,17 +43,27 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
private var isSendingSafetyAction = false
|
||||
private var isResummoningAction = false
|
||||
private var wasRealtimeLive = false
|
||||
private let coverURL: URL?
|
||||
private var finishedExecutions: Set<String> = []
|
||||
private var displayedCompletionIDs: Set<String> = []
|
||||
private var completionNotice: DroneDockRecordingCompletionView?
|
||||
private let countdownDelay: @Sendable () async throws -> Void
|
||||
private var countdownTask: Task<Void, Never>?
|
||||
private var countdownGeneration = 0
|
||||
|
||||
/// 构造时只保存依赖,首次 GET 必须等页面完整出现后才发送。
|
||||
init(viewModel: DroneDockShootingTaskViewModel,
|
||||
liveViewModel: DroneDockLiveViewModel? = nil,
|
||||
livePlayer: (any DroneDockLivePlaying)? = nil,
|
||||
coverURL: URL? = nil,
|
||||
realtimeSession: DroneDockShootingRealtimeSession? = nil,
|
||||
materialsControllerFactory: (@MainActor (DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController)? = nil,
|
||||
simulationRecordsProvider: (@MainActor () -> String)? = nil,
|
||||
shootingPollDelay: @escaping @Sendable (UInt64) async throws -> Void = { try await Task.sleep(nanoseconds: $0) },
|
||||
liveParameterDelay: @escaping @Sendable (TimeInterval) async throws -> Void = { try await Task.sleep(for: .seconds($0)) }) {
|
||||
liveParameterDelay: @escaping @Sendable (TimeInterval) async throws -> Void = { try await Task.sleep(for: .seconds($0)) },
|
||||
countdownDelay: @escaping @Sendable () async throws -> Void = { try await Task.sleep(for: .seconds(1)) }) {
|
||||
self.viewModel = viewModel
|
||||
self.coverURL = coverURL
|
||||
self.feedPlaceholder = livePlayer.map { DroneDockTaskLiveView(rtcPlayer: $0) } ?? DroneDockTaskLiveView()
|
||||
self.realtimeSession = realtimeSession
|
||||
self.liveViewModel = liveViewModel ?? DroneDockLiveViewModel(
|
||||
@@ -62,6 +72,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
self.simulationRecordsProvider = simulationRecordsProvider
|
||||
self.shootingPollDelay = shootingPollDelay
|
||||
self.liveParameterDelay = liveParameterDelay
|
||||
self.countdownDelay = countdownDelay
|
||||
self.materialsControllerFactory = materialsControllerFactory ?? { order, context in
|
||||
DroneDockMaterialsViewController(viewModel: DroneDockMaterialsViewModel(
|
||||
context: context, order: order,
|
||||
@@ -92,6 +103,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
resummonTask?.cancel()
|
||||
liveTask?.cancel()
|
||||
liveParameterTask?.cancel()
|
||||
countdownTask?.cancel()
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
@@ -228,6 +240,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
isPageVisible = false
|
||||
dismissCompletionNotice()
|
||||
logEvent("page.disappeared")
|
||||
cancelRefresh()
|
||||
stopLive()
|
||||
@@ -235,26 +248,103 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
|
||||
private func applySnapshot() {
|
||||
guard isViewLoaded else { return }
|
||||
if viewModel.isRecordingFinished { finishedExecutions.insert(viewModel.recordingExecutionID) }
|
||||
let recordingFinished = finishedExecutions.contains(viewModel.recordingExecutionID)
|
||||
if !viewModel.shouldPresentRecordingCompletion { dismissCompletionNotice() }
|
||||
if recordingFinished, liveTask != nil || liveParameterTask != nil || liveViewModel.playbackSessionID != nil || liveViewModel.playbackURL != nil {
|
||||
stopLive()
|
||||
}
|
||||
feedPlaceholder.showRecordingCover(recordingFinished, url: coverURL)
|
||||
let loading = (viewModel.response == nil && (isRequesting || viewModel.isLoading))
|
||||
|| isStartingAction || viewModel.isStartingShooting
|
||||
|| isSendingSafetyAction || viewModel.isSendingCommand || isResummoningAction || viewModel.isResummoning
|
||||
feedPlaceholder.apply(liveViewModel)
|
||||
feedPlaceholder.setPlaybackActive(isPageVisible && isApplicationActive)
|
||||
feedPlaceholder.setPlaybackActive(isPageVisible && isApplicationActive && !recordingFinished)
|
||||
taskTitleLabel.text = viewModel.title
|
||||
subtitleLabel.text = viewModel.subtitle + (viewModel.response?.metricsStale == true ? " · 读数已过期" : "")
|
||||
let telemetry = viewModel.telemetry
|
||||
telemetryView.apply(values: [telemetry.batteryText, telemetry.temperatureText, telemetry.windText,
|
||||
telemetry.rainText, telemetry.signalText, telemetry.satelliteText],
|
||||
isStale: viewModel.isTelemetryStale, accessibilityPrefix: "drone.task.remote.metric", preservingStaleValues: true)
|
||||
let value = loading && viewModel.response == nil ? DroneDockTaskPresentation(
|
||||
let presentation = viewModel.presentation
|
||||
let value = loading && viewModel.response == nil && presentation.phase != .navigating ? DroneDockTaskPresentation(
|
||||
phase: .loading, title: "正在获取任务状态", message: "正在读取当前拍摄任务",
|
||||
deviceStatus: "—", action: .none, actionTitle: nil, isActionEnabled: false) : viewModel.presentation
|
||||
deviceStatus: "—", action: .none, actionTitle: nil, isActionEnabled: false) : presentation
|
||||
statusView.apply(value, isRefreshing: loading)
|
||||
updateArrivalCountdown()
|
||||
safetyView.apply(model: viewModel, isSimulation: simulationRecordsProvider != nil,
|
||||
isInteractive: isPageVisible && isApplicationActive && !loading)
|
||||
statusView.isUserInteractionEnabled = isPageVisible && isApplicationActive && !loading
|
||||
navigationItem.rightBarButtonItems?.forEach { $0.isEnabled = isPageVisible && isApplicationActive && !loading }
|
||||
navigationItem.rightBarButtonItem?.accessibilityValue = loading ? "正在刷新" : nil
|
||||
presentCompletionNoticeIfNeeded()
|
||||
refreshLiveIfVisible(automatically: true)
|
||||
}
|
||||
|
||||
/// 倒计时只更新独立秒数标签;网络读取、飞控及后端阶段仍由原有流程驱动。
|
||||
private func updateArrivalCountdown() {
|
||||
let seconds = viewModel.countdownRemainingSeconds
|
||||
statusView.updateCountdown(seconds: seconds)
|
||||
guard isPageVisible, isApplicationActive, let seconds, seconds > 0 else {
|
||||
stopArrivalCountdown()
|
||||
return
|
||||
}
|
||||
guard countdownTask == nil else { return }
|
||||
countdownGeneration += 1
|
||||
let generation = countdownGeneration
|
||||
let delay = countdownDelay
|
||||
countdownTask = Task { @MainActor [weak self] in
|
||||
while !Task.isCancelled {
|
||||
do { try await delay() } catch { return }
|
||||
guard let self, !Task.isCancelled, self.countdownGeneration == generation,
|
||||
self.isPageVisible, self.isApplicationActive else { return }
|
||||
let remaining = self.viewModel.countdownRemainingSeconds
|
||||
self.statusView.updateCountdown(seconds: remaining)
|
||||
if remaining == nil || remaining == 0 {
|
||||
self.countdownTask = nil
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func stopArrivalCountdown() {
|
||||
countdownGeneration += 1
|
||||
countdownTask?.cancel()
|
||||
countdownTask = nil
|
||||
}
|
||||
|
||||
private func presentCompletionNoticeIfNeeded() {
|
||||
let id = viewModel.recordingExecutionID
|
||||
guard viewModel.shouldPresentRecordingCompletion, isPageVisible, isApplicationActive, view.window != nil,
|
||||
presentedViewController == nil, completionNotice == nil, !displayedCompletionIDs.contains(id) else { return }
|
||||
displayedCompletionIDs.insert(id)
|
||||
let notice = DroneDockRecordingCompletionView()
|
||||
completionNotice = notice
|
||||
notice.onLater = { [weak self] in self?.dismissCompletionNotice() }
|
||||
notice.onViewMaterials = { [weak self] in
|
||||
guard let self, self.isPageVisible, self.isApplicationActive,
|
||||
self.viewModel.recordingExecutionID == id else { return }
|
||||
self.dismissCompletionNotice()
|
||||
self.openMaterials()
|
||||
}
|
||||
let container = navigationController?.view ?? view!
|
||||
container.addSubview(notice)
|
||||
notice.snp.makeConstraints { $0.edges.equalToSuperview() }
|
||||
UIAccessibility.post(notification: .screenChanged, argument: notice)
|
||||
}
|
||||
|
||||
private func dismissCompletionNotice() {
|
||||
completionNotice?.removeFromSuperview()
|
||||
completionNotice = nil
|
||||
}
|
||||
|
||||
private func openMaterials() {
|
||||
guard isPageVisible, isApplicationActive, presentedViewController == nil,
|
||||
viewModel.presentation.action == .materials, viewModel.presentation.isActionEnabled,
|
||||
let navigationController, navigationController.topViewController === self else { return }
|
||||
dismissCompletionNotice()
|
||||
navigationController.pushViewController(materialsControllerFactory(viewModel.order, viewModel.context), animated: true)
|
||||
}
|
||||
|
||||
private func primaryActionTriggered() {
|
||||
@@ -274,8 +364,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
case .retry:
|
||||
resummonIfAllowed()
|
||||
case .materials:
|
||||
guard let navigationController, navigationController.topViewController === self else { return }
|
||||
navigationController.pushViewController(materialsControllerFactory(viewModel.order, viewModel.context), animated: true)
|
||||
openMaterials()
|
||||
case .resume, .none:
|
||||
break
|
||||
}
|
||||
@@ -366,6 +455,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func cancelRefresh() {
|
||||
stopArrivalCountdown()
|
||||
wasRealtimeLive = false
|
||||
realtimeSession?.stop()
|
||||
cancelScheduledPoll()
|
||||
@@ -473,6 +563,8 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
|
||||
/// 可见且活跃时自动开启一次;失败可手动重试,不随 shooting/Socket 刷新重复请求。
|
||||
private func refreshLiveIfVisible(automatically: Bool = false, keepingPlayback: Bool = false) {
|
||||
guard viewModel.response != nil, viewModel.readAccessError == nil,
|
||||
!finishedExecutions.contains(viewModel.recordingExecutionID), !viewModel.isRecordingFinished else { return }
|
||||
guard !automatically || liveViewModel.loadsAutomatically else { return }
|
||||
guard isPageVisible, isApplicationActive, liveTask == nil, liveViewModel.canLoad else { return }
|
||||
liveParameterTask?.cancel()
|
||||
|
||||
Reference in New Issue
Block a user