From 98b14e9318fd588177a5c37ee6229c992af0585d Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Thu, 29 Oct 2020 12:47:13 +0300 Subject: [PATCH] [iOS] CodeStyle --- .../MWMNavigationDashboardManager+Entity.h | 3 +- .../MWMNavigationDashboardManager+Entity.mm | 144 ++-- .../Views/MWMNavigationInfoView.mm | 437 +++++------- .../Views/NavigationControlView.swift | 9 +- iphone/Maps/Core/Routing/MWMRouter.mm | 623 ++++++++---------- 5 files changed, 535 insertions(+), 681 deletions(-) diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.h b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.h index acabbc7173..bbc1346f52 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.h +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.h @@ -1,8 +1,7 @@ #import "MWMNavigationDashboardManager.h" #import "MWMRouterType.h" -namespace routing -{ +namespace routing { class FollowingInfo; } diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm index b7e4deec7d..6e4cb03d6f 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm @@ -14,48 +14,44 @@ #include "geometry/distance_on_sphere.hpp" -namespace -{ -UIImage * image(routing::turns::CarDirection t, bool isNextTurn) -{ +namespace { +UIImage *image(routing::turns::CarDirection t, bool isNextTurn) { if (![MWMLocationManager lastLocation]) return nil; - + using namespace routing::turns; - NSString * imageName; - switch (t) - { - case CarDirection::ExitHighwayToRight: imageName = @"ic_exit_highway_to_right"; break; - case CarDirection::TurnSlightRight: imageName = @"slight_right"; break; - case CarDirection::TurnRight: imageName = @"simple_right"; break; - case CarDirection::TurnSharpRight: imageName = @"sharp_right"; break; - case CarDirection::ExitHighwayToLeft: imageName = @"ic_exit_highway_to_left"; break; - case CarDirection::TurnSlightLeft: imageName = @"slight_left"; break; - case CarDirection::TurnLeft: imageName = @"simple_left"; break; - case CarDirection::TurnSharpLeft: imageName = @"sharp_left"; break; - case CarDirection::UTurnLeft: imageName = @"uturn_left"; break; - case CarDirection::UTurnRight: imageName = @"uturn_right"; break; - case CarDirection::ReachedYourDestination: imageName = @"finish_point"; break; - case CarDirection::LeaveRoundAbout: - case CarDirection::EnterRoundAbout: imageName = @"round"; break; - case CarDirection::GoStraight: imageName = @"straight"; break; - case CarDirection::StartAtEndOfStreet: - case CarDirection::StayOnRoundAbout: - case CarDirection::Count: - case CarDirection::None: imageName = isNextTurn ? nil : @"straight"; break; + NSString *imageName; + switch (t) { + case CarDirection::ExitHighwayToRight: imageName = @"ic_exit_highway_to_right"; break; + case CarDirection::TurnSlightRight: imageName = @"slight_right"; break; + case CarDirection::TurnRight: imageName = @"simple_right"; break; + case CarDirection::TurnSharpRight: imageName = @"sharp_right"; break; + case CarDirection::ExitHighwayToLeft: imageName = @"ic_exit_highway_to_left"; break; + case CarDirection::TurnSlightLeft: imageName = @"slight_left"; break; + case CarDirection::TurnLeft: imageName = @"simple_left"; break; + case CarDirection::TurnSharpLeft: imageName = @"sharp_left"; break; + case CarDirection::UTurnLeft: imageName = @"uturn_left"; break; + case CarDirection::UTurnRight: imageName = @"uturn_right"; break; + case CarDirection::ReachedYourDestination: imageName = @"finish_point"; break; + case CarDirection::LeaveRoundAbout: + case CarDirection::EnterRoundAbout: imageName = @"round"; break; + case CarDirection::GoStraight: imageName = @"straight"; break; + case CarDirection::StartAtEndOfStreet: + case CarDirection::StayOnRoundAbout: + case CarDirection::Count: + case CarDirection::None: imageName = isNextTurn ? nil : @"straight"; break; } if (!imageName) return nil; return [UIImage imageNamed:isNextTurn ? [imageName stringByAppendingString:@"_then"] : imageName]; } -UIImage * image(routing::turns::PedestrianDirection t) -{ +UIImage *image(routing::turns::PedestrianDirection t) { if (![MWMLocationManager lastLocation]) return nil; - + using namespace routing::turns; - NSString * imageName; + NSString *imageName; switch (t) { case PedestrianDirection::TurnRight: imageName = @"simple_right"; break; @@ -70,17 +66,14 @@ UIImage * image(routing::turns::PedestrianDirection t) return [UIImage imageNamed:imageName]; } -NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSString * distance, - NSString * distanceUnits, NSDictionary * primaryAttributes, - NSDictionary * secondaryAttributes, BOOL isWalk) -{ - NSString * eta = [NSDateComponentsFormatter etaStringFrom:time]; +NSAttributedString *estimate(NSTimeInterval time, NSAttributedString *dot, NSString *distance, NSString *distanceUnits, + NSDictionary *primaryAttributes, NSDictionary *secondaryAttributes, BOOL isWalk) { + NSString *eta = [NSDateComponentsFormatter etaStringFrom:time]; auto result = [[NSMutableAttributedString alloc] initWithString:eta attributes:primaryAttributes]; [result appendAttributedString:dot]; - if (isWalk) - { - UIFont * font = primaryAttributes[NSFontAttributeName]; + if (isWalk) { + UIFont *font = primaryAttributes[NSFontAttributeName]; auto textAttachment = [[NSTextAttachment alloc] init]; auto image = [UIImage imageNamed:@"ic_walk"]; textAttachment.image = image; @@ -89,16 +82,14 @@ NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSS auto const width = image.size.width * height / image.size.height; textAttachment.bounds = CGRectIntegral({{0, y}, {width, height}}); - NSMutableAttributedString * attrStringWithImage = - [NSAttributedString attributedStringWithAttachment:textAttachment].mutableCopy; - [attrStringWithImage addAttributes:secondaryAttributes - range:NSMakeRange(0, attrStringWithImage.length)]; + NSMutableAttributedString *attrStringWithImage = + [NSAttributedString attributedStringWithAttachment:textAttachment].mutableCopy; + [attrStringWithImage addAttributes:secondaryAttributes range:NSMakeRange(0, attrStringWithImage.length)]; [result appendAttributedString:attrStringWithImage]; } auto target = [NSString stringWithFormat:@"%@ %@", distance, distanceUnits]; - [result appendAttributedString:[[NSAttributedString alloc] initWithString:target - attributes:secondaryAttributes]]; + [result appendAttributedString:[[NSAttributedString alloc] initWithString:target attributes:secondaryAttributes]]; return result; } @@ -106,20 +97,20 @@ NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSS @interface MWMNavigationDashboardEntity () -@property(copy, nonatomic, readwrite) NSArray * transitSteps; -@property(copy, nonatomic, readwrite) NSAttributedString * estimate; -@property(copy, nonatomic, readwrite) NSString * distanceToTurn; -@property(copy, nonatomic, readwrite) NSString * streetName; -@property(copy, nonatomic, readwrite) NSString * targetDistance; -@property(copy, nonatomic, readwrite) NSString * targetUnits; -@property(copy, nonatomic, readwrite) NSString * turnUnits; +@property(copy, nonatomic, readwrite) NSArray *transitSteps; +@property(copy, nonatomic, readwrite) NSAttributedString *estimate; +@property(copy, nonatomic, readwrite) NSString *distanceToTurn; +@property(copy, nonatomic, readwrite) NSString *streetName; +@property(copy, nonatomic, readwrite) NSString *targetDistance; +@property(copy, nonatomic, readwrite) NSString *targetUnits; +@property(copy, nonatomic, readwrite) NSString *turnUnits; @property(nonatomic, readwrite) BOOL isValid; @property(nonatomic, readwrite) CGFloat progress; -@property(nonatomic, readwrite) CLLocation * pedestrianDirectionPosition; +@property(nonatomic, readwrite) CLLocation *pedestrianDirectionPosition; @property(nonatomic, readwrite) NSUInteger roundExitNumber; @property(nonatomic, readwrite) NSUInteger timeToTarget; -@property(nonatomic, readwrite) UIImage * nextTurnImage; -@property(nonatomic, readwrite) UIImage * turnImage; +@property(nonatomic, readwrite) UIImage *nextTurnImage; +@property(nonatomic, readwrite) UIImage *turnImage; @end @@ -131,9 +122,9 @@ NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSS @interface MWMNavigationDashboardManager () -@property(copy, nonatomic) NSDictionary * etaAttributes; -@property(copy, nonatomic) NSDictionary * etaSecondaryAttributes; -@property(nonatomic) MWMNavigationDashboardEntity * entity; +@property(copy, nonatomic) NSDictionary *etaAttributes; +@property(copy, nonatomic) NSDictionary *etaSecondaryAttributes; +@property(nonatomic) MWMNavigationDashboardEntity *entity; - (void)onNavigationInfoUpdated; @@ -142,15 +133,13 @@ NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSS @implementation MWMNavigationDashboardManager (Entity) - (void)updateFollowingInfo:(routing::FollowingInfo const &)info type:(MWMRouterType)type { - if ([MWMRouter isRouteFinished]) - { + if ([MWMRouter isRouteFinished]) { [MWMRouter stopRouting]; AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); return; } - if (auto entity = self.entity) - { + if (auto entity = self.entity) { entity.isValid = YES; entity.timeToTarget = info.m_time; entity.targetDistance = @(info.m_distToTarget.c_str()); @@ -160,20 +149,18 @@ NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSS entity.turnUnits = [self localizedUnitLength:@(info.m_turnUnitsSuffix.c_str())]; entity.streetName = @(info.m_displayedStreetName.c_str()); - entity.estimate = - estimate(entity.timeToTarget, entity.estimateDot, entity.targetDistance, entity.targetUnits, - self.etaAttributes, self.etaSecondaryAttributes, NO); + entity.estimate = estimate(entity.timeToTarget, entity.estimateDot, entity.targetDistance, entity.targetUnits, + self.etaAttributes, self.etaSecondaryAttributes, NO); - if (type == MWMRouterTypePedestrian) { - entity.turnImage = image(info.m_pedestrianTurn); - } else { + if (type == MWMRouterTypePedestrian) { + entity.turnImage = image(info.m_pedestrianTurn); + } else { using namespace routing::turns; CarDirection const turn = info.m_turn; entity.turnImage = image(turn, false); entity.nextTurnImage = image(info.m_nextTurn, true); - BOOL const isRound = turn == CarDirection::EnterRoundAbout || - turn == CarDirection::StayOnRoundAbout || - turn == CarDirection::LeaveRoundAbout; + BOOL const isRound = turn == CarDirection::EnterRoundAbout || turn == CarDirection::StayOnRoundAbout || + turn == CarDirection::LeaveRoundAbout; if (isRound) entity.roundExitNumber = info.m_exitNum; else @@ -184,17 +171,14 @@ NSAttributedString * estimate(NSTimeInterval time, NSAttributedString * dot, NSS [self onNavigationInfoUpdated]; } -- (void)updateTransitInfo:(TransitRouteInfo const &)info -{ - if (auto entity = self.entity) - { +- (void)updateTransitInfo:(TransitRouteInfo const &)info { + if (auto entity = self.entity) { entity.isValid = YES; - entity.estimate = estimate(info.m_totalTimeInSec, entity.estimateDot, - @(info.m_totalPedestrianDistanceStr.c_str()), - @(info.m_totalPedestrianUnitsSuffix.c_str()), self.etaAttributes, - self.etaSecondaryAttributes, YES); - NSMutableArray * transitSteps = [@[] mutableCopy]; - for (auto const & stepInfo : info.m_steps) + entity.estimate = + estimate(info.m_totalTimeInSec, entity.estimateDot, @(info.m_totalPedestrianDistanceStr.c_str()), + @(info.m_totalPedestrianUnitsSuffix.c_str()), self.etaAttributes, self.etaSecondaryAttributes, YES); + NSMutableArray *transitSteps = [@[] mutableCopy]; + for (auto const &stepInfo : info.m_steps) [transitSteps addObject:[[MWMRouterTransitStepInfo alloc] initWithStepInfo:stepInfo]]; entity.transitSteps = transitSteps; } diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/MWMNavigationInfoView.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/MWMNavigationInfoView.mm index 5feebdc22f..0d152ac531 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/MWMNavigationInfoView.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/MWMNavigationInfoView.mm @@ -14,8 +14,7 @@ #include "geometry/angles.hpp" -namespace -{ +namespace { CGFloat const kTurnsiPhoneWidth = 96; CGFloat const kTurnsiPadWidth = 140; @@ -30,81 +29,81 @@ CGFloat const kShiftedTurnsTopOffset = 8; NSTimeInterval constexpr kCollapseSearchTimeout = 5.0; std::map const kSearchStateButtonImageNames{ - {NavigationSearchState::Maximized, @"ic_routing_search"}, - {NavigationSearchState::MinimizedNormal, @"ic_routing_search"}, - {NavigationSearchState::MinimizedSearch, @"ic_routing_search_off"}, - {NavigationSearchState::MinimizedGas, @"ic_routing_fuel_off"}, - {NavigationSearchState::MinimizedParking, @"ic_routing_parking_off"}, - {NavigationSearchState::MinimizedEat, @"ic_routing_eat_off"}, - {NavigationSearchState::MinimizedFood, @"ic_routing_food_off"}, - {NavigationSearchState::MinimizedATM, @"ic_routing_atm_off"}}; + {NavigationSearchState::Maximized, @"ic_routing_search"}, + {NavigationSearchState::MinimizedNormal, @"ic_routing_search"}, + {NavigationSearchState::MinimizedSearch, @"ic_routing_search_off"}, + {NavigationSearchState::MinimizedGas, @"ic_routing_fuel_off"}, + {NavigationSearchState::MinimizedParking, @"ic_routing_parking_off"}, + {NavigationSearchState::MinimizedEat, @"ic_routing_eat_off"}, + {NavigationSearchState::MinimizedFood, @"ic_routing_food_off"}, + {NavigationSearchState::MinimizedATM, @"ic_routing_atm_off"}}; std::map const kSearchButtonRequest{ - {NavigationSearchState::MinimizedGas, L(@"fuel")}, - {NavigationSearchState::MinimizedParking, L(@"parking")}, - {NavigationSearchState::MinimizedEat, L(@"eat")}, - {NavigationSearchState::MinimizedFood, L(@"food")}, - {NavigationSearchState::MinimizedATM, L(@"atm")}}; + {NavigationSearchState::MinimizedGas, L(@"fuel")}, + {NavigationSearchState::MinimizedParking, L(@"parking")}, + {NavigationSearchState::MinimizedEat, L(@"eat")}, + {NavigationSearchState::MinimizedFood, L(@"food")}, + {NavigationSearchState::MinimizedATM, L(@"atm")}}; -BOOL defaultOrientation(CGSize const & size) -{ - CGSize const & mapViewSize = [MapViewController sharedController].view.frame.size; +BOOL defaultOrientation(CGSize const &size) { + CGSize const &mapViewSize = [MapViewController sharedController].view.frame.size; CGFloat const minWidth = MIN(mapViewSize.width, mapViewSize.height); return IPAD || (size.height > size.width && size.width >= minWidth); } } // namespace -@interface MWMNavigationInfoView () +@interface MWMNavigationInfoView () -@property(weak, nonatomic) IBOutlet UIView * streetNameView; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * streetNameViewHideOffset; -@property(weak, nonatomic) IBOutlet UILabel * streetNameLabel; -@property(weak, nonatomic) IBOutlet UIView * turnsView; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * turnsViewHideOffset; -@property(weak, nonatomic) IBOutlet UIImageView * nextTurnImageView; -@property(weak, nonatomic) IBOutlet UILabel * roundTurnLabel; -@property(weak, nonatomic) IBOutlet UILabel * distanceToNextTurnLabel; -@property(weak, nonatomic) IBOutlet UIView * secondTurnView; -@property(weak, nonatomic) IBOutlet UIImageView * secondTurnImageView; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * turnsWidth; +@property(weak, nonatomic) IBOutlet UIView *streetNameView; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *streetNameViewHideOffset; +@property(weak, nonatomic) IBOutlet UILabel *streetNameLabel; +@property(weak, nonatomic) IBOutlet UIView *turnsView; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *turnsViewHideOffset; +@property(weak, nonatomic) IBOutlet UIImageView *nextTurnImageView; +@property(weak, nonatomic) IBOutlet UILabel *roundTurnLabel; +@property(weak, nonatomic) IBOutlet UILabel *distanceToNextTurnLabel; +@property(weak, nonatomic) IBOutlet UIView *secondTurnView; +@property(weak, nonatomic) IBOutlet UIImageView *secondTurnImageView; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *turnsWidth; -@property(weak, nonatomic) IBOutlet UIView * searchButtonsView; -@property(weak, nonatomic) IBOutlet MWMButton * searchMainButton; -@property(weak, nonatomic) IBOutlet MWMButton * bookmarksButton; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * searchButtonsViewHeight; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * searchButtonsViewWidth; -@property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray * searchLandscapeConstraints; -@property(nonatomic) IBOutletCollection(UIButton) NSArray * searchButtons; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * searchButtonsSideSize; -@property(weak, nonatomic) IBOutlet MWMButton * searchGasButton; -@property(weak, nonatomic) IBOutlet MWMButton * searchParkingButton; -@property(weak, nonatomic) IBOutlet MWMButton * searchEatButton; -@property(weak, nonatomic) IBOutlet MWMButton * searchFoodButton; -@property(weak, nonatomic) IBOutlet MWMButton * searchATMButton; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * turnsTopOffset; +@property(weak, nonatomic) IBOutlet UIView *searchButtonsView; +@property(weak, nonatomic) IBOutlet MWMButton *searchMainButton; +@property(weak, nonatomic) IBOutlet MWMButton *bookmarksButton; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *searchButtonsViewHeight; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *searchButtonsViewWidth; +@property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray *searchLandscapeConstraints; +@property(nonatomic) IBOutletCollection(UIButton) NSArray *searchButtons; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *searchButtonsSideSize; +@property(weak, nonatomic) IBOutlet MWMButton *searchGasButton; +@property(weak, nonatomic) IBOutlet MWMButton *searchParkingButton; +@property(weak, nonatomic) IBOutlet MWMButton *searchEatButton; +@property(weak, nonatomic) IBOutlet MWMButton *searchFoodButton; +@property(weak, nonatomic) IBOutlet MWMButton *searchATMButton; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *turnsTopOffset; -@property(weak, nonatomic) IBOutlet MWMNavigationAddPointToastView * toastView; -@property(weak, nonatomic) IBOutlet NSLayoutConstraint * toastViewHideOffset; +@property(weak, nonatomic) IBOutlet MWMNavigationAddPointToastView *toastView; +@property(weak, nonatomic) IBOutlet NSLayoutConstraint *toastViewHideOffset; @property(nonatomic, readwrite) NavigationSearchState searchState; @property(nonatomic) BOOL isVisible; -@property(weak, nonatomic) MWMNavigationDashboardEntity * navigationInfo; +@property(weak, nonatomic) MWMNavigationDashboardEntity *navigationInfo; @property(nonatomic) BOOL hasLocation; -@property(nonatomic) NSLayoutConstraint * topConstraint; -@property(nonatomic) NSLayoutConstraint * leftConstraint; -@property(nonatomic) NSLayoutConstraint * widthConstraint; -@property(nonatomic) NSLayoutConstraint * heightConstraint; +@property(nonatomic) NSLayoutConstraint *topConstraint; +@property(nonatomic) NSLayoutConstraint *leftConstraint; +@property(nonatomic) NSLayoutConstraint *widthConstraint; +@property(nonatomic) NSLayoutConstraint *heightConstraint; @end @implementation MWMNavigationInfoView -- (void)setMapSearch { [self setSearchState:NavigationSearchState::MinimizedSearch animated:YES]; } -- (void)updateToastView -{ +- (void)setMapSearch { + [self setSearchState:NavigationSearchState::MinimizedSearch animated:YES]; +} +- (void)updateToastView { // -S-F-L -> Start // -S-F+L -> Finish // -S+F-L -> Start @@ -118,8 +117,7 @@ BOOL defaultOrientation(CGSize const & size) BOOL const hasFinish = ([MWMRouter finishPoint] != nil); self.hasLocation = ([MWMLocationManager lastLocation] != nil); - if (hasStart && hasFinish) - { + if (hasStart && hasFinish) { [self setToastViewHidden:YES]; return; } @@ -128,14 +126,12 @@ BOOL defaultOrientation(CGSize const & size) auto toastView = self.toastView; - if (hasStart) - { + if (hasStart) { [toastView configWithIsStart:NO withLocationButton:NO]; return; } - if (hasFinish) - { + if (hasFinish) { [toastView configWithIsStart:YES withLocationButton:self.hasLocation]; return; } @@ -146,73 +142,61 @@ BOOL defaultOrientation(CGSize const & size) [toastView configWithIsStart:YES withLocationButton:NO]; } -- (IBAction)openSearch -{ +- (IBAction)openSearch { BOOL const isStart = self.toastView.isStart; auto const type = isStart ? kStatRoutingPointTypeStart : kStatRoutingPointTypeFinish; - [Statistics logEvent:kStatRoutingTooltipClicked withParameters:@{kStatRoutingPointType : type}]; + [Statistics logEvent:kStatRoutingTooltipClicked withParameters:@{kStatRoutingPointType: type}]; auto searchManager = [MWMSearchManager manager]; - searchManager.routingTooltipSearch = isStart ? MWMSearchManagerRoutingTooltipSearchStart - : MWMSearchManagerRoutingTooltipSearchFinish; + searchManager.routingTooltipSearch = + isStart ? MWMSearchManagerRoutingTooltipSearchStart : MWMSearchManagerRoutingTooltipSearchFinish; searchManager.state = MWMSearchManagerStateDefault; } -- (IBAction)addLocationRoutePoint -{ +- (IBAction)addLocationRoutePoint { NSAssert(![MWMRouter startPoint], @"Action button is active while start point is available"); - NSAssert([MWMLocationManager lastLocation], - @"Action button is active while my location is not available"); + NSAssert([MWMLocationManager lastLocation], @"Action button is active while my location is not available"); - [MWMRouter - buildFromPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart - intermediateIndex:0] - bestRouter:NO]; + [MWMRouter buildFromPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart + intermediateIndex:0] + bestRouter:NO]; } #pragma mark - Search -- (IBAction)searchMainButtonTouchUpInside -{ - switch (self.searchState) - { - case NavigationSearchState::Maximized: - [MWMSearchManager manager].state = MWMSearchManagerStateDefault; - [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; - [Statistics logEvent:kStatRoutingSearchClicked - withParameters:@{kStatMode: kStatRoutingModeOnRoute}]; - break; - case NavigationSearchState::MinimizedNormal: - if (self.state == MWMNavigationInfoViewStatePrepare) - { +- (IBAction)searchMainButtonTouchUpInside { + switch (self.searchState) { + case NavigationSearchState::Maximized: [MWMSearchManager manager].state = MWMSearchManagerStateDefault; - [Statistics logEvent:kStatRoutingSearchClicked - withParameters:@{kStatMode: kStatRoutingModePlanning}]; - } - else - { - [self setSearchState:NavigationSearchState::Maximized animated:YES]; - } - break; - case NavigationSearchState::MinimizedSearch: - case NavigationSearchState::MinimizedGas: - case NavigationSearchState::MinimizedParking: - case NavigationSearchState::MinimizedEat: - case NavigationSearchState::MinimizedFood: - case NavigationSearchState::MinimizedATM: - [MWMSearch clear]; - [MWMSearchManager manager].state = MWMSearchManagerStateHidden; - [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; - break; + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; + [Statistics logEvent:kStatRoutingSearchClicked withParameters:@{kStatMode: kStatRoutingModeOnRoute}]; + break; + case NavigationSearchState::MinimizedNormal: + if (self.state == MWMNavigationInfoViewStatePrepare) { + [MWMSearchManager manager].state = MWMSearchManagerStateDefault; + [Statistics logEvent:kStatRoutingSearchClicked withParameters:@{kStatMode: kStatRoutingModePlanning}]; + } else { + [self setSearchState:NavigationSearchState::Maximized animated:YES]; + } + break; + case NavigationSearchState::MinimizedSearch: + case NavigationSearchState::MinimizedGas: + case NavigationSearchState::MinimizedParking: + case NavigationSearchState::MinimizedEat: + case NavigationSearchState::MinimizedFood: + case NavigationSearchState::MinimizedATM: + [MWMSearch clear]; + [MWMSearchManager manager].state = MWMSearchManagerStateHidden; + [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; + break; } } -- (IBAction)searchButtonTouchUpInside:(MWMButton *)sender -{ +- (IBAction)searchButtonTouchUpInside:(MWMButton *)sender { auto const body = ^(NavigationSearchState state) { [MWMSearch setSearchOnMap:YES]; - NSString * query = [kSearchButtonRequest.at(state) stringByAppendingString:@" "]; - NSString * locale = [[AppInfo sharedInfo] languageId]; + NSString *query = [kSearchButtonRequest.at(state) stringByAppendingString:@" "]; + NSString *locale = [[AppInfo sharedInfo] languageId]; [MWMSearch searchQuery:query forInputLocale:locale]; [self setSearchState:state animated:YES]; }; @@ -229,107 +213,81 @@ BOOL defaultOrientation(CGSize const & size) body(NavigationSearchState::MinimizedATM); } -- (IBAction)bookmarksButtonTouchUpInside -{ +- (IBAction)bookmarksButtonTouchUpInside { BOOL const isOnRoute = (self.state == MWMNavigationInfoViewStateNavigation); [Statistics logEvent:kStatRoutingBookmarksClicked - withParameters:@{ - kStatMode: (isOnRoute ? kStatRoutingModeOnRoute : kStatRoutingModePlanning) - }]; + withParameters:@{kStatMode: (isOnRoute ? kStatRoutingModeOnRoute : kStatRoutingModePlanning)}]; [[MapViewController sharedController].bookmarksCoordinator open]; } -- (void)collapseSearchOnTimer -{ +- (void)collapseSearchOnTimer { [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; } -- (void)layoutSearch -{ +- (void)layoutSearch { BOOL const defaultView = defaultOrientation(self.availableArea.size); CGFloat alpha = 0; CGFloat searchButtonsSideSize = 0; self.searchButtonsViewWidth.constant = 0; self.searchButtonsViewHeight.constant = 0; - if (self.searchState == NavigationSearchState::Maximized) - { + if (self.searchState == NavigationSearchState::Maximized) { alpha = 1; searchButtonsSideSize = kSearchButtonsSideSize; self.searchButtonsViewWidth.constant = - defaultView ? kSearchButtonsViewWidthPortrait : kSearchButtonsViewWidthLandscape; + defaultView ? kSearchButtonsViewWidthPortrait : kSearchButtonsViewWidthLandscape; self.searchButtonsViewHeight.constant = - defaultView ? kSearchButtonsViewHeightPortrait : kSearchButtonsViewHeightLandscape; + defaultView ? kSearchButtonsViewHeightPortrait : kSearchButtonsViewHeightLandscape; } - for (UIButton * searchButton in self.searchButtons) + for (UIButton *searchButton in self.searchButtons) searchButton.alpha = alpha; - UILayoutPriority const priority = - (defaultView ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh); - for (NSLayoutConstraint * constraint in self.searchLandscapeConstraints) + UILayoutPriority const priority = (defaultView ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh); + for (NSLayoutConstraint *constraint in self.searchLandscapeConstraints) constraint.priority = priority; self.searchButtonsSideSize.constant = searchButtonsSideSize; } #pragma mark - MWMNavigationDashboardManager -- (void)onNavigationInfoUpdated:(MWMNavigationDashboardEntity *)info -{ +- (void)onNavigationInfoUpdated:(MWMNavigationDashboardEntity *)info { self.navigationInfo = info; if (self.state != MWMNavigationInfoViewStateNavigation) return; - if (info.streetName.length != 0) - { + if (info.streetName.length != 0) { [self setStreetNameVisible:YES]; self.streetNameLabel.text = info.streetName; - } - else - { + } else { [self setStreetNameVisible:NO]; } - if (info.turnImage) - { + if (info.turnImage) { [self setTurnsViewVisible:YES]; self.nextTurnImageView.image = info.turnImage; - if (info.roundExitNumber == 0) - { + if (info.roundExitNumber == 0) { self.roundTurnLabel.hidden = YES; - } - else - { + } else { self.roundTurnLabel.hidden = NO; self.roundTurnLabel.text = @(info.roundExitNumber).stringValue; } - NSDictionary * turnNumberAttributes = @{ - NSForegroundColorAttributeName : [UIColor white], - NSFontAttributeName : IPAD ? [UIFont bold36] : [UIFont bold28] - }; - NSDictionary * turnLegendAttributes = @{ - NSForegroundColorAttributeName : [UIColor white], - NSFontAttributeName : IPAD ? [UIFont bold24] : [UIFont bold16] - }; + NSDictionary *turnNumberAttributes = + @{NSForegroundColorAttributeName: [UIColor white], NSFontAttributeName: IPAD ? [UIFont bold36] : [UIFont bold28]}; + NSDictionary *turnLegendAttributes = + @{NSForegroundColorAttributeName: [UIColor white], NSFontAttributeName: IPAD ? [UIFont bold24] : [UIFont bold16]}; - NSMutableAttributedString * distance = - [[NSMutableAttributedString alloc] initWithString:info.distanceToTurn - attributes:turnNumberAttributes]; - [distance - appendAttributedString:[[NSAttributedString alloc] - initWithString:[NSString stringWithFormat:@" %@", info.turnUnits] - attributes:turnLegendAttributes]]; + NSMutableAttributedString *distance = [[NSMutableAttributedString alloc] initWithString:info.distanceToTurn + attributes:turnNumberAttributes]; + [distance appendAttributedString:[[NSAttributedString alloc] + initWithString:[NSString stringWithFormat:@" %@", info.turnUnits] + attributes:turnLegendAttributes]]; self.distanceToNextTurnLabel.attributedText = distance; - if (info.nextTurnImage) - { + if (info.nextTurnImage) { self.secondTurnView.hidden = NO; self.secondTurnImageView.image = info.nextTurnImage; - } - else - { + } else { self.secondTurnView.hidden = YES; } - } - else - { + } else { [self setTurnsViewVisible:NO]; } [self setNeedsLayout]; @@ -337,8 +295,7 @@ BOOL defaultOrientation(CGSize const & size) #pragma mark - MWMLocationObserver -- (void)onLocationUpdate:(CLLocation *)location -{ +- (void)onLocationUpdate:(CLLocation *)location { BOOL const hasLocation = ([MWMLocationManager lastLocation] != nil); if (self.hasLocation != hasLocation) [self updateToastView]; @@ -346,39 +303,34 @@ BOOL defaultOrientation(CGSize const & size) #pragma mark - SolidTouchView -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if (self.searchState == NavigationSearchState::Maximized) return; [super touchesBegan:touches withEvent:event]; } -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event -{ +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (self.searchState == NavigationSearchState::Maximized) return; [super touchesMoved:touches withEvent:event]; } -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (self.searchState == NavigationSearchState::Maximized) [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; else [super touchesEnded:touches withEvent:event]; } -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ +- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if (self.searchState == NavigationSearchState::Maximized) [self setSearchState:NavigationSearchState::MinimizedNormal animated:YES]; else [super touchesCancelled:touches withEvent:event]; } -- (void)configLayout -{ - UIView * ov = self.superview; +- (void)configLayout { + UIView *ov = self.superview; self.translatesAutoresizingMaskIntoConstraints = NO; self.topConstraint = [self.topAnchor constraintEqualToAnchor:ov.topAnchor]; @@ -391,8 +343,7 @@ BOOL defaultOrientation(CGSize const & size) self.heightConstraint.active = YES; } -- (void)refreshLayout -{ +- (void)refreshLayout { dispatch_async(dispatch_get_main_queue(), ^{ auto const availableArea = self.availableArea; [self animateConstraintsWithAnimations:^{ @@ -402,114 +353,96 @@ BOOL defaultOrientation(CGSize const & size) self.heightConstraint.constant = availableArea.size.height; [self layoutSearch]; - self.turnsTopOffset.constant = - availableArea.origin.y > 0 ? kShiftedTurnsTopOffset : kBaseTurnsTopOffset; + self.turnsTopOffset.constant = availableArea.origin.y > 0 ? kShiftedTurnsTopOffset : kBaseTurnsTopOffset; self.searchButtonsView.layer.cornerRadius = - (defaultOrientation(availableArea.size) ? kSearchButtonsViewHeightPortrait - : kSearchButtonsViewHeightLandscape) / - 2; + (defaultOrientation(availableArea.size) ? kSearchButtonsViewHeightPortrait + : kSearchButtonsViewHeightLandscape) / + 2; }]; }); } #pragma mark - Properties -- (void)setAvailableArea:(CGRect)availableArea -{ +- (void)setAvailableArea:(CGRect)availableArea { if (CGRectEqualToRect(_availableArea, availableArea)) return; _availableArea = availableArea; [self refreshLayout]; } -- (void)setSearchState:(NavigationSearchState)searchState animated:(BOOL)animated -{ +- (void)setSearchState:(NavigationSearchState)searchState animated:(BOOL)animated { self.searchState = searchState; auto block = ^{ [self layoutSearch]; [self layoutIfNeeded]; }; - if (animated) - { + if (animated) { [self layoutIfNeeded]; [UIView animateWithDuration:kDefaultAnimationDuration animations:block]; - } - else - { + } else { block(); } SEL const collapseSelector = @selector(collapseSearchOnTimer); [NSObject cancelPreviousPerformRequestsWithTarget:self selector:collapseSelector object:self]; - if (self.searchState == NavigationSearchState::Maximized) - { + if (self.searchState == NavigationSearchState::Maximized) { [self.superview bringSubviewToFront:self]; [self performSelector:collapseSelector withObject:self afterDelay:kCollapseSearchTimeout]; - } - else - { + } else { [self.superview sendSubviewToBack:self]; } } -- (void)setSearchState:(NavigationSearchState)searchState -{ +- (void)setSearchState:(NavigationSearchState)searchState { _searchState = searchState; self.searchMainButton.imageName = kSearchStateButtonImageNames.at(searchState); } -- (void)setState:(MWMNavigationInfoViewState)state -{ +- (void)setState:(MWMNavigationInfoViewState)state { if (_state == state) return; _state = state; - switch (state) - { - case MWMNavigationInfoViewStateHidden: - self.isVisible = NO; - [self setToastViewHidden:YES]; - [MWMLocationManager removeObserver:self]; - break; - case MWMNavigationInfoViewStateNavigation: - self.isVisible = YES; - if ([MWMRouter type] == MWMRouterTypePedestrian) - [MWMLocationManager addObserver:self]; - else + switch (state) { + case MWMNavigationInfoViewStateHidden: + self.isVisible = NO; + [self setToastViewHidden:YES]; [MWMLocationManager removeObserver:self]; - break; - case MWMNavigationInfoViewStatePrepare: - self.isVisible = YES; - [self setStreetNameVisible:NO]; - [self setTurnsViewVisible:NO]; - [MWMLocationManager addObserver:self]; - break; + break; + case MWMNavigationInfoViewStateNavigation: + self.isVisible = YES; + if ([MWMRouter type] == MWMRouterTypePedestrian) + [MWMLocationManager addObserver:self]; + else + [MWMLocationManager removeObserver:self]; + break; + case MWMNavigationInfoViewStatePrepare: + self.isVisible = YES; + [self setStreetNameVisible:NO]; + [self setTurnsViewVisible:NO]; + [MWMLocationManager addObserver:self]; + break; } } -- (void)setStreetNameVisible:(BOOL)isVisible -{ +- (void)setStreetNameVisible:(BOOL)isVisible { self.streetNameView.hidden = !isVisible; - self.streetNameViewHideOffset.priority = - isVisible ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh; + self.streetNameViewHideOffset.priority = isVisible ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh; } -- (void)setTurnsViewVisible:(BOOL)isVisible -{ +- (void)setTurnsViewVisible:(BOOL)isVisible { self.turnsView.hidden = !isVisible; - self.turnsViewHideOffset.priority = - isVisible ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh; + self.turnsViewHideOffset.priority = isVisible ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh; } -- (void)setIsVisible:(BOOL)isVisible -{ +- (void)setIsVisible:(BOOL)isVisible { if (_isVisible == isVisible) return; _isVisible = isVisible; [self setNeedsLayout]; - if (isVisible) - { + if (isVisible) { [self setSearchState:NavigationSearchState::MinimizedNormal animated:NO]; self.turnsWidth.constant = IPAD ? kTurnsiPadWidth : kTurnsiPhoneWidth; - UIView * sv = self.ownerView; + UIView *sv = self.ownerView; NSAssert(sv != nil, @"Superview can't be nil"); if ([sv.subviews containsObject:self]) return; @@ -517,36 +450,32 @@ BOOL defaultOrientation(CGSize const & size) [self configLayout]; } [UIView animateWithDuration:kDefaultAnimationDuration - animations:^{ - [self layoutIfNeeded]; - } - completion:^(BOOL finished) { - if (!isVisible) - [self removeFromSuperview]; - }]; + animations:^{ + [self layoutIfNeeded]; + } + completion:^(BOOL finished) { + if (!isVisible) + [self removeFromSuperview]; + }]; } -- (void)setToastViewHidden:(BOOL)hidden -{ +- (void)setToastViewHidden:(BOOL)hidden { if (!hidden) self.toastView.hidden = NO; [self setNeedsLayout]; - self.toastViewHideOffset.priority = - (hidden ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow); + self.toastViewHideOffset.priority = (hidden ? UILayoutPriorityDefaultHigh : UILayoutPriorityDefaultLow); [UIView animateWithDuration:kDefaultAnimationDuration - animations:^{ - [self layoutIfNeeded]; - } - completion:^(BOOL finished) { - if (hidden) - self.toastView.hidden = YES; - }]; + animations:^{ + [self layoutIfNeeded]; + } + completion:^(BOOL finished) { + if (hidden) + self.toastView.hidden = YES; + }]; } -//MARK: Update Theme -- (void)applyTheme -{ +// MARK: Update Theme +- (void)applyTheme { [self setSearchState:_searchState]; - } @end diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift index 51ef544d8d..dd78d9dc51 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/NavigationControlView.swift @@ -155,12 +155,12 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MapO let routingNumberAttributes: [NSAttributedString.Key: Any] = [ NSAttributedString.Key.foregroundColor: UIColor.blackPrimaryText(), - NSAttributedString.Key.font: UIFont.bold24(), + NSAttributedString.Key.font: UIFont.bold24() ] let routingLegendAttributes: [NSAttributedString.Key: Any] = [ NSAttributedString.Key.foregroundColor: UIColor.blackSecondaryText(), - NSAttributedString.Key.font: UIFont.bold14(), + NSAttributedString.Key.font: UIFont.bold14() ] if timePageControl.currentPage == 0 { @@ -197,7 +197,7 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MapO speedLegendLabel.textColor = textColor speedWithLegendLabel.textColor = textColor - self.routingProgress.constant = self.progressView.width * info.progress / 100 + routingProgress.constant = progressView.width * info.progress / 100 } @IBAction @@ -284,5 +284,6 @@ final class NavigationControlView: SolidTouchView, MWMTextToSpeechObserver, MapO } override var widgetsAreaAffectDirections: MWMAvailableAreaAffectDirections { - return alternative(iPhone: .bottom, iPad: []) } + return alternative(iPhone: .bottom, iPad: []) + } } diff --git a/iphone/Maps/Core/Routing/MWMRouter.mm b/iphone/Maps/Core/Routing/MWMRouter.mm index 59750e57f6..d304364622 100644 --- a/iphone/Maps/Core/Routing/MWMRouter.mm +++ b/iphone/Maps/Core/Routing/MWMRouter.mm @@ -21,39 +21,42 @@ using namespace routing; -@interface MWMRouter () +@interface MWMRouter () -@property(nonatomic) NSMutableDictionary * altitudeImagesData; -@property(nonatomic) NSString * altitudeElevation; +@property(nonatomic) NSMutableDictionary *altitudeImagesData; +@property(nonatomic) NSString *altitudeElevation; @property(nonatomic) dispatch_queue_t renderAltitudeImagesQueue; @property(nonatomic) uint32_t taxiRoutePointTransactionId; @property(nonatomic) uint32_t routeManagerTransactionId; @property(nonatomic) BOOL canAutoAddLastLocation; @property(nonatomic) BOOL isAPICall; @property(nonatomic) BOOL isRestoreProcessCompleted; -@property(strong, nonatomic) MWMRoutingOptions * routingOptions; +@property(strong, nonatomic) MWMRoutingOptions *routingOptions; + (MWMRouter *)router; @end -namespace -{ -char const * kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeImagesQueue"; +namespace { +char const *kRenderAltitudeImagesQueueLabel = "mapsme.mwmrouter.renderAltitudeImagesQueue"; -void logPointEvent(MWMRoutePoint * point, NSString * eventType) -{ +void logPointEvent(MWMRoutePoint *point, NSString *eventType) { if (point == nullptr) return; - NSString * pointTypeStr = nil; - switch (point.type) - { - case MWMRoutePointTypeStart: pointTypeStr = kStatRoutingPointTypeStart; break; - case MWMRoutePointTypeIntermediate: pointTypeStr = kStatRoutingPointTypeIntermediate; break; - case MWMRoutePointTypeFinish: pointTypeStr = kStatRoutingPointTypeFinish; break; + NSString *pointTypeStr = nil; + switch (point.type) { + case MWMRoutePointTypeStart: + pointTypeStr = kStatRoutingPointTypeStart; + break; + case MWMRoutePointTypeIntermediate: + pointTypeStr = kStatRoutingPointTypeIntermediate; + break; + case MWMRoutePointTypeFinish: + pointTypeStr = kStatRoutingPointTypeFinish; + break; } - NSString * method = nil; + NSString *method = nil; if ([MWMRouter router].isAPICall) method = kStatRoutingPointMethodApi; else if ([MWMNavigationDashboardManager sharedManager].state != MWMNavigationDashboardStateHidden) @@ -63,8 +66,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [Statistics logEvent:eventType withParameters:@{ kStatRoutingPointType: pointTypeStr, - kStatRoutingPointValue: - (point.isMyPosition ? kStatRoutingPointValueMyPosition : kStatRoutingPointValuePoint), + kStatRoutingPointValue: (point.isMyPosition ? kStatRoutingPointValueMyPosition : kStatRoutingPointValuePoint), kStatRoutingPointMethod: method, kStatMode: ([MWMRouter isOnRoute] ? kStatRoutingModeOnRoute : kStatRoutingModePlanning) }]; @@ -73,9 +75,8 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) @implementation MWMRouter -+ (MWMRouter *)router -{ - static MWMRouter * router; ++ (MWMRouter *)router { + static MWMRouter *router; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ router = [[self alloc] initRouter]; @@ -83,143 +84,155 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) return router; } -+ (BOOL)hasRouteAltitude -{ - switch ([self type]) - { - case MWMRouterTypeVehicle: - case MWMRouterTypePublicTransport: - case MWMRouterTypeTaxi: return NO; - case MWMRouterTypePedestrian: - case MWMRouterTypeBicycle: return GetFramework().GetRoutingManager().HasRouteAltitude(); ++ (BOOL)hasRouteAltitude { + switch ([self type]) { + case MWMRouterTypeVehicle: + case MWMRouterTypePublicTransport: + case MWMRouterTypeTaxi: + return NO; + case MWMRouterTypePedestrian: + case MWMRouterTypeBicycle: + return GetFramework().GetRoutingManager().HasRouteAltitude(); } } -+ (BOOL)isTaxi -{ ++ (BOOL)isTaxi { return GetFramework().GetRoutingManager().GetRouter() == routing::RouterType::Taxi; } -+ (void)startRouting -{ - if (![self isTaxi]) - { ++ (void)startRouting { + if (![self isTaxi]) { [self start]; return; } auto taxiDataSource = [MWMNavigationDashboardManager sharedManager].taxiDataSource; - auto & rm = GetFramework().GetRoutingManager(); + auto &rm = GetFramework().GetRoutingManager(); auto const routePoints = rm.GetRoutePoints(); - if (routePoints.size() >= 2) - { - auto eventName = - taxiDataSource.isTaxiInstalled ? kStatRoutingTaxiOrder : kStatRoutingTaxiInstall; + if (routePoints.size() >= 2) { + auto eventName = taxiDataSource.isTaxiInstalled ? kStatRoutingTaxiOrder : kStatRoutingTaxiInstall; auto p1 = [[MWMRoutePoint alloc] initWithRouteMarkData:routePoints.front()]; auto p2 = [[MWMRoutePoint alloc] initWithRouteMarkData:routePoints.back()]; - NSString * provider = nil; - switch (taxiDataSource.type) - { - case MWMRoutePreviewTaxiCellTypeTaxi: provider = kStatUnknown; break; - case MWMRoutePreviewTaxiCellTypeUber: provider = kStatUber; break; - case MWMRoutePreviewTaxiCellTypeYandex: provider = kStatYandex; break; - case MWMRoutePreviewTaxiCellTypeMaxim: provider = kStatMaxim; break; - case MWMRoutePreviewTaxiCellTypeVezet: provider = kStatVezet; break; - case MWMRoutePreviewTaxiCellTypeFreenow: provider = kStatFreenow; break; - case MWMRoutePreviewTaxiCellTypeYango: provider = kStatYango; break; - case MWMRoutePreviewTaxiCellTypeCitymobil: provider = kStatCitymobil; break; + NSString *provider = nil; + switch (taxiDataSource.type) { + case MWMRoutePreviewTaxiCellTypeTaxi: + provider = kStatUnknown; + break; + case MWMRoutePreviewTaxiCellTypeUber: + provider = kStatUber; + break; + case MWMRoutePreviewTaxiCellTypeYandex: + provider = kStatYandex; + break; + case MWMRoutePreviewTaxiCellTypeMaxim: + provider = kStatMaxim; + break; + case MWMRoutePreviewTaxiCellTypeVezet: + provider = kStatVezet; + break; + case MWMRoutePreviewTaxiCellTypeFreenow: + provider = kStatFreenow; + break; + case MWMRoutePreviewTaxiCellTypeYango: + provider = kStatYango; + break; + case MWMRoutePreviewTaxiCellTypeCitymobil: + provider = kStatCitymobil; + break; } [Statistics logEvent:eventName withParameters:@{ - kStatProvider : provider, - kStatFromLocation : makeLocationEventValue(p1.latitude, p1.longitude), - kStatToLocation : makeLocationEventValue(p2.latitude, p2.longitude) + kStatProvider: provider, + kStatFromLocation: makeLocationEventValue(p1.latitude, p1.longitude), + kStatToLocation: makeLocationEventValue(p2.latitude, p2.longitude) } atLocation:[MWMLocationManager lastLocation]]; - } - else - { - auto err = [[NSError alloc] initWithDomain:kMapsmeErrorDomain - code:5 - userInfo:@{ - @"Description" : @"Invalid number of taxi route points", - @"Count" : @(routePoints.size()) - }]; + } else { + auto err = [[NSError alloc] + initWithDomain:kMapsmeErrorDomain + code:5 + userInfo:@{@"Description": @"Invalid number of taxi route points", @"Count": @(routePoints.size())}]; [[FIRCrashlytics crashlytics] recordError:err]; } - [taxiDataSource taxiURL:^(NSURL * url) { + [taxiDataSource taxiURL:^(NSURL *url) { [UIApplication.sharedApplication openURL:url options:@{} completionHandler:nil]; }]; } -+ (void)stopRouting -{ ++ (void)stopRouting { auto type = GetFramework().GetRoutingManager().GetRouter(); - [Statistics logEvent:kStatRoutingRouteFinish withParameters:@{ - kStatMode : @(routing::ToString(type).c_str()), - kStatRoutingInterrupted : @([self isRouteFinished]) - }]; + [Statistics logEvent:kStatRoutingRouteFinish + withParameters:@{ + kStatMode: @(routing::ToString(type).c_str()), + kStatRoutingInterrupted: @([self isRouteFinished]) + }]; [self stop:YES]; } -+ (BOOL)isRoutingActive { return GetFramework().GetRoutingManager().IsRoutingActive(); } -+ (BOOL)isRouteBuilt { return GetFramework().GetRoutingManager().IsRouteBuilt(); } -+ (BOOL)isRouteFinished { return GetFramework().GetRoutingManager().IsRouteFinished(); } -+ (BOOL)isRouteRebuildingOnly { return GetFramework().GetRoutingManager().IsRouteRebuildingOnly(); } -+ (BOOL)isOnRoute { return GetFramework().GetRoutingManager().IsRoutingFollowing(); } -+ (BOOL)IsRouteValid { return GetFramework().GetRoutingManager().IsRouteValid(); } -+ (NSArray *)points -{ - NSMutableArray * points = [@[] mutableCopy]; ++ (BOOL)isRoutingActive { + return GetFramework().GetRoutingManager().IsRoutingActive(); +} ++ (BOOL)isRouteBuilt { + return GetFramework().GetRoutingManager().IsRouteBuilt(); +} ++ (BOOL)isRouteFinished { + return GetFramework().GetRoutingManager().IsRouteFinished(); +} ++ (BOOL)isRouteRebuildingOnly { + return GetFramework().GetRoutingManager().IsRouteRebuildingOnly(); +} ++ (BOOL)isOnRoute { + return GetFramework().GetRoutingManager().IsRoutingFollowing(); +} ++ (BOOL)IsRouteValid { + return GetFramework().GetRoutingManager().IsRouteValid(); +} ++ (NSArray *)points { + NSMutableArray *points = [@[] mutableCopy]; auto const routePoints = GetFramework().GetRoutingManager().GetRoutePoints(); - for (auto const & routePoint : routePoints) + for (auto const &routePoint : routePoints) [points addObject:[[MWMRoutePoint alloc] initWithRouteMarkData:routePoint]]; return [points copy]; } -+ (NSInteger)pointsCount { return GetFramework().GetRoutingManager().GetRoutePointsCount(); } -+ (MWMRoutePoint *)startPoint -{ ++ (NSInteger)pointsCount { + return GetFramework().GetRoutingManager().GetRoutePointsCount(); +} ++ (MWMRoutePoint *)startPoint { auto const routePoints = GetFramework().GetRoutingManager().GetRoutePoints(); if (routePoints.empty()) return nil; - auto const & routePoint = routePoints.front(); + auto const &routePoint = routePoints.front(); if (routePoint.m_pointType == RouteMarkType::Start) return [[MWMRoutePoint alloc] initWithRouteMarkData:routePoint]; return nil; } -+ (MWMRoutePoint *)finishPoint -{ ++ (MWMRoutePoint *)finishPoint { auto const routePoints = GetFramework().GetRoutingManager().GetRoutePoints(); if (routePoints.empty()) return nil; - auto const & routePoint = routePoints.back(); + auto const &routePoint = routePoints.back(); if (routePoint.m_pointType == RouteMarkType::Finish) return [[MWMRoutePoint alloc] initWithRouteMarkData:routePoint]; return nil; } -+ (void)enableAutoAddLastLocation:(BOOL)enable -{ ++ (void)enableAutoAddLastLocation:(BOOL)enable { [MWMRouter router].canAutoAddLastLocation = enable; } -+ (BOOL)canAddIntermediatePoint -{ ++ (BOOL)canAddIntermediatePoint { return GetFramework().GetRoutingManager().CouldAddIntermediatePoint() && ![MWMRouter isTaxi]; } -- (instancetype)initRouter -{ +- (instancetype)initRouter { self = [super init]; - if (self) - { + if (self) { self.altitudeImagesData = [@{} mutableCopy]; - self.renderAltitudeImagesQueue = - dispatch_queue_create(kRenderAltitudeImagesQueueLabel, DISPATCH_QUEUE_SERIAL); + self.renderAltitudeImagesQueue = dispatch_queue_create(kRenderAltitudeImagesQueueLabel, DISPATCH_QUEUE_SERIAL); self.taxiRoutePointTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); self.routeManagerTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); [MWMLocationManager addObserver:self]; @@ -231,23 +244,20 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) return self; } -+ (void)subscribeToEvents -{ ++ (void)subscribeToEvents { [MWMFrameworkListener addObserver:[MWMRouter router]]; [MWMLocationManager addObserver:[MWMRouter router]]; } -+ (void)unsubscribeFromEvents -{ ++ (void)unsubscribeFromEvents { [MWMFrameworkListener removeObserver:[MWMRouter router]]; [MWMLocationManager removeObserver:[MWMRouter router]]; } -+ (void)setType:(MWMRouterType)type -{ ++ (void)setType:(MWMRouterType)type { if (type == self.type) return; - + if (type == MWMRouterTypeTaxi) [self openTaxiTransaction]; else @@ -257,65 +267,59 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) GetFramework().GetRoutingManager().SetRouter(coreRouterType(type)); } -+ (void)openTaxiTransaction -{ - auto & rm = GetFramework().GetRoutingManager(); ++ (void)openTaxiTransaction { + auto &rm = GetFramework().GetRoutingManager(); auto router = [MWMRouter router]; router.taxiRoutePointTransactionId = rm.OpenRoutePointsTransaction(); rm.RemoveIntermediateRoutePoints(); } -+ (void)cancelTaxiTransaction -{ ++ (void)cancelTaxiTransaction { auto router = [MWMRouter router]; - if (router.taxiRoutePointTransactionId != RoutingManager::InvalidRoutePointsTransactionId()) - { + if (router.taxiRoutePointTransactionId != RoutingManager::InvalidRoutePointsTransactionId()) { GetFramework().GetRoutingManager().CancelRoutePointsTransaction(router.taxiRoutePointTransactionId); router.taxiRoutePointTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); } } -+ (void)applyTaxiTransaction -{ ++ (void)applyTaxiTransaction { // We have to apply taxi transaction each time we add/remove points after switch to taxi mode. auto router = [MWMRouter router]; - if (router.taxiRoutePointTransactionId != RoutingManager::InvalidRoutePointsTransactionId()) - { + if (router.taxiRoutePointTransactionId != RoutingManager::InvalidRoutePointsTransactionId()) { GetFramework().GetRoutingManager().ApplyRoutePointsTransaction(router.taxiRoutePointTransactionId); router.taxiRoutePointTransactionId = RoutingManager::InvalidRoutePointsTransactionId(); } } -+ (MWMRouterType)type { return routerType(GetFramework().GetRoutingManager().GetRouter()); } -+ (void)disableFollowMode { GetFramework().GetRoutingManager().DisableFollowMode(); } -+ (void)enableTurnNotifications:(BOOL)active -{ ++ (MWMRouterType)type { + return routerType(GetFramework().GetRoutingManager().GetRouter()); +} ++ (void)disableFollowMode { + GetFramework().GetRoutingManager().DisableFollowMode(); +} ++ (void)enableTurnNotifications:(BOOL)active { GetFramework().GetRoutingManager().EnableTurnNotifications(active); } -+ (BOOL)areTurnNotificationsEnabled -{ ++ (BOOL)areTurnNotificationsEnabled { return GetFramework().GetRoutingManager().AreTurnNotificationsEnabled(); } -+ (void)setTurnNotificationsLocale:(NSString *)locale -{ ++ (void)setTurnNotificationsLocale:(NSString *)locale { GetFramework().GetRoutingManager().SetTurnNotificationsLocale(locale.UTF8String); } -+ (NSArray *)turnNotifications -{ - NSMutableArray * turnNotifications = [@[] mutableCopy]; ++ (NSArray *)turnNotifications { + NSMutableArray *turnNotifications = [@[] mutableCopy]; std::vector notifications; GetFramework().GetRoutingManager().GenerateNotifications(notifications); - for (auto const & text : notifications) + for (auto const &text : notifications) [turnNotifications addObject:@(text.c_str())]; return [turnNotifications copy]; } -+ (void)removePoint:(MWMRoutePoint *)point -{ ++ (void)removePoint:(MWMRoutePoint *)point { logPointEvent(point, kStatRoutingRemovePoint); [self applyTaxiTransaction]; RouteMarkData pt = point.routeMarkData; @@ -323,19 +327,18 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [[MWMNavigationDashboardManager sharedManager] onRoutePointsUpdated]; } -+ (void)removePointAndRebuild:(MWMRoutePoint *)point -{ ++ (void)removePointAndRebuild:(MWMRoutePoint *)point { if (!point) return; [self removePoint:point]; [self rebuildWithBestRouter:NO]; } -+ (void)removePoints { GetFramework().GetRoutingManager().RemoveRoutePoints(); } -+ (void)addPoint:(MWMRoutePoint *)point -{ - if (!point) - { ++ (void)removePoints { + GetFramework().GetRoutingManager().RemoveRoutePoints(); +} ++ (void)addPoint:(MWMRoutePoint *)point { + if (!point) { NSAssert(NO, @"Point can not be nil"); return; } @@ -346,32 +349,26 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [[MWMNavigationDashboardManager sharedManager] onRoutePointsUpdated]; } -+ (void)addPointAndRebuild:(MWMRoutePoint *)point -{ ++ (void)addPointAndRebuild:(MWMRoutePoint *)point { if (!point) return; [self addPoint:point]; [self rebuildWithBestRouter:NO]; } -+ (void)buildFromPoint:(MWMRoutePoint *)startPoint bestRouter:(BOOL)bestRouter -{ ++ (void)buildFromPoint:(MWMRoutePoint *)startPoint bestRouter:(BOOL)bestRouter { if (!startPoint) return; [self addPoint:startPoint]; [self rebuildWithBestRouter:bestRouter]; } -+ (void)buildToPoint:(MWMRoutePoint *)finishPoint bestRouter:(BOOL)bestRouter -{ ++ (void)buildToPoint:(MWMRoutePoint *)finishPoint bestRouter:(BOOL)bestRouter { if (!finishPoint) return; [self addPoint:finishPoint]; - if (![self startPoint] && [MWMLocationManager lastLocation] && - [MWMRouter router].canAutoAddLastLocation) - { - [self addPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart - intermediateIndex:0]]; + if (![self startPoint] && [MWMLocationManager lastLocation] && [MWMRouter router].canAutoAddLastLocation) { + [self addPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart intermediateIndex:0]]; } if ([self startPoint] && [self finishPoint]) [self rebuildWithBestRouter:bestRouter]; @@ -379,8 +376,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) + (void)buildApiRouteWithType:(MWMRouterType)type startPoint:(MWMRoutePoint *)startPoint - finishPoint:(MWMRoutePoint *)finishPoint -{ + finishPoint:(MWMRoutePoint *)finishPoint { if (!startPoint || !finishPoint) return; @@ -395,35 +391,27 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [self rebuildWithBestRouter:NO]; } -+ (void)rebuildWithBestRouter:(BOOL)bestRouter -{ ++ (void)rebuildWithBestRouter:(BOOL)bestRouter { [self clearAltitudeImagesData]; - auto & rm = GetFramework().GetRoutingManager(); - auto const & points = rm.GetRoutePoints(); + auto &rm = GetFramework().GetRoutingManager(); + auto const &points = rm.GetRoutePoints(); auto const pointsCount = points.size(); - if (pointsCount < 2) - { + if (pointsCount < 2) { [self doStop:NO]; [[MWMMapViewControlsManager manager] onRoutePrepare]; return; } - if (pointsCount == 2) - { - if (points.front().m_isMyPosition) - { + if (pointsCount == 2) { + if (points.front().m_isMyPosition) { [Statistics logEvent:kStatPointToPoint - withParameters:@{kStatAction : kStatBuildRoute, kStatValue : kStatFromMyPosition}]; - } - else if (points.back().m_isMyPosition) - { + withParameters:@{kStatAction: kStatBuildRoute, kStatValue: kStatFromMyPosition}]; + } else if (points.back().m_isMyPosition) { [Statistics logEvent:kStatPointToPoint - withParameters:@{kStatAction : kStatBuildRoute, kStatValue : kStatToMyPosition}]; - } - else - { + withParameters:@{kStatAction: kStatBuildRoute, kStatValue: kStatToMyPosition}]; + } else { [Statistics logEvent:kStatPointToPoint - withParameters:@{kStatAction : kStatBuildRoute, kStatValue : kStatPointToPoint}]; + withParameters:@{kStatAction: kStatBuildRoute, kStatValue: kStatPointToPoint}]; } } @@ -435,74 +423,61 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) rm.BuildRoute(); } -+ (void)start -{ ++ (void)start { [self saveRoute]; auto const doStart = ^{ - auto & rm = GetFramework().GetRoutingManager(); + auto &rm = GetFramework().GetRoutingManager(); auto const routePoints = rm.GetRoutePoints(); - if (routePoints.size() >= 2) - { + if (routePoints.size() >= 2) { auto p1 = [[MWMRoutePoint alloc] initWithRouteMarkData:routePoints.front()]; auto p2 = [[MWMRoutePoint alloc] initWithRouteMarkData:routePoints.back()]; if (p1.isMyPosition) [Statistics logEvent:kStatEventName(kStatPointToPoint, kStatGo) - withParameters:@{kStatValue : kStatFromMyPosition}]; + withParameters:@{kStatValue: kStatFromMyPosition}]; else if (p2.isMyPosition) [Statistics logEvent:kStatEventName(kStatPointToPoint, kStatGo) - withParameters:@{kStatValue : kStatToMyPosition}]; + withParameters:@{kStatValue: kStatToMyPosition}]; else [Statistics logEvent:kStatEventName(kStatPointToPoint, kStatGo) - withParameters:@{kStatValue : kStatPointToPoint}]; + withParameters:@{kStatValue: kStatPointToPoint}]; auto type = GetFramework().GetRoutingManager().GetRouter(); [Statistics logEvent:kStatRoutingRouteStart withParameters:@{ - kStatMode : @(routing::ToString(type).c_str()), - kStatTraffic : @(GetFramework().GetTrafficManager().IsEnabled()) - }]; + kStatMode: @(routing::ToString(type).c_str()), + kStatTraffic: @(GetFramework().GetTrafficManager().IsEnabled()) + }]; - if (p1.isMyPosition && [MWMLocationManager lastLocation]) - { + if (p1.isMyPosition && [MWMLocationManager lastLocation]) { rm.FollowRoute(); [[MWMMapViewControlsManager manager] onRouteStart]; [MWMThemeManager setAutoUpdates:YES]; + } else { + MWMAlertViewController *alertController = [MWMAlertViewController activeAlertController]; + CLLocation *lastLocation = [MWMLocationManager lastLocation]; + BOOL const needToRebuild = + lastLocation && !location_helpers::isMyPositionPendingOrNoPosition() && !p2.isMyPosition; + [alertController + presentPoint2PointAlertWithOkBlock:^{ + [self buildFromPoint:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart + intermediateIndex:0] + bestRouter:NO]; + } + needToRebuild:needToRebuild]; } - else - { - MWMAlertViewController * alertController = [MWMAlertViewController activeAlertController]; - CLLocation * lastLocation = [MWMLocationManager lastLocation]; - BOOL const needToRebuild = lastLocation && - !location_helpers::isMyPositionPendingOrNoPosition() && - !p2.isMyPosition; - [alertController presentPoint2PointAlertWithOkBlock:^{ - [self buildFromPoint:[[MWMRoutePoint alloc] - initWithLastLocationAndType:MWMRoutePointTypeStart - intermediateIndex:0] - bestRouter:NO]; - } - needToRebuild:needToRebuild]; - } - } - else - { - auto err = [[NSError alloc] initWithDomain:kMapsmeErrorDomain - code:5 - userInfo:@{ - @"Description" : @"Invalid number of route points", - @"Count" : @(routePoints.size()) - }]; + } else { + auto err = [[NSError alloc] + initWithDomain:kMapsmeErrorDomain + code:5 + userInfo:@{@"Description": @"Invalid number of route points", @"Count": @(routePoints.size())}]; [[FIRCrashlytics crashlytics] recordError:err]; } }; - if ([MWMSettings routingDisclaimerApproved]) - { + if ([MWMSettings routingDisclaimerApproved]) { doStart(); - } - else - { + } else { [[MWMAlertViewController activeAlertController] presentRoutingDisclaimerAlertWithOkBlock:^{ doStart(); [MWMSettings setRoutingDisclaimerApproved]; @@ -510,8 +485,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) } } -+ (void)stop:(BOOL)removeRoutePoints -{ ++ (void)stop:(BOOL)removeRoutePoints { [self doStop:removeRoutePoints]; // Don't save taxi routing type as default. if ([MWMRouter isTaxi]) @@ -520,8 +494,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [MWMRouter router].canAutoAddLastLocation = YES; } -+ (void)doStop:(BOOL)removeRoutePoints -{ ++ (void)doStop:(BOOL)removeRoutePoints { [self clearAltitudeImagesData]; GetFramework().GetRoutingManager().CloseRouting(removeRoutePoints); if (removeRoutePoints) @@ -530,11 +503,10 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [[MapsAppDelegate theApp] showAlertIfRequired]; } -- (void)updateFollowingInfo -{ +- (void)updateFollowingInfo { if (![MWMRouter isRoutingActive]) return; - auto const & rm = GetFramework().GetRoutingManager(); + auto const &rm = GetFramework().GetRoutingManager(); routing::FollowingInfo info; rm.GetRouteFollowingInfo(info); auto navManager = [MWMNavigationDashboardManager sharedManager]; @@ -546,8 +518,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) [navManager updateFollowingInfo:info type:[MWMRouter type]]; } -+ (void)routeAltitudeImageForSize:(CGSize)size completion:(MWMImageHeightBlock)block -{ ++ (void)routeAltitudeImageForSize:(CGSize)size completion:(MWMImageHeightBlock)block { if (![self hasRouteAltitude]) return; @@ -557,7 +528,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) return; // Note. |routePointDistanceM| and |altitudes| should not be used in the method after line below. - dispatch_async(self.router.renderAltitudeImagesQueue, [=] () { + dispatch_async(self.router.renderAltitudeImagesQueue, [=]() { auto router = self.router; CGFloat const screenScale = [UIScreen mainScreen].scale; CGSize const scaledSize = {size.width * screenScale, size.height * screenScale}; @@ -568,22 +539,17 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) if (width == 0 || height == 0) return; - NSValue * sizeValue = [NSValue valueWithCGSize:scaledSize]; - NSData * imageData = router.altitudeImagesData[sizeValue]; - if (!imageData) - { + NSValue *sizeValue = [NSValue valueWithCGSize:scaledSize]; + NSData *imageData = router.altitudeImagesData[sizeValue]; + if (!imageData) { std::vector imageRGBAData; int32_t minRouteAltitude = 0; int32_t maxRouteAltitude = 0; measurement_utils::Units units = measurement_utils::Units::Metric; - - if(!GetFramework().GetRoutingManager().GenerateRouteAltitudeChart(width, height, - *altitudes, - *routePointDistanceM, - imageRGBAData, - minRouteAltitude, - maxRouteAltitude, units)) - { + + if (!GetFramework().GetRoutingManager().GenerateRouteAltitudeChart(width, height, *altitudes, + *routePointDistanceM, imageRGBAData, + minRouteAltitude, maxRouteAltitude, units)) { return; } @@ -599,15 +565,14 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) } dispatch_async(dispatch_get_main_queue(), ^{ - UIImage * altitudeImage = [UIImage imageWithRGBAData:imageData width:width height:height]; + UIImage *altitudeImage = [UIImage imageWithRGBAData:imageData width:width height:height]; if (altitudeImage) block(altitudeImage, router.altitudeElevation); }); }); } -+ (void)clearAltitudeImagesData -{ ++ (void)clearAltitudeImagesData { auto router = self.router; dispatch_async(router.renderAltitudeImagesQueue, ^{ [router.altitudeImagesData removeAllObjects]; @@ -617,14 +582,12 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) #pragma mark - MWMLocationObserver -- (void)onLocationUpdate:(CLLocation *)location -{ +- (void)onLocationUpdate:(CLLocation *)location { if (![MWMRouter isRoutingActive]) return; auto tts = [MWMTextToSpeech tts]; NSArray *turnNotifications = [MWMRouter turnNotifications]; - if ([MWMRouter isOnRoute] && tts.active) - { + if ([MWMRouter isOnRoute] && tts.active) { [tts playTurnNotifications:turnNotifications]; [tts playWarningSound]; } @@ -634,14 +597,12 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) #pragma mark - MWMFrameworkRouteBuilderObserver -- (void)onRouteReady:(BOOL)hasWarnings -{ +- (void)onRouteReady:(BOOL)hasWarnings { self.routingOptions = [MWMRoutingOptions new]; GetFramework().DeactivateMapSelection(true); auto startPoint = [MWMRouter startPoint]; - if (!startPoint || !startPoint.isMyPosition) - { + if (!startPoint || !startPoint.isMyPosition) { dispatch_async(dispatch_get_main_queue(), ^{ [MWMRouter disableFollowMode]; }); @@ -652,155 +613,135 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) } - (void)processRouteBuilderEvent:(routing::RouterResultCode)code - countries:(storage::CountriesSet const &)absentCountries -{ - MWMMapViewControlsManager * mapViewControlsManager = [MWMMapViewControlsManager manager]; - switch (code) - { - case routing::RouterResultCode::NoError: - [self onRouteReady:NO]; - break; - case routing::RouterResultCode::HasWarnings: - [self onRouteReady:YES]; - break; - case routing::RouterResultCode::RouteFileNotExist: - case routing::RouterResultCode::InconsistentMWMandRoute: - case routing::RouterResultCode::NeedMoreMaps: - case routing::RouterResultCode::FileTooOld: - case routing::RouterResultCode::RouteNotFound: - if ([MWMRouter isTaxi]) - return; - self.routingOptions = [MWMRoutingOptions new]; - [self presentDownloaderAlert:code countries:absentCountries]; - [[MWMNavigationDashboardManager sharedManager] onRouteError:L(@"routing_planning_error")]; - break; - case routing::RouterResultCode::Cancelled: - [mapViewControlsManager onRoutePrepare]; - break; - case routing::RouterResultCode::StartPointNotFound: - case routing::RouterResultCode::EndPointNotFound: - case routing::RouterResultCode::NoCurrentPosition: - case routing::RouterResultCode::PointsInDifferentMWM: - case routing::RouterResultCode::InternalError: - case routing::RouterResultCode::IntermediatePointNotFound: - case routing::RouterResultCode::TransitRouteNotFoundNoNetwork: - case routing::RouterResultCode::TransitRouteNotFoundTooLongPedestrian: - case routing::RouterResultCode::RouteNotFoundRedressRouteError: - if ([MWMRouter isTaxi]) - return; - [[MWMAlertViewController activeAlertController] presentAlert:code]; - [[MWMNavigationDashboardManager sharedManager] onRouteError:L(@"routing_planning_error")]; - break; + countries:(storage::CountriesSet const &)absentCountries { + MWMMapViewControlsManager *mapViewControlsManager = [MWMMapViewControlsManager manager]; + switch (code) { + case routing::RouterResultCode::NoError: + [self onRouteReady:NO]; + break; + case routing::RouterResultCode::HasWarnings: + [self onRouteReady:YES]; + break; + case routing::RouterResultCode::RouteFileNotExist: + case routing::RouterResultCode::InconsistentMWMandRoute: + case routing::RouterResultCode::NeedMoreMaps: + case routing::RouterResultCode::FileTooOld: + case routing::RouterResultCode::RouteNotFound: + if ([MWMRouter isTaxi]) + return; + self.routingOptions = [MWMRoutingOptions new]; + [self presentDownloaderAlert:code countries:absentCountries]; + [[MWMNavigationDashboardManager sharedManager] onRouteError:L(@"routing_planning_error")]; + break; + case routing::RouterResultCode::Cancelled: + [mapViewControlsManager onRoutePrepare]; + break; + case routing::RouterResultCode::StartPointNotFound: + case routing::RouterResultCode::EndPointNotFound: + case routing::RouterResultCode::NoCurrentPosition: + case routing::RouterResultCode::PointsInDifferentMWM: + case routing::RouterResultCode::InternalError: + case routing::RouterResultCode::IntermediatePointNotFound: + case routing::RouterResultCode::TransitRouteNotFoundNoNetwork: + case routing::RouterResultCode::TransitRouteNotFoundTooLongPedestrian: + case routing::RouterResultCode::RouteNotFoundRedressRouteError: + if ([MWMRouter isTaxi]) + return; + [[MWMAlertViewController activeAlertController] presentAlert:code]; + [[MWMNavigationDashboardManager sharedManager] onRouteError:L(@"routing_planning_error")]; + break; } } -- (void)processRouteBuilderProgress:(CGFloat)progress -{ +- (void)processRouteBuilderProgress:(CGFloat)progress { if (![MWMRouter isTaxi]) [[MWMNavigationDashboardManager sharedManager] setRouteBuilderProgress:progress]; } -- (void)processRouteRecommendation:(MWMRouterRecommendation)recommendation -{ - switch (recommendation) - { - case MWMRouterRecommendationRebuildAfterPointsLoading: - [MWMRouter - addPointAndRebuild:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart - intermediateIndex:0]]; - break; +- (void)processRouteRecommendation:(MWMRouterRecommendation)recommendation { + switch (recommendation) { + case MWMRouterRecommendationRebuildAfterPointsLoading: + [MWMRouter addPointAndRebuild:[[MWMRoutePoint alloc] initWithLastLocationAndType:MWMRoutePointTypeStart + intermediateIndex:0]]; + break; } } #pragma mark - Alerts -- (void)presentDownloaderAlert:(routing::RouterResultCode)code - countries:(storage::CountriesSet const &)countries -{ - MWMAlertViewController * activeAlertController = [MWMAlertViewController activeAlertController]; - if (!countries.empty()) - { +- (void)presentDownloaderAlert:(routing::RouterResultCode)code countries:(storage::CountriesSet const &)countries { + MWMAlertViewController *activeAlertController = [MWMAlertViewController activeAlertController]; + if (!countries.empty()) { [activeAlertController presentDownloaderAlertWithCountries:countries - code:code - cancelBlock:^{ - if (code != routing::RouterResultCode::NeedMoreMaps) - [MWMRouter stopRouting]; + code:code + cancelBlock:^{ + if (code != routing::RouterResultCode::NeedMoreMaps) + [MWMRouter stopRouting]; + } + downloadBlock:^(storage::CountriesVec const &downloadCountries, MWMVoidBlock onSuccess) { + NSMutableArray *array = [NSMutableArray arrayWithCapacity:downloadCountries.size()]; + for (auto const &cid : downloadCountries) { + [array addObject:@(cid.c_str())]; } - downloadBlock:^(storage::CountriesVec const & downloadCountries, MWMVoidBlock onSuccess) { - NSMutableArray *array = [NSMutableArray arrayWithCapacity:downloadCountries.size()]; - for (auto const &cid : downloadCountries) { - [array addObject:@(cid.c_str())]; - } - [[MWMStorage sharedStorage] downloadNodes:array onSuccess:onSuccess]; - } - downloadCompleteBlock:^{ - [MWMRouter rebuildWithBestRouter:NO]; - }]; - } - else if ([MWMRouter hasActiveDrivingOptions]) - { + [[MWMStorage sharedStorage] downloadNodes:array onSuccess:onSuccess]; + } + downloadCompleteBlock:^{ + [MWMRouter rebuildWithBestRouter:NO]; + }]; + } else if ([MWMRouter hasActiveDrivingOptions]) { [activeAlertController presentDefaultAlertWithTitle:L(@"unable_to_calc_alert_title") message:L(@"unable_to_calc_alert_subtitle") rightButtonTitle:L(@"settings") leftButtonTitle:L(@"cancel") rightButtonAction:^{ [[MapViewController sharedController] openDrivingOptions]; - }]; - } - else - { + }]; + } else { [activeAlertController presentAlert:code]; } } #pragma mark - Save / Load route points -+ (void)saveRoute { GetFramework().GetRoutingManager().SaveRoutePoints(); } ++ (void)saveRoute { + GetFramework().GetRoutingManager().SaveRoutePoints(); +} -+ (void)saveRouteIfNeeded -{ ++ (void)saveRouteIfNeeded { if ([self isOnRoute]) [self saveRoute]; } -+ (void)restoreRouteIfNeeded -{ - if ([MapsAppDelegate theApp].isDrapeEngineCreated) - { - auto & rm = GetFramework().GetRoutingManager(); ++ (void)restoreRouteIfNeeded { + if ([MapsAppDelegate theApp].isDrapeEngineCreated) { + auto &rm = GetFramework().GetRoutingManager(); if ([self isRoutingActive] || ![self hasSavedRoute]) { self.router.isRestoreProcessCompleted = YES; return; } - rm.LoadRoutePoints([self](bool success) - { + rm.LoadRoutePoints([self](bool success) { if (success) [self rebuildWithBestRouter:YES]; self.router.isRestoreProcessCompleted = YES; }); - } - else - { + } else { dispatch_async(dispatch_get_main_queue(), ^{ [self restoreRouteIfNeeded]; }); } } -+ (BOOL)isRestoreProcessCompleted -{ ++ (BOOL)isRestoreProcessCompleted { return self.router.isRestoreProcessCompleted; } -+ (BOOL)hasSavedRoute -{ ++ (BOOL)hasSavedRoute { return GetFramework().GetRoutingManager().HasSavedRoutePoints(); } + (void)updateRoute { MWMRoutingOptions *newOptions = [MWMRoutingOptions new]; - if ((self.isRoutingActive && !self.isOnRoute) - && ![newOptions isEqual:[self router].routingOptions]) { + if ((self.isRoutingActive && !self.isOnRoute) && ![newOptions isEqual:[self router].routingOptions]) { [self rebuildWithBestRouter:YES]; } } @@ -811,7 +752,7 @@ void logPointEvent(MWMRoutePoint * point, NSString * eventType) + (void)avoidRoadTypeAndRebuild:(MWMRoadType)type { MWMRoutingOptions *options = [MWMRoutingOptions new]; - switch(type) { + switch (type) { case MWMRoadTypeToll: options.avoidToll = YES; break;