diff --git a/iphone/Maps/Core/Routing/MWMRoutePoint+CPP.h b/iphone/Maps/Core/Routing/MWMRoutePoint+CPP.h index 12bf931239..511af52a6a 100644 --- a/iphone/Maps/Core/Routing/MWMRoutePoint+CPP.h +++ b/iphone/Maps/Core/Routing/MWMRoutePoint+CPP.h @@ -12,6 +12,8 @@ intermediateIndex:(int8_t)intermediateIndex; - (instancetype)initWithRouteMarkData:(RouteMarkData const &)point; - (instancetype)initWithPoint:(m2::PointD const &)point + title:(NSString *)title + subtitle:(NSString *)subtitle type:(MWMRoutePointType)type intermediateIndex:(int8_t)intermediateIndex; diff --git a/iphone/Maps/Core/Routing/MWMRoutePoint.mm b/iphone/Maps/Core/Routing/MWMRoutePoint.mm index 19a26d2341..03d0ea64c5 100644 --- a/iphone/Maps/Core/Routing/MWMRoutePoint.mm +++ b/iphone/Maps/Core/Routing/MWMRoutePoint.mm @@ -26,7 +26,7 @@ { _point = lastLocation.mercator; _title = L(@"p2p_your_location"); - _subtitle = L(@""); + _subtitle = @""; _isMyPosition = YES; _type = type; _intermediateIndex = intermediateIndex; @@ -43,7 +43,7 @@ { _point = point.m_org; _title = @(point.m_name.c_str()); - _subtitle = L(@""); + _subtitle = @""; _isMyPosition = NO; _type = type; _intermediateIndex = intermediateIndex; @@ -72,6 +72,8 @@ } - (instancetype)initWithPoint:(m2::PointD const &)point + title:(NSString *)title + subtitle:(NSString *)subtitle type:(MWMRoutePointType)type intermediateIndex:(int8_t)intermediateIndex { @@ -79,13 +81,8 @@ if (self) { _point = point; - switch (type) - { - case MWMRoutePointTypeStart: _title = @"Source"; break; - case MWMRoutePointTypeIntermediate: _title = @"Intermediate"; break; - case MWMRoutePointTypeFinish: _title = @"Destination"; break; - } - _subtitle = L(@""); + _title = title; + _subtitle = subtitle ?: @""; _isMyPosition = NO; _type = type; _intermediateIndex = intermediateIndex; @@ -105,7 +102,7 @@ case MWMRoutePointTypeFinish: pt.m_pointType = RouteMarkType::Finish; break; } pt.m_position = self.point; - pt.m_isMyPosition = static_cast(self.isMyPosition); + pt.m_isMyPosition = self.isMyPosition; pt.m_title = self.title.UTF8String; pt.m_subTitle = self.subtitle.UTF8String; pt.m_intermediateIndex = self.intermediateIndex; diff --git a/iphone/Maps/Core/Routing/MWMRouter+RouteManager.mm b/iphone/Maps/Core/Routing/MWMRouter+RouteManager.mm new file mode 100644 index 0000000000..ab90c02b5b --- /dev/null +++ b/iphone/Maps/Core/Routing/MWMRouter+RouteManager.mm @@ -0,0 +1,78 @@ +#import "MWMRouter.h" + +#include "Framework.h" + +@interface MWMRouter () + +@property(nonatomic) uint32_t routeManagerTransactionId; + ++ (MWMRouter *)router; + +@end + +@implementation MWMRouter (RouteManager) + ++ (void)openRouteManagerTransaction +{ + auto router = [MWMRouter router]; + router.routeManagerTransactionId = + GetFramework().GetRoutingManager().OpenRoutePointsTransaction(); +} + ++ (void)applyRouteManagerTransaction +{ + auto router = [MWMRouter router]; + if (router.routeManagerTransactionId == RoutingManager::InvalidRoutePointsTransactionId()) + return; + GetFramework().GetRoutingManager().ApplyRoutePointsTransaction(router.routeManagerTransactionId); + router.routeManagerTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); +} + ++ (void)cancelRouteManagerTransaction +{ + auto router = [MWMRouter router]; + if (router.routeManagerTransactionId == RoutingManager::InvalidRoutePointsTransactionId()) + return; + GetFramework().GetRoutingManager().CancelRoutePointsTransaction(router.routeManagerTransactionId); + router.routeManagerTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); +} + ++ (void)movePointAtIndex:(NSInteger)index toIndex:(NSInteger)newIndex +{ + NSAssert(index != newIndex, @"Route manager moves point to its' current position."); + NSMutableArray * points = [[MWMRouter points] mutableCopy]; + + auto removeIndex = index; + auto insertIndex = newIndex; + + if (index < newIndex) + insertIndex += 1; + else + removeIndex += 1; + + [points insertObject:points[index] atIndex:insertIndex]; + [points removeObjectAtIndex:removeIndex]; + + [MWMRouter removePoints]; + + [points enumerateObjectsUsingBlock:^(MWMRoutePoint * point, NSUInteger idx, BOOL * stop) { + if (idx == 0) + { + point.type = MWMRoutePointTypeStart; + point.intermediateIndex = 0; + } + else if (idx == points.count - 1) + { + point.type = MWMRoutePointTypeFinish; + point.intermediateIndex = 0; + } + else + { + point.type = MWMRoutePointTypeIntermediate; + point.intermediateIndex = idx - 1; + } + [MWMRouter addPoint:point]; + }]; +} + +@end diff --git a/iphone/Maps/Core/Routing/MWMRouter.h b/iphone/Maps/Core/Routing/MWMRouter.h index 7bb2e19fb1..138893fc9b 100644 --- a/iphone/Maps/Core/Routing/MWMRouter.h +++ b/iphone/Maps/Core/Routing/MWMRouter.h @@ -23,7 +23,6 @@ typedef void (^MWMImageHeightBlock)(UIImage *, NSString *); + (void)setType:(MWMRouterType)type; + (MWMRouterType)type; -- (uint32_t)taxiRoutePointTransactionId; + (void)disableFollowMode; @@ -32,8 +31,11 @@ typedef void (^MWMImageHeightBlock)(UIImage *, NSString *); + (void)setTurnNotificationsLocale:(NSString *)locale; + (NSArray *)turnNotifications; ++ (void)addPoint:(MWMRoutePoint *)point; ++ (void)removePoint:(MWMRoutePoint *)point; + (void)addPointAndRebuild:(MWMRoutePoint *)point; + (void)removePointAndRebuild:(MWMRoutePoint *)point; ++ (void)removePoints; + (void)buildFromPoint:(MWMRoutePoint *)start bestRouter:(BOOL)bestRouter; + (void)buildToPoint:(MWMRoutePoint *)finish bestRouter:(BOOL)bestRouter; @@ -46,3 +48,12 @@ typedef void (^MWMImageHeightBlock)(UIImage *, NSString *); + (void)routeAltitudeImageForSize:(CGSize)size completion:(MWMImageHeightBlock)block; @end + +@interface MWMRouter (RouteManager) + ++ (void)openRouteManagerTransaction; ++ (void)applyRouteManagerTransaction; ++ (void)cancelRouteManagerTransaction; ++ (void)movePointAtIndex:(NSInteger)index toIndex:(NSInteger)newIndex; + +@end diff --git a/iphone/Maps/Core/Routing/MWMRouter.mm b/iphone/Maps/Core/Routing/MWMRouter.mm index 2cd1bfd05b..d6c6a8ad24 100644 --- a/iphone/Maps/Core/Routing/MWMRouter.mm +++ b/iphone/Maps/Core/Routing/MWMRouter.mm @@ -42,6 +42,7 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI @property(nonatomic) NSString * altitudeElevation; @property(nonatomic) dispatch_queue_t renderAltitudeImagesQueue; @property(nonatomic) uint32_t taxiRoutePointTransactionId; +@property(nonatomic) uint32_t routeManagerTransactionId; @end @@ -131,7 +132,7 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI return [points copy]; } -+ (NSInteger)pointsCount { return GetFramework().GetRoutingManager().GetRoutePoints().size(); } ++ (NSInteger)pointsCount { return GetFramework().GetRoutingManager().GetRoutePointsCount(); } + (MWMRoutePoint *)startPoint { auto const routePoints = GetFramework().GetRoutingManager().GetRoutePoints(); @@ -168,6 +169,7 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI self.renderAltitudeImagesQueue = dispatch_queue_create(kRenderAltitudeImagesQueueLabel, DISPATCH_QUEUE_SERIAL); self.taxiRoutePointTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); + self.routeManagerTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); [MWMLocationManager addObserver:self]; [MWMFrameworkListener addObserver:self]; } @@ -260,6 +262,7 @@ char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeI [self rebuildWithBestRouter:NO]; } ++ (void)removePoints { GetFramework().GetRoutingManager().RemoveRoutePoints(); } + (void)addPoint:(MWMRoutePoint *)point { if (!point) diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 19443d9d14..b93dbc960c 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -150,6 +150,9 @@ 340708861F2B863500029ECC /* MWMNavigationDashboardManager+Entity.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340708831F2B863500029ECC /* MWMNavigationDashboardManager+Entity.mm */; }; 340837131B7243CE00B5C185 /* MWMActivityViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340837121B7243CE00B5C185 /* MWMActivityViewController.mm */; }; 340837161B72451A00B5C185 /* MWMShareActivityItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340837151B72451A00B5C185 /* MWMShareActivityItem.mm */; }; + 340B33C51F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */; }; + 340B33C61F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */; }; + 340B33C71F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */; }; 340E1EEB1E2F614400CE49BF /* Authorization.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 340E1EE41E2F614400CE49BF /* Authorization.storyboard */; }; 340E1EEC1E2F614400CE49BF /* Authorization.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 340E1EE41E2F614400CE49BF /* Authorization.storyboard */; }; 340E1EED1E2F614400CE49BF /* Authorization.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 340E1EE41E2F614400CE49BF /* Authorization.storyboard */; }; @@ -1825,6 +1828,7 @@ 340837121B7243CE00B5C185 /* MWMActivityViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMActivityViewController.mm; sourceTree = ""; }; 340837141B72451A00B5C185 /* MWMShareActivityItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMShareActivityItem.h; sourceTree = ""; }; 340837151B72451A00B5C185 /* MWMShareActivityItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMShareActivityItem.mm; sourceTree = ""; }; + 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "MWMRouter+RouteManager.mm"; sourceTree = ""; }; 340DC82B1C4E72C700EAA2CC /* liboauthcpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liboauthcpp.a; path = "../../../omim-xcode-build/Debug/liboauthcpp.a"; sourceTree = ""; }; 340E1EE41E2F614400CE49BF /* Authorization.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Authorization.storyboard; sourceTree = ""; }; 340E1EE51E2F614400CE49BF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; @@ -3051,6 +3055,7 @@ 34F5E0DA1E3F3ED300B1C415 /* MWMRoutePoint.h */, 340475351E081A4600C92850 /* MWMRouter.h */, 340475361E081A4600C92850 /* MWMRouter.mm */, + 340B33C41F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm */, ); path = Routing; sourceTree = ""; @@ -5499,6 +5504,7 @@ 340708771F2B5D6C00029ECC /* DimBackground.swift in Sources */, F6E2FDF71E097BA00083EBEC /* MWMOpeningHoursAllDayTableViewCell.mm in Sources */, 1D3623260D0F684500981E51 /* MapsAppDelegate.mm in Sources */, + 340B33C51F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */, 34763EF21F2F5F6400F4D2D3 /* MWMiPhoneRoutePreview.mm in Sources */, F6E2FE181E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.mm in Sources */, F6E2FDEB1E097BA00083EBEC /* MWMOpeningHoursAddClosedTableViewCell.mm in Sources */, @@ -5836,6 +5842,7 @@ 340708781F2B5D6C00029ECC /* DimBackground.swift in Sources */, 3490D2DF1CE9DD2500D0B838 /* MWMSideButtons.mm in Sources */, F6E2FDF81E097BA00083EBEC /* MWMOpeningHoursAllDayTableViewCell.mm in Sources */, + 340B33C61F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */, 34763EF31F2F5F6400F4D2D3 /* MWMiPhoneRoutePreview.mm in Sources */, F6E2FE191E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.mm in Sources */, F6E2FDEC1E097BA00083EBEC /* MWMOpeningHoursAddClosedTableViewCell.mm in Sources */, @@ -6173,6 +6180,7 @@ 340708791F2B5D6C00029ECC /* DimBackground.swift in Sources */, F6E2FEC21E097BA00083EBEC /* MWMConsole.mm in Sources */, 845E4B1C1DEC839800D6BED8 /* MWMTrafficButtonViewController.mm in Sources */, + 340B33C71F3AEFDB00A8C1B4 /* MWMRouter+RouteManager.mm in Sources */, 34763EF41F2F5F6400F4D2D3 /* MWMiPhoneRoutePreview.mm in Sources */, F6E2FDF91E097BA00083EBEC /* MWMOpeningHoursAllDayTableViewCell.mm in Sources */, F6E2FE1A1E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.mm in Sources */, diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index 3d63260f1b..737048bf19 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -412,19 +412,25 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) return [[MWMRoutePoint alloc] initWithLastLocationAndType:type intermediateIndex:intermediateIndex]; - NSString * name = nil; + NSString * title = nil; if (data.title.length > 0) - name = data.title; + title = data.title; else if (data.address.length > 0) - name = data.address; + title = data.address; else if (data.subtitle.length > 0) - name = data.subtitle; + title = data.subtitle; else if (data.isBookmark) - name = data.externalTitle; + title = data.externalTitle; else - name = L(@"placepage_unknown_place"); + title = L(@"placepage_unknown_place"); + + NSString * subtitle = nil; + if (data.subtitle.length > 0 && ![title isEqualToString:data.subtitle]) + subtitle = data.subtitle; return [[MWMRoutePoint alloc] initWithPoint:data.mercator + title:title + subtitle:subtitle type:type intermediateIndex:intermediateIndex]; }