From 8efd7d30acefc58d20dae80a5138493a71e65242 Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Tue, 5 Nov 2024 16:16:30 +0400 Subject: [PATCH] [ios] refactor CoreApi to support the Track selection and ElevationProfile 1. setElevationActivePoint is changed to work withe the CLLocationCoordinate2D that allows to pass the selected point to the core and show the blue mark on the track in the correct place 2. initWithElevationInfo is removed from the PlacePagePreviewData because the elevation profile is a part of track now and the PP header is configured in the core 3. ElevationHeightPoint stores the coordinates for easily track marks creation 4. add PlacePageTrackData to the PlacePageDate Signed-off-by: Kiryl Kaveryn --- .../CoreApi/Bookmarks/MWMBookmarksManager.h | 5 ++-- .../CoreApi/Bookmarks/MWMBookmarksManager.mm | 5 ++-- .../Common/PlacePagePreviewData.h | 13 ++++----- .../Common/PlacePagePreviewData.mm | 12 ++++---- .../ElevationProfile/ElevationHeightPoint.h | 4 ++- .../ElevationProfile/ElevationHeightPoint.m | 3 +- .../ElevationProfileData+Core.h | 8 +++-- .../ElevationProfile/ElevationProfileData.h | 8 +---- .../ElevationProfile/ElevationProfileData.mm | 29 +++++++++++-------- .../CoreApi/PlacePageData/PlacePageData.h | 13 +++++++-- .../CoreApi/PlacePageData/PlacePageData.mm | 9 ++++-- .../Classes/Share/MWMShareActivityItem.mm | 6 ++-- 12 files changed, 66 insertions(+), 49 deletions(-) diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h index e23bb0d857..47cd173dbc 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.h @@ -1,9 +1,10 @@ +#import + #import "MWMTypes.h" #import "MWMBookmarksObserver.h" #import "PlacePageBookmarkData.h" -@class CLLocation; @class MWMBookmark; @class MWMBookmarkGroup; @class MWMBookmarksSection; @@ -157,7 +158,7 @@ NS_SWIFT_NAME(BookmarksManager) + (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable("call +manager instead"))); + (instancetype) new __attribute__((unavailable("call +manager instead"))); -- (void)setElevationActivePoint:(double)distance trackId:(uint64_t)trackId; +- (void)setElevationActivePoint:(CLLocationCoordinate2D)point distance:(double)distance trackId:(uint64_t)trackId; - (void)setElevationActivePointChanged:(uint64_t)trackId callback:(ElevationPointChangedBlock)callback; - (void)resetElevationActivePointChanged; - (void)setElevationMyPositionChanged:(uint64_t)trackId callback:(ElevationPointChangedBlock)callback; diff --git a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm index c8be851587..acfa3d617b 100644 --- a/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm +++ b/iphone/CoreApi/CoreApi/Bookmarks/MWMBookmarksManager.mm @@ -830,9 +830,8 @@ static KmlFileType convertFileTypeToCore(MWMKmlFileType fileType) { } } -- (void)setElevationActivePoint:(double)distance trackId:(uint64_t)trackId { - // TODO: Pass correct coordinates to show mark point on the map - self.bm.SetElevationActivePoint(trackId, {0,0}, distance); +- (void)setElevationActivePoint:(CLLocationCoordinate2D)point distance:(double)distance trackId:(uint64_t)trackId { + self.bm.SetElevationActivePoint(trackId, mercator::FromLatLon(point.latitude, point.longitude), distance); } - (void)setElevationActivePointChanged:(uint64_t)trackId callback:(ElevationPointChangedBlock)callback { diff --git a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h index f0f91b7d46..ab25289cb4 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.h @@ -15,16 +15,16 @@ typedef NS_ENUM(NSInteger, PlacePageDataHotelType) { }; typedef NS_ENUM(NSInteger, PlacePageDataOpeningHours) { + PlacePageDataOpeningHoursUnknown, PlacePageDataOpeningHoursAllDay, PlacePageDataOpeningHoursOpen, - PlacePageDataOpeningHoursClosed, - PlacePageDataOpeningHoursUnknown + PlacePageDataOpeningHoursClosed }; typedef struct { - PlacePageDataOpeningHours state; - time_t nextTimeOpen; - time_t nextTimeClosed; + PlacePageDataOpeningHours state; + time_t nextTimeOpen; + time_t nextTimeClosed; } PlacePageDataSchedule; NS_ASSUME_NONNULL_BEGIN @@ -35,10 +35,9 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, nullable) NSString *secondaryTitle; @property(nonatomic, readonly, nullable) NSString *subtitle; @property(nonatomic, readonly, nullable) NSString *coordinates; -@property(nonatomic, readonly, nullable) NSString *address; +@property(nonatomic, readonly, nullable) NSString *secondarySubtitle; @property(nonatomic, readonly) PlacePageDataSchedule schedule; @property(nonatomic, readonly) BOOL isMyPosition; -//@property(nonatomic, readonly) BOOL isPopular; @end diff --git a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm index 8f4fa09606..9aed885cbb 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm +++ b/iphone/CoreApi/CoreApi/PlacePageData/Common/PlacePagePreviewData.mm @@ -56,11 +56,13 @@ static PlacePageDataSchedule convertOpeningHours(std::string_view rawOH) _title = rawData.GetTitle().empty() ? nil : @(rawData.GetTitle().c_str()); _secondaryTitle = rawData.GetSecondaryTitle().empty() ? nil : @(rawData.GetSecondaryTitle().c_str()); _subtitle = rawData.GetSubtitle().empty() ? nil : @(rawData.GetSubtitle().c_str()); - _coordinates = @(rawData.GetFormattedCoordinate(place_page::CoordinatesFormat::LatLonDMS).c_str()); - _address = rawData.GetSecondarySubtitle().empty() ? nil : @(rawData.GetSecondarySubtitle().c_str()); - _isMyPosition = rawData.IsMyPosition(); - //_isPopular = rawData.GetPopularity() > 0; - _schedule = convertOpeningHours(rawData.GetOpeningHours()); + _secondarySubtitle = rawData.GetSecondarySubtitle().empty() ? nil : @(rawData.GetSecondarySubtitle().c_str()); + + if (!rawData.IsTrack()) { + _coordinates = @(rawData.GetFormattedCoordinate(place_page::CoordinatesFormat::LatLonDMS).c_str()); + _isMyPosition = rawData.IsMyPosition(); + _schedule = convertOpeningHours(rawData.GetOpeningHours()); + } } return self; } diff --git a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.h b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.h index e5982da5ea..c306de353c 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.h @@ -1,13 +1,15 @@ #import +#import NS_ASSUME_NONNULL_BEGIN @interface ElevationHeightPoint : NSObject +@property(nonatomic, readonly) CLLocationCoordinate2D coordinates; @property(nonatomic, readonly) double distance; @property(nonatomic, readonly) double altitude; -- (instancetype)initWithDistance:(double)distance andAltitude:(double)altitude; +- (instancetype)initWithCoordinates:(CLLocationCoordinate2D)coordinates distance:(double)distance andAltitude:(double)altitude; @end diff --git a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.m b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.m index 84346997d2..807b1d9ff7 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.m +++ b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationHeightPoint.m @@ -2,9 +2,10 @@ @implementation ElevationHeightPoint -- (instancetype)initWithDistance:(double)distance andAltitude:(double)altitude { +- (instancetype)initWithCoordinates:(CLLocationCoordinate2D)coordinates distance:(double)distance andAltitude:(double)altitude { self = [super init]; if (self) { + _coordinates = coordinates; _distance = distance; _altitude = altitude; } diff --git a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData+Core.h b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData+Core.h index c94b5000da..48c63cde20 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData+Core.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData+Core.h @@ -1,4 +1,5 @@ #import "ElevationProfileData.h" +#import "MWMTypes.h" #include "map/elevation_info.hpp" @@ -6,9 +7,10 @@ NS_ASSUME_NONNULL_BEGIN @interface ElevationProfileData (Core) -- (instancetype)initWithElevationInfo:(ElevationInfo const &)elevationInfo - activePoint:(double)activePoint - myPosition:(double)myPosition; +- (instancetype)initWithTrackId:(MWMTrackID)trackId + elevationInfo:(ElevationInfo const &)elevationInfo + activePoint:(double)activePoint + myPosition:(double)myPosition; @end diff --git a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.h b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.h index 54f6e110a2..f8b5a070e3 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.h @@ -13,14 +13,8 @@ typedef NS_ENUM(NSInteger, ElevationDifficulty) { @interface ElevationProfileData : NSObject @property(nonatomic, readonly) uint64_t trackId; -@property(nonatomic, readonly) NSString *serverId; -@property(nonatomic, readonly) NSUInteger ascent; -@property(nonatomic, readonly) NSUInteger descent; -@property(nonatomic, readonly) NSUInteger maxAttitude; -@property(nonatomic, readonly) NSUInteger minAttitude; @property(nonatomic, readonly) ElevationDifficulty difficulty; -@property(nonatomic, readonly) NSUInteger trackTime; -@property(nonatomic, readonly) NSArray *points; +@property(nonatomic, readonly) NSArray * points; @property(nonatomic, readonly) double activePoint; @property(nonatomic, readonly) double myPosition; diff --git a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.mm b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.mm index 183b54a67f..69e89c9388 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.mm +++ b/iphone/CoreApi/CoreApi/PlacePageData/ElevationProfile/ElevationProfileData.mm @@ -1,5 +1,7 @@ #import "ElevationProfileData+Core.h" +#include "geometry/mercator.hpp" + static ElevationDifficulty convertDifficulty(uint8_t difficulty) { switch (difficulty) { case ElevationInfo::Difficulty::Easy: @@ -20,21 +22,24 @@ static ElevationDifficulty convertDifficulty(uint8_t difficulty) { @implementation ElevationProfileData (Core) -- (instancetype)initWithElevationInfo:(ElevationInfo const &)elevationInfo - activePoint:(double)activePoint - myPosition:(double)myPosition { +- (instancetype)initWithTrackId:(MWMTrackID)trackId + elevationInfo:(ElevationInfo const &)elevationInfo + activePoint:(double)activePoint + myPosition:(double)myPosition { self = [super init]; if (self) { - _ascent = elevationInfo.GetAscent(); - _descent = elevationInfo.GetDescent(); - _maxAttitude = elevationInfo.GetMaxAltitude(); - _minAttitude = elevationInfo.GetMinAltitude(); + _trackId = trackId; _difficulty = convertDifficulty(elevationInfo.GetDifficulty()); - NSMutableArray *pointsArray = [NSMutableArray array]; - for (auto const &p : elevationInfo.GetPoints()) { - ElevationHeightPoint *point = [[ElevationHeightPoint alloc] initWithDistance:p.m_distance - andAltitude:p.m_point.GetAltitude()]; - [pointsArray addObject:point]; + + 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]; _activePoint = activePoint; diff --git a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h index 4ac496b9c1..5974df6eea 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h +++ b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.h @@ -4,11 +4,12 @@ #import "MWMTypes.h" @class PlacePageButtonsData; +@class PlacePageTrackData; @class PlacePagePreviewData; @class PlacePageInfoData; @class PlacePageBookmarkData; -@class ElevationProfileData; @class MWMMapNodeAttributes; +@class TrackRecordingInfo; typedef NS_ENUM(NSInteger, PlacePageRoadType) { PlacePageRoadTypeToll, @@ -17,6 +18,13 @@ typedef NS_ENUM(NSInteger, PlacePageRoadType) { PlacePageRoadTypeNone }; +typedef NS_ENUM(NSInteger, PlacePageObjectType) { + PlacePageObjectTypePOI, + PlacePageObjectTypeBookmark, + PlacePageObjectTypeTrack, + PlacePageObjectTypeTrackRecording +}; + @protocol IOpeningHoursLocalization; NS_ASSUME_NONNULL_BEGIN @@ -31,12 +39,13 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, nullable) PlacePageBookmarkData *bookmarkData; @property(nonatomic, readonly) PlacePageRoadType roadType; @property(nonatomic, readonly, nullable) NSString *wikiDescriptionHtml; -@property(nonatomic, readonly, nullable) ElevationProfileData *elevationProfileData; +@property(nonatomic, readonly, nullable) PlacePageTrackData *trackData; @property(nonatomic, readonly, nullable) MWMMapNodeAttributes *mapNodeAttributes; @property(nonatomic, readonly, nullable) NSString *bookingSearchUrl; @property(nonatomic, readonly) BOOL isMyPosition; @property(nonatomic, readonly) BOOL isPreviewPlus; @property(nonatomic, readonly) BOOL isRoutePoint; +@property(nonatomic, readonly) PlacePageObjectType objectType; @property(nonatomic, readonly) CLLocationCoordinate2D locationCoordinate; @property(nonatomic, copy, nullable) MWMVoidBlock onBookmarkStatusUpdate; @property(nonatomic, copy, nullable) MWMVoidBlock onMapNodeStatusUpdate; diff --git a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm index b864cc24e8..cda7f27918 100644 --- a/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm +++ b/iphone/CoreApi/CoreApi/PlacePageData/PlacePageData.mm @@ -4,7 +4,7 @@ #import "PlacePagePreviewData+Core.h" #import "PlacePageInfoData+Core.h" #import "PlacePageBookmarkData+Core.h" -#import "ElevationProfileData+Core.h" +#import "PlacePageTrackData+Core.h" #import "MWMMapNodeAttributes.h" #include @@ -42,6 +42,7 @@ static PlacePageRoadType convertRoadType(RoadWarningMarkType roadType) { _infoData = [[PlacePageInfoData alloc] initWithRawData:rawData() ohLocalization:localization]; if (rawData().IsBookmark()) { + _objectType = PlacePageObjectTypeBookmark; _bookmarkData = [[PlacePageBookmarkData alloc] initWithRawData:rawData()]; } @@ -63,8 +64,10 @@ static PlacePageRoadType convertRoadType(RoadWarningMarkType roadType) { } if (rawData().IsTrack()) { - // TODO: (KK) implement init with a track - _infoData = nil; + _objectType = PlacePageObjectTypeTrack; + auto const & track = GetFramework().GetBookmarkManager().GetTrack(rawData().GetTrackId()); + _trackData = [[PlacePageTrackData alloc] initWithTrack:*track]; + _isPreviewPlus = track->HasAltitudes(); } _previewData = [[PlacePagePreviewData alloc] initWithRawData:rawData()]; diff --git a/iphone/Maps/Classes/Share/MWMShareActivityItem.mm b/iphone/Maps/Classes/Share/MWMShareActivityItem.mm index 52991ab799..157aabdb37 100644 --- a/iphone/Maps/Classes/Share/MWMShareActivityItem.mm +++ b/iphone/Maps/Classes/Share/MWMShareActivityItem.mm @@ -63,8 +63,8 @@ NSString * httpGe0Url(NSString * shortUrl) return data.previewData.title; else if (data.previewData.subtitle.length) return data.previewData.subtitle; - else if (data.previewData.address.length) - return data.previewData.address; + else if (data.previewData.secondarySubtitle.length) + return data.previewData.secondarySubtitle; else return @""; }; @@ -138,7 +138,7 @@ NSString * httpGe0Url(NSString * shortUrl) NSMutableString * result = [L(@"sharing_call_action_look") mutableCopy]; std::vector strings{self.data.previewData.title, self.data.previewData.subtitle, - self.data.previewData.address, + self.data.previewData.secondarySubtitle, self.data.infoData.phone, url, ge0Url};