diff --git a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj index 1c0c86d49e..42a28ce545 100644 --- a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj +++ b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj @@ -92,6 +92,9 @@ ED49D75B2CEF8BD2004AF27E /* ProductsConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED49D7562CEF850F004AF27E /* ProductsConfiguration.swift */; }; ED49D75F2CEFA8C0004AF27E /* Product+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = ED49D75E2CEFA8C0004AF27E /* Product+Core.h */; }; ED49D7612CEFA8E1004AF27E /* Product+Core.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED49D7602CEFA8E1004AF27E /* Product+Core.mm */; }; + ED7306F42D0C5D2400523AA1 /* TrackRecordingInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED7306F12D0C5D2400523AA1 /* TrackRecordingInfo.mm */; }; + ED7306F52D0C5D2400523AA1 /* TrackRecordingInfo+Core.h in Headers */ = {isa = PBXBuildFile; fileRef = ED7306F22D0C5D2400523AA1 /* TrackRecordingInfo+Core.h */; }; + ED7306F62D0C5D2400523AA1 /* TrackRecordingInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = ED7306F02D0C5D2400523AA1 /* TrackRecordingInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; ED965B0D2CD67A470049E39E /* DistanceFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED965B0A2CD67A470049E39E /* DistanceFormatter.mm */; }; ED965B102CD67A470049E39E /* DistanceFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = ED965B092CD67A470049E39E /* DistanceFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; ED965B132CD67A9B0049E39E /* AltitudeFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED965B122CD67A9B0049E39E /* AltitudeFormatter.mm */; }; @@ -197,6 +200,9 @@ ED49D7562CEF850F004AF27E /* ProductsConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductsConfiguration.swift; sourceTree = ""; }; ED49D75E2CEFA8C0004AF27E /* Product+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Product+Core.h"; sourceTree = ""; }; ED49D7602CEFA8E1004AF27E /* Product+Core.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "Product+Core.mm"; sourceTree = ""; }; + ED7306F02D0C5D2400523AA1 /* TrackRecordingInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TrackRecordingInfo.h; sourceTree = ""; }; + ED7306F12D0C5D2400523AA1 /* TrackRecordingInfo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TrackRecordingInfo.mm; sourceTree = ""; }; + ED7306F22D0C5D2400523AA1 /* TrackRecordingInfo+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TrackRecordingInfo+Core.h"; sourceTree = ""; }; ED965B092CD67A470049E39E /* DistanceFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DistanceFormatter.h; sourceTree = ""; }; ED965B0A2CD67A470049E39E /* DistanceFormatter.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DistanceFormatter.mm; sourceTree = ""; }; ED965B112CD67A9B0049E39E /* AltitudeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AltitudeFormatter.h; sourceTree = ""; }; @@ -244,6 +250,7 @@ 470015F12342509C00EBF03D /* CoreApi */ = { isa = PBXGroup; children = ( + ED7306F32D0C5D2400523AA1 /* TrackRecorder */, ED965B0B2CD67A470049E39E /* Formatting */, 47F4F1F623A333280022FD56 /* Storage */, 9957FAE5237AE59C00855F48 /* Logger */, @@ -450,6 +457,16 @@ path = ElevationProfile; sourceTree = ""; }; + ED7306F32D0C5D2400523AA1 /* TrackRecorder */ = { + isa = PBXGroup; + children = ( + ED7306F02D0C5D2400523AA1 /* TrackRecordingInfo.h */, + ED7306F12D0C5D2400523AA1 /* TrackRecordingInfo.mm */, + ED7306F22D0C5D2400523AA1 /* TrackRecordingInfo+Core.h */, + ); + path = TrackRecorder; + sourceTree = ""; + }; ED965B0B2CD67A470049E39E /* Formatting */ = { isa = PBXGroup; children = ( @@ -488,6 +505,8 @@ ED965B102CD67A470049E39E /* DistanceFormatter.h in Headers */, 47942D6D237CC3E300DEFAE3 /* PlacePagePreviewData.h in Headers */, 47CA68DD2502022400671019 /* MWMBookmark.h in Headers */, + ED7306F52D0C5D2400523AA1 /* TrackRecordingInfo+Core.h in Headers */, + ED7306F62D0C5D2400523AA1 /* TrackRecordingInfo.h in Headers */, 9940622023EAC57900493D1A /* ElevationHeightPoint.h in Headers */, 9957FACE237AB01400855F48 /* DeepLinkParser.h in Headers */, 9974CA2D23DF197B003FE824 /* ElevationProfileData+Core.h in Headers */, @@ -625,6 +644,7 @@ 479F7062234FBC4700011E2E /* MWMCarPlayBookmarkObject.mm in Sources */, 47942D6C237CC3DE00DEFAE3 /* PlacePageData.mm in Sources */, 479F705E234FBB8C00011E2E /* MWMBookmarkGroup.m in Sources */, + ED7306F42D0C5D2400523AA1 /* TrackRecordingInfo.mm in Sources */, 47F0D2162516847F00BC685E /* MWMBookmarksSection.m in Sources */, 479F7057234FB7F200011E2E /* MWMBookmarksManager.mm in Sources */, 47942D71237CC40800DEFAE3 /* PlacePageInfoData.mm in Sources */, diff --git a/iphone/CoreApi/CoreApi/CoreApi.h b/iphone/CoreApi/CoreApi/CoreApi.h index 04a623aec9..5589e59f14 100644 --- a/iphone/CoreApi/CoreApi/CoreApi.h +++ b/iphone/CoreApi/CoreApi/CoreApi.h @@ -31,6 +31,7 @@ FOUNDATION_EXPORT const unsigned char CoreApiVersionString[]; #import "CoreApi/DistanceFormatter.h" #import "CoreApi/AltitudeFormatter.h" #import "CoreApi/DurationFormatter.h" +#import "CoreApi/TrackRecordingInfo.h" #pragma mark - Place Page diff --git a/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.h b/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.h index c9c06a2fe7..14b92d4298 100644 --- a/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.h +++ b/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.h @@ -4,6 +4,7 @@ #import "MWMTypes.h" @class MWMMapSearchResult; +@class TrackRecordingInfo; typedef NS_ENUM(NSUInteger, MWMZoomMode) { MWMZoomModeIn = 0, MWMZoomModeOut }; @@ -17,10 +18,12 @@ typedef NS_ENUM(NSInteger, ProductsPopupCloseReason) { NS_ASSUME_NONNULL_BEGIN typedef void (^SearchInDownloaderCompletions)(NSArray *results, BOOL finished); +typedef void (^TrackRecordingUpdatedHandler)(TrackRecordingInfo * _Nonnull trackStatistics); @protocol TrackRecorder + (void)startTrackRecording; ++ (void)setTrackRecordingUpdateHandler:(TrackRecordingUpdatedHandler _Nullable)trackRecordingDidUpdate; + (void)stopTrackRecording; + (void)saveTrackRecordingWithName:(nullable NSString *)name; + (BOOL)isTrackRecordingEnabled; diff --git a/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.mm b/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.mm index 30c826bedc..6a696d2885 100644 --- a/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.mm +++ b/iphone/CoreApi/CoreApi/Framework/MWMFrameworkHelper.mm @@ -2,6 +2,7 @@ #import "MWMMapSearchResult+Core.h" #import "ProductsConfiguration+Core.h" #import "Product+Core.h" +#import "TrackRecordingInfo+Core.h" #include "Framework.h" @@ -217,6 +218,18 @@ static Framework::ProductsPopupCloseReason ConvertProductPopupCloseReasonToCore( GetFramework().StartTrackRecording(); } ++ (void)setTrackRecordingUpdateHandler:(TrackRecordingUpdatedHandler _Nullable)trackRecordingDidUpdate { + if (!trackRecordingDidUpdate) + { + GetFramework().SetTrackRecordingUpdateHandler(nullptr); + return; + } + GetFramework().SetTrackRecordingUpdateHandler([trackRecordingDidUpdate](GpsTrackInfo const & gpsTrackInfo) { + TrackRecordingInfo * info = [[TrackRecordingInfo alloc] initWithGpsTrackInfo:gpsTrackInfo]; + trackRecordingDidUpdate(info); + }); +} + + (void)stopTrackRecording { GetFramework().StopTrackRecording(); } diff --git a/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo+Core.h b/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo+Core.h new file mode 100644 index 0000000000..969b4c2374 --- /dev/null +++ b/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo+Core.h @@ -0,0 +1,10 @@ +#import "TrackRecordingInfo.h" + +#include +#include "map/gps_track_collection.hpp" + +@interface TrackRecordingInfo (Core) + +- (instancetype)initWithGpsTrackInfo:(GpsTrackInfo const &)info; + +@end diff --git a/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo.h b/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo.h new file mode 100644 index 0000000000..6289e90c0b --- /dev/null +++ b/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo.h @@ -0,0 +1,16 @@ +#import + +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; + +@end + +NS_ASSUME_NONNULL_END diff --git a/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo.mm b/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo.mm new file mode 100644 index 0000000000..1cdc8f1d00 --- /dev/null +++ b/iphone/CoreApi/CoreApi/TrackRecorder/TrackRecordingInfo.mm @@ -0,0 +1,24 @@ +#import "TrackRecordingInfo+Core.h" +#import "AltitudeFormatter.h" +#import "DistanceFormatter.h" +#import "DurationFormatter.h" + +@implementation TrackRecordingInfo + +@end + +@implementation TrackRecordingInfo (Core) + +- (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]; + } + return self; +} + +@end diff --git a/map/gps_track_collection.cpp b/map/gps_track_collection.cpp index 8de210f690..42ca892e6b 100644 --- a/map/gps_track_collection.cpp +++ b/map/gps_track_collection.cpp @@ -66,7 +66,7 @@ std::pair GpsTrackCollection::Add(std::vector const & ite if (item.m_altitude > lastItem.m_altitude) m_trackInfo.m_ascent += deltaAltitude; if (item.m_altitude < lastItem.m_altitude) - m_trackInfo.m_descent += deltaAltitude; + m_trackInfo.m_descent -= deltaAltitude; m_trackInfo.m_maxElevation = std::max(static_cast(m_trackInfo.m_maxElevation), item.m_altitude); m_trackInfo.m_minElevation = std::min(static_cast(m_trackInfo.m_minElevation), item.m_altitude); @@ -106,7 +106,7 @@ std::pair GpsTrackCollection::Clear(bool resetIds) m_items.clear(); m_items.shrink_to_fit(); - m_trackInfo = GpsTrackInfo(); + m_trackInfo = {}; if (resetIds) m_lastId = 0;