92 lines
4.8 KiB
Swift
92 lines
4.8 KiB
Swift
import UIKit
|
|
|
|
/// 订单列表与素材库共用的真实成片交付页面工厂。
|
|
@MainActor
|
|
enum DroneDockDeliveryEntry {
|
|
/// 所有交付入口先选择方式;素材入口保留任务预选,云端页面在同一弹窗内继续。
|
|
static func makeMethodSheet(order: DroneDockHomeOrder, context: DroneDockHomeContext,
|
|
taskID: Int? = nil,
|
|
controllerFactory: @escaping (DroneDockHomeOrder, DroneDockHomeContext, Int?) -> UIViewController,
|
|
onDidDismiss: ((Bool) -> Void)? = nil,
|
|
onDidCloseCloud: @escaping () -> Void = {}) -> UINavigationController {
|
|
let methods = DroneDockDeliveryMethodViewController(customerTitle: order.touristTitle)
|
|
let navigation = DroneDockDeliverySheetNavigationController(rootViewController: methods)
|
|
navigation.modalPresentationStyle = .pageSheet
|
|
navigation.onDidCloseCloud = onDidCloseCloud
|
|
navigation.onDidDismiss = onDidDismiss
|
|
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, orderNumber: order.orderNumber)
|
|
nearby.onClose = { [weak navigation] in navigation?.dismiss(animated: true) }
|
|
navigation.isModalInPresentation = true
|
|
navigation.sheetPresentationController?.animateChanges {
|
|
navigation.sheetPresentationController?.detents = [.large()]
|
|
navigation.sheetPresentationController?.selectedDetentIdentifier = .large
|
|
}
|
|
navigation.setNavigationBarHidden(false, animated: true)
|
|
navigation.pushViewController(nearby, animated: true)
|
|
}
|
|
methods.onCloudUpload = { [weak navigation, weak methods] in
|
|
guard let navigation, let methods, navigation.topViewController === methods else { return }
|
|
let cloud = controllerFactory(order, context, taskID)
|
|
if let cloud = cloud as? DroneDockDeliveryViewController {
|
|
cloud.configureSheetPresentation { [weak navigation] in navigation?.dismiss(animated: true) }
|
|
}
|
|
navigation.didOpenCloud = true
|
|
navigation.isModalInPresentation = true
|
|
navigation.sheetPresentationController?.animateChanges {
|
|
navigation.sheetPresentationController?.detents = [.large()]
|
|
navigation.sheetPresentationController?.selectedDetentIdentifier = .large
|
|
}
|
|
navigation.setNavigationBarHidden(false, animated: true)
|
|
navigation.pushViewController(cloud, animated: true)
|
|
}
|
|
return navigation
|
|
}
|
|
|
|
/// 同时传递订单与可选任务,进入页面后重新校验当前身份和上传权限。
|
|
static func makeController(order: DroneDockHomeOrder, context: DroneDockHomeContext, taskID: Int?) -> UIViewController {
|
|
let client = NetworkServices.shared.apiClient
|
|
return DroneDockDeliveryViewController(viewModel: DroneDockDeliveryViewModel(
|
|
context: context, order: order,
|
|
service: DroneDockDeliveryAPI(client: client),
|
|
uploader: DroneDockFilmUploader(configService: UploadAPI(client: client)),
|
|
initialTaskID: taskID,
|
|
currentContext: { DroneDockHomeViewController.currentContext() }
|
|
))
|
|
}
|
|
}
|
|
|
|
/// 统一处理手动关闭与下拉关闭,云端交付结束后只通知来源列表一次。
|
|
@MainActor
|
|
private final class DroneDockDeliverySheetNavigationController: UINavigationController, UIAdaptivePresentationControllerDelegate {
|
|
/// 云端页面已经进入,关闭弹窗后需要重读订单状态。
|
|
var didOpenCloud = false
|
|
/// 不因仅查看交付方式而刷新订单。
|
|
var onDidCloseCloud: (() -> Void)?
|
|
/// 关闭方式弹窗后通知来源页,并传回是否曾打开云端交付。
|
|
var onDidDismiss: ((Bool) -> Void)?
|
|
private var didNotifyClose = false
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
presentationController?.delegate = self
|
|
}
|
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
super.viewDidDisappear(animated)
|
|
if isBeingDismissed || presentingViewController == nil { notifyClose() }
|
|
}
|
|
|
|
/// 系统下拉关闭与按钮关闭使用同一去重通知。
|
|
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { notifyClose() }
|
|
|
|
private func notifyClose() {
|
|
guard !didNotifyClose else { return }
|
|
didNotifyClose = true
|
|
if didOpenCloud { onDidCloseCloud?() }
|
|
onDidDismiss?(didOpenCloud)
|
|
}
|
|
}
|