[ios] Fix track selection point updates on every new selection

On the every new tap on the `Track` or during the `Elevation chart` dragging, the track `Active point` will be updated now. It allows to keep the current selected track point coordinates up to date and fix the bug when the `route to/route from` buttons use only the initial coordinates.
Key changes:
1. the `Active point` and `My position` points are moved from the `Elevation profile` to the `PlacePageTrackData` because this properties are related to the whole track. Not only chart. The chart is only one of the consumers of this data updates.
2. The subscription to the active point updates is moved from the `Elevation profile` to the `PlacePagePresenter`. The reason - see 1.
2. The callback `onActivePointChanged` is added to notify that the active point is updated
3. When the callback is triggered the `PlacePageTrackData` fetches the new coordinates from the core and saves it. This coordinates are used by the `route to/from` buttons.

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn
2025-06-17 21:22:47 +04:00
committed by Konstantin Pastbin
parent 927299f4a9
commit aec82794ac
13 changed files with 126 additions and 65 deletions

View File

@@ -1,13 +1,11 @@
import CoreApi
class ElevationProfileBuilder {
static func build(trackInfo: TrackInfo,
elevationProfileData: ElevationProfileData?,
static func build(trackData: PlacePageTrackData,
delegate: ElevationProfileViewControllerDelegate?) -> ElevationProfileViewController {
let viewController = ElevationProfileViewController();
let presenter = ElevationProfilePresenter(view: viewController,
trackInfo: trackInfo,
profileData: elevationProfileData,
trackData: trackData,
delegate: delegate)
viewController.presenter = presenter
return viewController

View File

@@ -1,10 +1,14 @@
import Chart
import CoreApi
protocol ElevationProfilePresenterProtocol: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func configure()
func update(trackInfo: TrackInfo, profileData: ElevationProfileData?)
protocol TrackActivePointPresenter: AnyObject {
func updateActivePoint(_ distance: Double)
func updateMyPosition(_ distance: Double)
}
protocol ElevationProfilePresenterProtocol: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, TrackActivePointPresenter {
func configure()
func update(with trackData: PlacePageTrackData)
func onDifficultyButtonPressed()
func onSelectedPointChanged(_ point: CGFloat)
}
@@ -22,8 +26,7 @@ fileprivate struct DescriptionsViewModel {
final class ElevationProfilePresenter: NSObject {
private weak var view: ElevationProfileViewProtocol?
private var trackInfo: TrackInfo
private var profileData: ElevationProfileData?
private var trackData: PlacePageTrackData
private let delegate: ElevationProfileViewControllerDelegate?
private let bookmarkManager: BookmarksManager = .shared()
@@ -33,19 +36,17 @@ final class ElevationProfilePresenter: NSObject {
private let formatter: ElevationProfileFormatter
init(view: ElevationProfileViewProtocol,
trackInfo: TrackInfo,
profileData: ElevationProfileData?,
trackData: PlacePageTrackData,
formatter: ElevationProfileFormatter = ElevationProfileFormatter(),
delegate: ElevationProfileViewControllerDelegate?) {
self.view = view
self.delegate = delegate
self.formatter = formatter
self.trackInfo = trackInfo
self.profileData = profileData
if let profileData {
self.trackData = trackData
if let profileData = trackData.elevationProfileData {
self.chartData = ElevationProfileChartData(profileData)
}
self.descriptionModels = Self.descriptionModels(for: trackInfo)
self.descriptionModels = Self.descriptionModels(for: trackData.trackInfo)
}
private static func descriptionModels(for trackInfo: TrackInfo) -> [DescriptionsViewModel] {
@@ -56,30 +57,37 @@ final class ElevationProfilePresenter: NSObject {
DescriptionsViewModel(title: L("elevation_profile_min_elevation"), value: trackInfo.minElevation, imageName: "ic_em_min_attitude_24")
]
}
deinit {
bookmarkManager.resetElevationActivePointChanged()
bookmarkManager.resetElevationMyPositionChanged()
}
}
extension ElevationProfilePresenter: ElevationProfilePresenterProtocol {
func update(trackInfo: TrackInfo, profileData: ElevationProfileData?) {
self.profileData = profileData
if let profileData {
func update(with trackData: PlacePageTrackData) {
self.trackData = trackData
if let profileData = trackData.elevationProfileData {
self.chartData = ElevationProfileChartData(profileData)
} else {
self.chartData = nil
}
descriptionModels = Self.descriptionModels(for: trackInfo)
descriptionModels = Self.descriptionModels(for: trackData.trackInfo)
configure()
}
func updateActivePoint(_ distance: Double) {
guard let view, !view.isChartViewInfoHidden else { return }
view.setActivePoint(distance)
}
func updateMyPosition(_ distance: Double) {
guard let view, !view.isChartViewInfoHidden else { return }
view.setMyPosition(distance)
}
func configure() {
view?.isChartViewHidden = false
let kMinPointsToDraw = 3
guard let profileData, let chartData, chartData.points.count >= kMinPointsToDraw else {
guard let profileData = trackData.elevationProfileData,
let chartData,
chartData.points.count >= kMinPointsToDraw else {
view?.userInteractionEnabled = false
return
}
@@ -93,14 +101,8 @@ extension ElevationProfilePresenter: ElevationProfilePresenterProtocol {
return
}
view?.setActivePoint(profileData.activePoint)
view?.setMyPosition(profileData.myPosition)
bookmarkManager.setElevationActivePointChanged(profileData.trackId) { [weak self] distance in
self?.view?.setActivePoint(distance)
}
bookmarkManager.setElevationMyPositionChanged(profileData.trackId) { [weak self] distance in
self?.view?.setMyPosition(distance)
}
view?.setActivePoint(trackData.activePoint)
view?.setMyPosition(trackData.myPosition)
}
func onDifficultyButtonPressed() {