[ios] subscribe on the ElevationInfo updates when the TR PP is opened

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2025-01-09 16:35:31 +04:00
parent 1c6bedf230
commit 867778c368
10 changed files with 107 additions and 14 deletions

View file

@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
@class PlacePageScheduleData;
@class TrackInfo;
typedef NS_ENUM(NSInteger, PlacePageDataHotelType) {
PlacePageDataHotelTypeHotel,
@ -39,6 +40,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) PlacePageDataSchedule schedule;
@property(nonatomic, readonly) BOOL isMyPosition;
- (instancetype)initWithTrackInfo:(TrackInfo * _Nonnull)trackInfo;
@end
NS_ASSUME_NONNULL_END

View file

@ -1,4 +1,8 @@
#import "PlacePagePreviewData+Core.h"
#import "DistanceFormatter.h"
#import "AltitudeFormatter.h"
#import "DurationFormatter.h"
#import "TrackInfo.h"
#include "3party/opening_hours/opening_hours.hpp"
@ -46,6 +50,18 @@ static PlacePageDataSchedule convertOpeningHours(std::string_view rawOH)
@implementation PlacePagePreviewData
- (instancetype)initWithTrackInfo:(TrackInfo * _Nonnull)trackInfo {
self = [super init];
if (self) {
// TODO: (KK) Replace separator with a shared static constant.
NSString * kSeparator = @" • ";
NSString * duration = [DurationFormatter durationStringFromTimeInterval:trackInfo.duration];
NSString * distance = [DistanceFormatter distanceStringFromMeters:trackInfo.distance];
_title = [@[duration, distance] componentsJoinedByString:kSeparator];
}
return self;
}
@end
@implementation PlacePagePreviewData (Core)

View file

@ -10,8 +10,10 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) MWMTrackID trackId;
@property(nonatomic, readonly) MWMMarkGroupID groupId;
@property(nonatomic, readonly, nonnull) TrackInfo * trackInfo;
@property(nonatomic, readonly, nullable) ElevationProfileData * elevationProfileData;
@property(nonatomic, readwrite, nonnull) TrackInfo * trackInfo;
@property(nonatomic, readwrite, nullable) ElevationProfileData * elevationProfileData;
- (instancetype)initWithTrackInfo:(TrackInfo * _Nonnull)trackInfo elevationInfo:(ElevationProfileData * _Nullable)elevationInfo;
@end

View file

@ -4,6 +4,15 @@
@implementation PlacePageTrackData
- (nonnull instancetype)initWithTrackInfo:(TrackInfo *)trackInfo elevationInfo:(ElevationProfileData * _Nullable)elevationInfo {
self = [super init];
if (self) {
_trackInfo = trackInfo;
_elevationProfileData = elevationInfo;
}
return self;
}
@end
@implementation PlacePageTrackData (Core)

View file

@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
elevationInfo:(ElevationInfo const &)elevationInfo
activePoint:(double)activePoint
myPosition:(double)myPosition;
- (instancetype)initWithElevationInfo:(ElevationInfo const &)elevationInfo;
@end

View file

