[ios] add API to get updates of the track recording state

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-10-11 23:17:12 +04:00 committed by Viktor Havaka
parent a2eaccc564
commit bfdae6bc79
8 changed files with 89 additions and 2 deletions

View file

@ -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 = "<group>"; };
ED49D75E2CEFA8C0004AF27E /* Product+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Product+Core.h"; sourceTree = "<group>"; };
ED49D7602CEFA8E1004AF27E /* Product+Core.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "Product+Core.mm"; sourceTree = "<group>"; };
ED7306F02D0C5D2400523AA1 /* TrackRecordingInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TrackRecordingInfo.h; sourceTree = "<group>"; };
ED7306F12D0C5D2400523AA1 /* TrackRecordingInfo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TrackRecordingInfo.mm; sourceTree = "<group>"; };
ED7306F22D0C5D2400523AA1 /* TrackRecordingInfo+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TrackRecordingInfo+Core.h"; sourceTree = "<group>"; };
ED965B092CD67A470049E39E /* DistanceFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DistanceFormatter.h; sourceTree = "<group>"; };
ED965B0A2CD67A470049E39E /* DistanceFormatter.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DistanceFormatter.mm; sourceTree = "<group>"; };
ED965B112CD67A9B0049E39E /* AltitudeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AltitudeFormatter.h; sourceTree = "<group>"; };
@ -244,6 +250,7 @@
470015F12342509C00EBF03D /* CoreApi */ = {
isa = PBXGroup;
children = (
ED7306F32D0C5D2400523AA1 /* TrackRecorder */,
ED965B0B2CD67A470049E39E /* Formatting */,
47F4F1F623A333280022FD56 /* Storage */,
9957FAE5237AE59C00855F48 /* Logger */,
@ -450,6 +457,16 @@
path = ElevationProfile;
sourceTree = "<group>";
};
ED7306F32D0C5D2400523AA1 /* TrackRecorder */ = {
isa = PBXGroup;
children = (
ED7306F02D0C5D2400523AA1 /* TrackRecordingInfo.h */,
ED7306F12D0C5D2400523AA1 /* TrackRecordingInfo.mm */,
ED7306F22D0C5D2400523AA1 /* TrackRecordingInfo+Core.h */,
);
path = TrackRecorder;
sourceTree = "<group>";
};
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 */,

View file

@ -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

View file

@ -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<MWMMapSearchResult *> *results, BOOL finished);
typedef void (^TrackRecordingUpdatedHandler)(TrackRecordingInfo * _Nonnull trackStatistics);
@protocol TrackRecorder <NSObject>
+ (void)startTrackRecording;
+ (void)setTrackRecordingUpdateHandler:(TrackRecordingUpdatedHandler _Nullable)trackRecordingDidUpdate;
+ (void)stopTrackRecording;
+ (void)saveTrackRecordingWithName:(nullable NSString *)name;
+ (BOOL)isTrackRecordingEnabled;

View file

@ -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();
}

View file

@ -0,0 +1,10 @@
#import "TrackRecordingInfo.h"
#include <CoreApi/Framework.h>
#include "map/gps_track_collection.hpp"
@interface TrackRecordingInfo (Core)
- (instancetype)initWithGpsTrackInfo:(GpsTrackInfo const &)info;
@end

View file

@ -0,0 +1,16 @@
#import <Foundation/Foundation.h>
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

View file

@ -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

View file

@ -66,7 +66,7 @@ std::pair<size_t, size_t> GpsTrackCollection::Add(std::vector<TItem> 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<double>(m_trackInfo.m_maxElevation), item.m_altitude);
m_trackInfo.m_minElevation = std::min(static_cast<double>(m_trackInfo.m_minElevation), item.m_altitude);
@ -106,7 +106,7 @@ std::pair<size_t, size_t> GpsTrackCollection::Clear(bool resetIds)
m_items.clear();
m_items.shrink_to_fit();
m_trackInfo = GpsTrackInfo();
m_trackInfo = {};
if (resetIds)
m_lastId = 0;