feat: 更新素材管理和举报风险地图
This commit is contained in:
@ -25,18 +25,16 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
private let detailContainerView = UIView()
|
||||
private let scrollView = UIScrollView()
|
||||
private let contentStack = UIStackView()
|
||||
private let loadingIndicator = UIActivityIndicatorView(style: .medium)
|
||||
private var annotationMap: [String: WildReportMapMarker] = [:]
|
||||
private var isShowingRiskMapLoading = false
|
||||
|
||||
init(
|
||||
record: WildReportRecord,
|
||||
riskPoints: [WildReportRiskPoint],
|
||||
api: any WildPhotographerReportServing = NetworkServices.shared.wildPhotographerReportAPI,
|
||||
locationProvider: any LocationProviding = LocationProvider.shared,
|
||||
scenicIdProvider: @escaping () -> Int = { AppStore.shared.currentScenicId },
|
||||
scenicNameProvider: @escaping () -> String = { AppStore.shared.currentScenicName }
|
||||
) {
|
||||
self.viewModel = WildReportRiskMapViewModel(record: record, riskPoints: riskPoints)
|
||||
self.viewModel = WildReportRiskMapViewModel()
|
||||
self.api = api
|
||||
self.locationProvider = locationProvider
|
||||
self.scenicIdProvider = scenicIdProvider
|
||||
@ -61,6 +59,13 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
if isMovingFromParent || isBeingDismissed || navigationController?.isBeingDismissed == true {
|
||||
setRiskMapLoadingVisible(false)
|
||||
}
|
||||
}
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "附近风险地图"
|
||||
}
|
||||
@ -184,6 +189,7 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
|
||||
@MainActor
|
||||
private func refreshContent(animated: Bool) {
|
||||
setRiskMapLoadingVisible(viewModel.isLoading)
|
||||
scenicNameLabel.text = viewModel.scenicAreaName
|
||||
syncMapAnnotations()
|
||||
mapView.setRegion(viewModel.region, animated: animated)
|
||||
@ -192,6 +198,13 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
rebuildPanel()
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func setRiskMapLoadingVisible(_ isVisible: Bool) {
|
||||
guard isShowingRiskMapLoading != isVisible else { return }
|
||||
isShowingRiskMapLoading = isVisible
|
||||
isVisible ? showLoading() : hideLoading()
|
||||
}
|
||||
|
||||
private func syncMapAnnotations() {
|
||||
let oldAnnotations = mapView.annotations.compactMap { $0 as? WildReportMapAnnotation }
|
||||
mapView.removeAnnotations(oldAnnotations)
|
||||
@ -234,9 +247,6 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
contentStack.addArrangedSubview(makeLoadingView(text: "正在加载风险点位..."))
|
||||
}
|
||||
if let message = viewModel.errorMessage, !viewModel.isLoading {
|
||||
contentStack.addArrangedSubview(makeStateCard(icon: "exclamationmark.triangle.fill", text: message))
|
||||
}
|
||||
@ -401,15 +411,6 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
return row
|
||||
}
|
||||
|
||||
private func makeLoadingView(text: String) -> UIView {
|
||||
let card = WildReportCardView(spacing: 12, inset: 16)
|
||||
card.stack.alignment = .center
|
||||
loadingIndicator.startAnimating()
|
||||
card.stack.addArrangedSubview(loadingIndicator)
|
||||
card.stack.addArrangedSubview(WildReportUI.label(text, font: .systemFont(ofSize: 14), color: AppColor.textSecondary))
|
||||
return card
|
||||
}
|
||||
|
||||
private func makeInlineLoading(text: String) -> UIView {
|
||||
let row = UIStackView()
|
||||
row.axis = .horizontal
|
||||
@ -464,7 +465,7 @@ final class WildReportRiskMapViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func presentImagePreview(url: String) {
|
||||
present(WildReportRiskImagePreviewController(url: url), animated: true)
|
||||
presentImagePreview(imageURLs: [url], startIndex: 0)
|
||||
}
|
||||
|
||||
@objc private func navigateTapped() {
|
||||
@ -711,46 +712,3 @@ private final class WildReportRiskImageTile: UIView {
|
||||
onTap?()
|
||||
}
|
||||
}
|
||||
|
||||
/// 风险地图图片预览页面。
|
||||
private final class WildReportRiskImagePreviewController: UIViewController {
|
||||
private let url: String
|
||||
private let imageView = UIImageView()
|
||||
|
||||
init(url: String) {
|
||||
self.url = url
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
modalPresentationStyle = .fullScreen
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = .black
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
view.addSubview(imageView)
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.edges.equalTo(view.safeAreaLayoutGuide)
|
||||
}
|
||||
if let imageURL = URL(string: url) {
|
||||
imageView.kf.setImage(with: imageURL)
|
||||
}
|
||||
let closeButton = UIButton(type: .system)
|
||||
closeButton.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
|
||||
closeButton.tintColor = .white
|
||||
closeButton.addTarget(self, action: #selector(closeTapped), for: .touchUpInside)
|
||||
view.addSubview(closeButton)
|
||||
closeButton.snp.makeConstraints { make in
|
||||
make.top.trailing.equalTo(view.safeAreaLayoutGuide).inset(18)
|
||||
make.size.equalTo(36)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func closeTapped() {
|
||||
dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user