From 14d8fb0e17b78b886e16fa12bac649e38769ee31 Mon Sep 17 00:00:00 2001 From: Kiryl <79797627+kirylkaveryn@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:07:02 +0400 Subject: [PATCH] [ios] Fix the route estimates colors when the app appearance was changed (#7331) * [ios] fix: route estimates color when the app appearance was changed Signed-off-by: Kiryl Kaveryn * [ios] fix: MWMNavigationDashboardManager+Entity.mm formatting Signed-off-by: Kiryl Kaveryn --------- Signed-off-by: Kiryl Kaveryn --- .../MWMNavigationDashboardEntity.h | 3 +- .../MWMNavigationDashboardManager+Entity.mm | 128 +++++++++--------- .../MWMNavigationDashboardManager.mm | 16 --- .../BaseRoutePreviewStatus.swift | 3 +- .../TransportRoutePreviewStatus.swift | 4 +- 5 files changed, 71 insertions(+), 83 deletions(-) diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardEntity.h b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardEntity.h index 2639e5df51..56f42340fd 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardEntity.h +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardEntity.h @@ -3,7 +3,6 @@ @interface MWMNavigationDashboardEntity : NSObject @property(copy, nonatomic, readonly) NSArray *transitSteps; -@property(copy, nonatomic, readonly) NSAttributedString *estimate; @property(copy, nonatomic, readonly) NSString *distanceToTurn; @property(copy, nonatomic, readonly) NSString *streetName; @property(copy, nonatomic, readonly) NSString *targetDistance; @@ -19,6 +18,8 @@ @property(nonatomic, readonly) NSString * arrival; +- (NSAttributedString *) estimate; + + (NSAttributedString *) estimateDot; + (instancetype) new __attribute__((unavailable("init is not available"))); diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm index 19c58e5584..578942314d 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager+Entity.mm @@ -18,12 +18,12 @@ #include "geometry/distance_on_sphere.hpp" namespace { -UIImage *image(routing::turns::CarDirection t, bool isNextTurn) { +UIImage * image(routing::turns::CarDirection t, bool isNextTurn) { if (![MWMLocationManager lastLocation]) return nil; using namespace routing::turns; - NSString *imageName; + NSString * imageName; switch (t) { case CarDirection::ExitHighwayToRight: imageName = @"ic_exit_highway_to_right"; break; case CarDirection::TurnSlightRight: imageName = @"slight_right"; break; @@ -49,60 +49,28 @@ UIImage *image(routing::turns::CarDirection t, bool isNextTurn) { 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; - switch (t) - { - case PedestrianDirection::TurnRight: imageName = @"simple_right"; break; - case PedestrianDirection::TurnLeft: imageName = @"simple_left"; break; - case PedestrianDirection::ReachedYourDestination: imageName = @"finish_point"; break; - case PedestrianDirection::GoStraight: - case PedestrianDirection::Count: - case PedestrianDirection::None: imageName = @"straight"; break; - } + NSString * imageName; + switch (t) { + case PedestrianDirection::TurnRight: imageName = @"simple_right"; break; + case PedestrianDirection::TurnLeft: imageName = @"simple_left"; break; + case PedestrianDirection::ReachedYourDestination: imageName = @"finish_point"; break; + case PedestrianDirection::GoStraight: + case PedestrianDirection::Count: + case PedestrianDirection::None: imageName = @"straight"; break; + } if (!imageName) return nil; return [UIImage imageNamed:imageName]; } -NSAttributedString *estimate(NSTimeInterval time, NSString *distance, NSString *distanceUnits, - NSDictionary *primaryAttributes, NSDictionary *secondaryAttributes, BOOL isWalk, BOOL showEta) { - auto result = [[NSMutableAttributedString alloc] initWithString:@""]; - if (showEta) { - NSString *eta = [NSDateComponentsFormatter etaStringFrom:time]; - [result appendAttributedString:[[NSMutableAttributedString alloc] initWithString:eta attributes:primaryAttributes]]; - [result appendAttributedString:MWMNavigationDashboardEntity.estimateDot]; - } - - if (isWalk) { - UIFont *font = primaryAttributes[NSFontAttributeName]; - auto textAttachment = [[NSTextAttachment alloc] init]; - auto image = [UIImage imageNamed:@"ic_walk"]; - textAttachment.image = image; - auto const height = font.lineHeight; - auto const y = height - image.size.height; - 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)]; - [result appendAttributedString:attrStringWithImage]; - } - - auto target = [NSString stringWithFormat:@"%@ %@", distance, distanceUnits]; - [result appendAttributedString:[[NSAttributedString alloc] initWithString:target attributes:secondaryAttributes]]; - - return result; -} - NSArray *buildRouteTransitSteps(NSArray *points) { // Generate step info in format: (Segment 1 distance) (1) (Segment 2 distance) (2) ... (n-1) (Segment N distance). - NSMutableArray *steps = [NSMutableArray arrayWithCapacity:[points count] * 2 - 1]; + NSMutableArray * steps = [NSMutableArray arrayWithCapacity:[points count] * 2 - 1]; auto const numPoints = [points count]; for (int i = 0; i < numPoints - 1; i++) { MWMRoutePoint* segmentStart = points[i]; @@ -130,20 +98,21 @@ NSArray *buildRouteTransitSteps(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) 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) double speedLimitMps; @property(nonatomic, readwrite) BOOL isValid; @property(nonatomic, readwrite) CGFloat progress; @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; +@property(nonatomic, readwrite) BOOL showEta; +@property(nonatomic, readwrite) BOOL isWalk; @end @@ -166,6 +135,39 @@ NSArray *buildRouteTransitSteps(NSArray *buildRouteTransitSteps(NSArray *buildRouteTransitSteps(NSArray 2) entity.transitSteps = buildRouteTransitSteps(points); else @@ -235,10 +238,9 @@ NSArray *buildRouteTransitSteps(NSArray *transitSteps = [NSMutableArray new]; + entity.isWalk = YES; + entity.showEta = YES; + NSMutableArray * transitSteps = [NSMutableArray new]; for (auto const &stepInfo : info.m_steps) [transitSteps addObject:[[MWMRouterTransitStepInfo alloc] initWithStepInfo:stepInfo]]; entity.transitSteps = transitSteps; diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm index 95b56068bd..7ad7002306 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm @@ -259,22 +259,6 @@ NSString *const kNavigationControlViewXibName = @"NavigationControlView"; } #pragma mark - Properties -- (NSDictionary *)etaAttributes { - if (!_etaAttributes) { - _etaAttributes = - @{NSForegroundColorAttributeName: [UIColor blackPrimaryText], NSFontAttributeName: [UIFont medium17]}; - } - return _etaAttributes; -} - -- (NSDictionary *)etaSecondaryAttributes { - if (!_etaSecondaryAttributes) { - _etaSecondaryAttributes = - @{NSForegroundColorAttributeName: [UIColor blackSecondaryText], NSFontAttributeName: [UIFont medium17]}; - } - return _etaSecondaryAttributes; -} - - (void)setState:(MWMNavigationDashboardState)state { if (state == MWMNavigationDashboardStateHidden) [MWMSearchManager removeObserver:self]; diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift index 07bdf67372..b050007f36 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/BaseRoutePreviewStatus.swift @@ -92,6 +92,7 @@ final class BaseRoutePreviewStatus: SolidTouchView { super.traitCollectionDidChange(previousTraitCollection) updateManageRouteVisibility() updateHeight() + updateResultsLabel() } private func updateManageRouteVisibility() { @@ -140,7 +141,7 @@ final class BaseRoutePreviewStatus: SolidTouchView { private func updateResultsLabel() { guard let info = navigationInfo else { return } - if let result = info.estimate.mutableCopy() as? NSMutableAttributedString { + if let result = info.estimate().mutableCopy() as? NSMutableAttributedString { if let elevation = self.elevation { result.append(MWMNavigationDashboardEntity.estimateDot()) result.append(elevation) diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/TransportRoutePreviewStatus.swift b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/TransportRoutePreviewStatus.swift index 5f9db2d8c3..84f4a72736 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/TransportRoutePreviewStatus.swift +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Views/RoutePreview/RoutePreviewStatus/TransportRoutePreviewStatus.swift @@ -43,11 +43,11 @@ final class TransportRoutePreviewStatus: SolidTouchView { navigationInfo = info if (prependDistance) { let labelText = NSMutableAttributedString(string: NSLocalizedString("placepage_distance", comment: "") + ": ") - labelText.append(info.estimate) + labelText.append(info.estimate()) etaLabel.attributedText = labelText } else { - etaLabel.attributedText = info.estimate + etaLabel.attributedText = info.estimate() } stepsCollectionView.steps = info.transitSteps