[ios] refactor TrackRecordingInfo to only wrap the data from the core

This refactoring allows to split the data for the PP on 2 parts:
1. TrackRecordingInfo (dist, dur, acend, descend etc)
2. ElecationProfileData (only the points to draw)
Because the PP should be created only with the 1st one for the TrackRecordings (will be implemented later) and the PP shoul display all the info without the chart.
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-12-22 12:45:59 +04:00 committed by Roman Tsisyk
parent 438e923de5
commit a862a9ff10
4 changed files with 50 additions and 20 deletions

View file

@ -2,9 +2,13 @@
#include <CoreApi/Framework.h>
#include "map/gps_track_collection.hpp"
#include "map/elevation_info.hpp"
@interface TrackRecordingInfo (Core)
- (instancetype)initWithGpsTrackInfo:(GpsTrackInfo const &)info;
- (instancetype)initWithDistance:(double)distance duration:(double)duration;
- (void)setElevationInfo:(ElevationInfo const &)elevationInfo;
@end

View file

@ -4,12 +4,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface TrackRecordingInfo : NSObject
@property (nonatomic, readonly) NSString * distance;
@property (nonatomic, readonly) NSString * duration;
@property (nonatomic, readonly) NSString * ascent;
@property (nonatomic, readonly) NSString * descent;
@property (nonatomic, readonly) NSString * maxElevation;
@property (nonatomic, readonly) NSString * minElevation;
@property (nonatomic, readonly) double distance;
@property (nonatomic, readonly) double duration;
@property (nonatomic, readonly) NSUInteger ascent;
@property (nonatomic, readonly) NSUInteger descent;
@property (nonatomic, readonly) NSUInteger maxElevation;
@property (nonatomic, readonly) NSUInteger minElevation;
- (BOOL)hasElevationInfo;
+ (TrackRecordingInfo *)emptyInfo;

View file

@ -3,10 +3,12 @@
#import "DistanceFormatter.h"
#import "DurationFormatter.h"
#include "map/elevation_info.hpp"
@implementation TrackRecordingInfo
+ (TrackRecordingInfo *)emptyInfo {
return [[TrackRecordingInfo alloc] initWithGpsTrackInfo:GpsTrackInfo()];
- (BOOL)hasElevationInfo {
return _ascent != 0 || _descent != 0 || _maxElevation != 0 || _minElevation != 0;
}
@end
@ -15,14 +17,29 @@
- (instancetype)initWithGpsTrackInfo:(GpsTrackInfo const &)trackInfo {
if (self = [super init]) {
_distance = [DistanceFormatter distanceStringFromMeters:trackInfo.m_length];
_duration = [DurationFormatter durationStringFromTimeInterval:trackInfo.m_duration];
_ascent = [AltitudeFormatter altitudeStringFromMeters:trackInfo.m_ascent];
_descent = [AltitudeFormatter altitudeStringFromMeters:trackInfo.m_descent];
_maxElevation = [AltitudeFormatter altitudeStringFromMeters:trackInfo.m_maxElevation];
_minElevation = [AltitudeFormatter altitudeStringFromMeters:trackInfo.m_minElevation];
_distance = trackInfo.m_length;
_duration = trackInfo.m_duration;
_ascent = trackInfo.m_ascent;
_descent = trackInfo.m_descent;
_maxElevation = trackInfo.m_maxElevation;
_minElevation = trackInfo.m_minElevation;
}
return self;
}
- (instancetype)initWithDistance:(double)distance duration:(double)duration {
if (self = [super init]) {
_distance = distance;
_duration = duration;
}
return self;
}
- (void)setElevationInfo:(ElevationInfo const &)elevationInfo {
_ascent = elevationInfo.GetAscent();
_descent = elevationInfo.GetDescent();
_maxElevation = elevationInfo.GetMaxAltitude();
_minElevation = elevationInfo.GetMinAltitude();
}
@end

View file

@ -48,12 +48,19 @@ extension TrackRecordingLiveActivityManager: TrackRecordingActivityManager {
private extension TrackRecordingLiveActivityAttributes.ContentState {
init(trackInfo: TrackRecordingInfo) {
self.distance = StatisticsViewModel(key: "", value: trackInfo.distance)
self.duration = StatisticsViewModel(key: "", value: trackInfo.duration)
self.maxElevation = StatisticsViewModel(key: L("elevation_profile_max_elevation"), value: trackInfo.maxElevation)
self.minElevation = StatisticsViewModel(key: L("elevation_profile_min_elevation"), value: trackInfo.minElevation)
self.ascent = StatisticsViewModel(key: L("elevation_profile_ascent"), value: trackInfo.ascent)
self.descent = StatisticsViewModel(key: L("elevation_profile_descent"), value: trackInfo.descent)
let distance = DistanceFormatter.distanceString(fromMeters: trackInfo.distance)
let duration = DurationFormatter.durationString(from: trackInfo.duration)
let maxElevation = AltitudeFormatter.altitudeString(fromMeters: Double(trackInfo.maxElevation))
let minElevation = AltitudeFormatter.altitudeString(fromMeters: Double(trackInfo.minElevation))
let ascent = AltitudeFormatter.altitudeString(fromMeters: Double(trackInfo.ascent))
let descent = AltitudeFormatter.altitudeString(fromMeters: Double(trackInfo.descent))
self.distance = StatisticsViewModel(key: "", value: distance)
self.duration = StatisticsViewModel(key: "", value: duration)
self.maxElevation = StatisticsViewModel(key: L("elevation_profile_max_elevation"), value: maxElevation)
self.minElevation = StatisticsViewModel(key: L("elevation_profile_min_elevation"), value: minElevation)
self.ascent = StatisticsViewModel(key: L("elevation_profile_ascent"), value: ascent)
self.descent = StatisticsViewModel(key: L("elevation_profile_descent"), value: descent)
}
}