From 2861d9db2ae09aa2d9e0d3fdba30219ffbfcbbe9 Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Wed, 4 Jun 2025 19:43:44 +0400 Subject: [PATCH] [ios] replase ints/doubles with string for track stats in ios to pass already formatted by the core values instead of formatting them later using the same core formatters Signed-off-by: Kiryl Kaveryn --- iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.h | 14 +++++------ iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.mm | 24 +++++++++---------- .../TrackRecordingActivityManager.swift | 19 +++++---------- .../ElevationProfilePresenter.swift | 4 ++-- .../Layouts/PlacePageTrackLayout.swift | 2 +- 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.h b/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.h index e4d63bbb9..8a4e3f5f9 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.h +++ b/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.h @@ -4,14 +4,14 @@ NS_ASSUME_NONNULL_BEGIN @interface TrackInfo : NSObject -@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; +@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; -- (BOOL)hasElevationInfo; +@property (nonatomic, readonly) BOOL hasElevationInfo; + (TrackInfo *)emptyInfo; diff --git a/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.mm b/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.mm index a6fa37597..64803f191 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.mm +++ b/iphone/CoreApi/CoreApi/Bookmarks/TrackInfo.mm @@ -1,14 +1,8 @@ #import "TrackInfo+Core.h" -#import "AltitudeFormatter.h" -#import "DistanceFormatter.h" -#import "DurationFormatter.h" +#import "StringUtils.h" @implementation TrackInfo -- (BOOL)hasElevationInfo { - return _ascent != 0 || _descent != 0 || _maxElevation != 0 || _minElevation != 0; -} - + (TrackInfo *)emptyInfo { return [[TrackInfo alloc] init]; } @@ -19,12 +13,16 @@ - (instancetype)initWithTrackStatistics:(TrackStatistics const &)statistics { if (self = [super init]) { - _distance = statistics.m_length; - _duration = statistics.m_duration; - _ascent = statistics.m_ascent; - _descent = statistics.m_descent; - _maxElevation = statistics.m_maxElevation; - _minElevation = statistics.m_minElevation; + _distance = ToNSString(statistics.GetFormattedLength()); + _duration = ToNSString(statistics.GetFormattedDuration()); + _ascent = ToNSString(statistics.GetFormattedAscent()); + _descent = ToNSString(statistics.GetFormattedDescent()); + _maxElevation = ToNSString(statistics.GetFormattedMaxElevation()); + _minElevation = ToNSString(statistics.GetFormattedMinElevation()); + _hasElevationInfo = statistics.m_ascent != 0 || + statistics.m_descent != 0 || + statistics.m_maxElevation != 0 || + statistics.m_minElevation != 0; } return self; } diff --git a/iphone/Maps/Core/TrackRecorder/TrackRecordingActivityManager.swift b/iphone/Maps/Core/TrackRecorder/TrackRecordingActivityManager.swift index 5df98663b..d2ea6ed22 100644 --- a/iphone/Maps/Core/TrackRecorder/TrackRecordingActivityManager.swift +++ b/iphone/Maps/Core/TrackRecorder/TrackRecordingActivityManager.swift @@ -48,19 +48,12 @@ extension TrackRecordingLiveActivityManager: TrackRecordingActivityManager { private extension TrackRecordingLiveActivityAttributes.ContentState { init(trackInfo: TrackInfo) { - 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) + 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) } } diff --git a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift index 585ae633a..0211a6672 100644 --- a/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift +++ b/iphone/Maps/UI/PlacePage/Components/ElevationProfile/ElevationProfilePresenter.swift @@ -16,7 +16,7 @@ protocol ElevationProfileViewControllerDelegate: AnyObject { fileprivate struct DescriptionsViewModel { let title: String - let value: UInt + let value: String let imageName: String } @@ -117,7 +117,7 @@ extension ElevationProfilePresenter { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(cell: ElevationProfileDescriptionCell.self, indexPath: indexPath) let model = descriptionModels[indexPath.row] - cell.configure(subtitle: model.title, value: formatter.yAxisString(from: Double(model.value)), imageName: model.imageName) + cell.configure(subtitle: model.title, value: model.value, imageName: model.imageName) return cell } } diff --git a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageTrackLayout.swift b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageTrackLayout.swift index bde3c68ab..f93d9e800 100644 --- a/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageTrackLayout.swift +++ b/iphone/Maps/UI/PlacePage/PlacePageLayout/Layouts/PlacePageTrackLayout.swift @@ -43,7 +43,7 @@ class PlacePageTrackLayout: IPlacePageLayout { }() lazy var elevationMapViewController: ElevationProfileViewController? = { - guard trackData.trackInfo.hasElevationInfo(), + guard trackData.trackInfo.hasElevationInfo, let elevationProfileData = trackData.elevationProfileData else { return nil }