@ -13,6 +13,7 @@ typedef NS_ENUM(NSInteger, ElevationDifficulty) {
@interface ElevationProfileData : NSObject
@property(nonatomic, readonly) uint64_t trackId;
@property(nonatomic, readonly) BOOL isTrackRecording;
@property(nonatomic, readonly) ElevationDifficulty difficulty;
@property(nonatomic, readonly) NSArray<ElevationHeightPoint *> * points;
@property(nonatomic, readonly) double activePoint;

View file

@ -30,23 +30,36 @@ static ElevationDifficulty convertDifficulty(uint8_t difficulty) {
if (self) {
_trackId = trackId;
_difficulty = convertDifficulty(elevationInfo.GetDifficulty());
auto const & points = elevationInfo.GetPoints();
NSMutableArray * pointsArray = [[NSMutableArray alloc] initWithCapacity:points.size()];
for (auto const & point : points) {
auto pointLatLon = mercator::ToLatLon(point.m_point.GetPoint());
CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(pointLatLon.m_lat, pointLatLon.m_lon);
ElevationHeightPoint * elevationPoint = [[ElevationHeightPoint alloc] initWithCoordinates:coordinates
distance:point.m_distance
andAltitude:point.m_point.GetAltitude()];
[pointsArray addObject:elevationPoint];
}
_points = [pointsArray copy];
_points = [ElevationProfileData pointsFromElevationInfo:elevationInfo];
_activePoint = activePoint;
_myPosition = myPosition;
_isTrackRecording = false;
}
return self;
}
- (instancetype)initWithElevationInfo:(ElevationInfo const &)elevationInfo {
self = [super init];
if (self) {
_difficulty = convertDifficulty(elevationInfo.GetDifficulty());
_points = [ElevationProfileData pointsFromElevationInfo:elevationInfo];
_isTrackRecording = true;
}
return self;
}
+ (NSArray<ElevationHeightPoint *> *)pointsFromElevationInfo:(ElevationInfo const &)elevationInfo {
auto const & points = elevationInfo.GetPoints();
NSMutableArray * pointsArray = [[NSMutableArray alloc] initWithCapacity:points.size()];
for (auto const & point : points) {
auto pointLatLon = mercator::ToLatLon(point.m_point.GetPoint());
CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(pointLatLon.m_lat, pointLatLon.m_lon);
ElevationHeightPoint * elevationPoint = [[ElevationHeightPoint alloc] initWithCoordinates:coordinates
distance:point.m_distance
andAltitude:point.m_point.GetAltitude()];
[pointsArray addObject:elevationPoint];
}
return [pointsArray copy];
}
@end

View file

@ -10,6 +10,7 @@
@class PlacePageBookmarkData;
@class MWMMapNodeAttributes;
@class TrackInfo;
@class ElevationProfileData;
typedef NS_ENUM(NSInteger, PlacePageRoadType) {
PlacePageRoadTypeToll,
@ -49,12 +50,15 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) CLLocationCoordinate2D locationCoordinate;
@property(nonatomic, copy, nullable) MWMVoidBlock onBookmarkStatusUpdate;
@property(nonatomic, copy, nullable) MWMVoidBlock onMapNodeStatusUpdate;
@property(nonatomic, copy, nullable) MWMVoidBlock onTrackRecordingProgressUpdate;
@property(nonatomic, copy, nullable) void (^onMapNodeProgressUpdate)(uint64_t downloadedBytes, uint64_t totalBytes);
- (instancetype)initWithLocalizationProvider:(id<IOpeningHoursLocalization>)localization;
- (instancetype)initWithTrackInfo:(TrackInfo * _Nonnull)trackInfo elevationInfo:(ElevationProfileData * _Nullable)elevationInfo;
- (instancetype)init NS_UNAVAILABLE;
- (void)updateBookmarkStatus;
- (void)updateWithTrackInfo:(TrackInfo * _Nonnull)trackInfo elevationInfo:(ElevationProfileData * _Nullable)elevationInfo;
@end

View file

@ -5,6 +5,7 @@
#import "PlacePageInfoData+Core.h"
#import "PlacePageBookmarkData+Core.h"
#import "PlacePageTrackData+Core.h"
#import "ElevationProfileData+Core.h"
#import "MWMMapNodeAttributes.h"
#include <CoreApi/CoreApi.h>
@ -84,6 +85,25 @@ static PlacePageRoadType convertRoadType(RoadWarningMarkType roadType) {
return self;
}
- (instancetype)initWithTrackInfo:(TrackInfo * _Nonnull)trackInfo elevationInfo:(ElevationProfileData * _Nullable)elevationInfo {
self = [super init];
if (self) {
_objectType = PlacePageObjectTypeTrackRecording;
_roadType = PlacePageRoadTypeNone;
_previewData = [[PlacePagePreviewData alloc] initWithTrackInfo:trackInfo];
_trackData = [[PlacePageTrackData alloc] initWithTrackInfo:trackInfo elevationInfo:elevationInfo];
}
return self;
}
- (void)updateWithTrackInfo:(TrackInfo * _Nonnull)trackInfo elevationInfo:(ElevationProfileData * _Nullable)elevationInfo {
_previewData = [[PlacePagePreviewData alloc] initWithTrackInfo:trackInfo];
_trackData.trackInfo = trackInfo;
_trackData.elevationProfileData = elevationInfo;
if (self.onTrackRecordingProgressUpdate != nil)
self.onTrackRecordingProgressUpdate();
}
- (void)dealloc {
if (self.mapNodeAttributes != nil) {
[[MWMStorage sharedStorage] removeObserver:self];

View file

@ -118,6 +118,28 @@ NSString *const kSettingsSegue = @"Map2Settings";
#pragma mark - Map Navigation
- (void)showTrackRecordingPlacePage {
__block PlacePageData * placePageData = [[PlacePageData alloc] initWithTrackInfo:TrackRecordingManager.shared.trackRecordingInfo
elevationInfo:[MWMFrameworkHelper trackRecordingElevationInfo]];
[TrackRecordingManager.shared addObserver:self recordingIsActiveDidChangeHandler:^(TrackRecordingState state, TrackInfo * _Nonnull trackInfo) {
switch (state) {
case TrackRecordingStateInactive:
[self stopObservingTrackRecordingUpdates];
break;
case TrackRecordingStateActive:
if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive)
return;
[placePageData updateWithTrackInfo:trackInfo elevationInfo:[MWMFrameworkHelper trackRecordingElevationInfo]];
break;
}
}];
[self showOrUpdatePlacePage:placePageData];
}
- (void)stopObservingTrackRecordingUpdates {
[TrackRecordingManager.shared removeObserver:self];
}
- (void)showOrUpdatePlacePage:(PlacePageData *)data {
if (self.searchManager.isSearching)
[self.searchManager setPlaceOnMapSelected:YES];
@ -190,6 +212,7 @@ NSString *const kSettingsSegue = @"Map2Settings";
}
- (void)hideRegularPlacePage {
[self stopObservingTrackRecordingUpdates];
[self.placePageVC closeAnimatedWithCompletion:^{
[self.placePageVC.view removeFromSuperview];
[self.placePageVC willMoveToParentViewController:nil];
@ -233,6 +256,7 @@ NSString *const kSettingsSegue = @"Map2Settings";
return;
}
PlacePageData * data = [[PlacePageData alloc] initWithLocalizationProvider:[[OpeinigHoursLocalization alloc] init]];
[self stopObservingTrackRecordingUpdates];
[self showOrUpdatePlacePage:data];
}