diff options
author | Ilya Grechuhin <i.grechuhin@gmail.com> | 2016-12-02 21:22:04 +0300 |
---|---|---|
committer | Ilya Grechuhin <i.grechuhin@gmail.com> | 2016-12-05 11:01:51 +0300 |
commit | c54950a40fb6e2c56e8c6d6e51e47dd988f3da9c (patch) | |
tree | 8cebe4fae715c19e816ebb8814fb5f4069baedb0 /iphone/Maps/Classes/CustomViews/MapViewControls | |
parent | 9eae4de5a65a3ba752cdcd77ae120289b4bd9c31 (diff) |
[traffic] [ios] Added traffic states support.
Diffstat (limited to 'iphone/Maps/Classes/CustomViews/MapViewControls')
3 files changed, 72 insertions, 39 deletions
diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm index dae70992a6..5a5f19be23 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/BottomMenu/MWMBottomMenuViewController.mm @@ -15,6 +15,7 @@ #import "MWMSearchManager.h" #import "MWMSettingsViewController.h" #import "MWMTextToSpeech.h" +#import "MWMTrafficManager.h" #import "MapViewController.h" #import "MapsAppDelegate.h" #import "Statistics.h" @@ -58,7 +59,8 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { @end -@interface MWMBottomMenuViewController ()<UICollectionViewDataSource, UICollectionViewDelegate> +@interface MWMBottomMenuViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, + MWMTrafficManagerObserver> @property(weak, nonatomic) MapViewController * controller; @property(weak, nonatomic) IBOutlet UICollectionView * buttonsCollectionView; @@ -143,6 +145,7 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { selector:@selector(ttsButtonStatusChanged:) name:[MWMTextToSpeech ttsStatusNotificationKey] object:nil]; + [MWMTrafficManager addObserver:self]; } - (void)viewWillAppear:(BOOL)animated @@ -230,12 +233,22 @@ typedef NS_ENUM(NSUInteger, MWMBottomMenuViewCell) { [MWMTextToSpeech tts].active = isEnable; [self refreshRoutingDiminishTimer]; } + +#pragma mark - MWMTrafficManagerObserver + +- (void)onTrafficStateUpdated +{ + MWMButton * tb = self.trafficButton; + BOOL const enabled = ([MWMTrafficManager state] != TrafficManager::TrafficState::Disabled); + tb.coloring = enabled ? MWMButtonColoringBlue : MWMButtonColoringGray; + tb.selected = enabled; +} + - (IBAction)trafficTouchUpInside:(MWMButton *)sender { - BOOL const isEnable = sender.selected; - [Statistics logEvent:kStatMenu withParameters:@{kStatTraffic : isEnable ? kStatOn : kStatOff}]; - sender.coloring = isEnable ? MWMButtonColoringBlue : MWMButtonColoringGray; - sender.selected = !isEnable; // TODO: Replace with real logic + BOOL const switchOn = ([MWMTrafficManager state] == TrafficManager::TrafficState::Disabled); + [Statistics logEvent:kStatMenu withParameters:@{kStatTraffic : switchOn ? kStatOn : kStatOff}]; + [MWMTrafficManager enableTraffic:switchOn]; [self refreshRoutingDiminishTimer]; } diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.mm index a58b593570..3cc1462bc3 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.mm @@ -1,21 +1,31 @@ #import "MWMTrafficButtonViewController.h" #import "Common.h" +#import "MWMAlertViewController.h" #import "MWMButton.h" #import "MWMMapViewControlsCommon.h" #import "MWMMapViewControlsManager.h" +#import "MWMToast.h" +#import "MWMTrafficManager.h" #import "MapViewController.h" #import "UIColor+MapsMeColor.h" -typedef NS_ENUM(NSUInteger, MWMTrafficButtonState) { - MWMTrafficButtonStateOff, - MWMTrafficButtonStateOn, - MWMTrafficButtonStateUpdate -}; - namespace { CGFloat const kTopOffset = 26; CGFloat const kTopShiftedOffset = 6; + +NSArray<UIImage *> * imagesWithName(NSString * name) +{ + NSUInteger const imagesCount = 3; + NSMutableArray<UIImage *> * images = [NSMutableArray arrayWithCapacity:imagesCount]; + NSString * mode = [UIColor isNightMode] ? @"dark" : @"light"; + for (NSUInteger i = 1; i <= imagesCount; i += 1) + { + NSString * imageName = [NSString stringWithFormat:@"%@_%@_%@", name, mode, @(i).stringValue]; + [images addObject:static_cast<UIImage * _Nonnull>([UIImage imageNamed:imageName])]; + } + return [images copy]; +} } // namespace @interface MWMMapViewControlsManager () @@ -24,11 +34,10 @@ CGFloat const kTopShiftedOffset = 6; @end -@interface MWMTrafficButtonViewController () +@interface MWMTrafficButtonViewController ()<MWMTrafficManagerObserver> @property(nonatomic) NSLayoutConstraint * topOffset; @property(nonatomic) NSLayoutConstraint * leftOffset; -@property(nonatomic) MWMTrafficButtonState state; @end @@ -48,7 +57,7 @@ CGFloat const kTopShiftedOffset = 6; [ovc addChildViewController:self]; [ovc.view addSubview:self.view]; [self configLayout]; - self.state = MWMTrafficButtonStateOff; + [MWMTrafficManager addObserver:self]; } return self; } @@ -110,12 +119,6 @@ CGFloat const kTopShiftedOffset = 6; [self refreshLayout]; } -- (void)setState:(MWMTrafficButtonState)state -{ - _state = state; - [self refreshAppearance]; -} - - (void)refreshLayout { runAsyncOnMainQueue(^{ @@ -136,29 +139,43 @@ CGFloat const kTopShiftedOffset = 6; - (void)refreshAppearance { MWMButton * btn = static_cast<MWMButton *>(self.view); - switch (self.state) + UIImageView * iv = btn.imageView; + [iv stopAnimating]; + switch ([MWMTrafficManager state]) { - case MWMTrafficButtonStateOff: btn.imageName = @"btn_traffic_off"; break; - case MWMTrafficButtonStateOn: btn.imageName = @"btn_traffic_on"; break; - case MWMTrafficButtonStateUpdate: - { - NSUInteger const imagesCount = 3; - NSMutableArray<UIImage *> * images = [NSMutableArray arrayWithCapacity:imagesCount]; - NSString * mode = [UIColor isNightMode] ? @"dark" : @"light"; - for (NSUInteger i = 1; i <= imagesCount; i += 1) - { - NSString * name = - [NSString stringWithFormat:@"btn_traffic_update_%@_%@", mode, @(i).stringValue]; - [images addObject:[UIImage imageNamed:name]]; - } - UIImageView * iv = btn.imageView; - iv.animationImages = images; + case TrafficManager::TrafficState::Disabled: btn.imageName = @"btn_traffic_off"; break; + case TrafficManager::TrafficState::Enabled: btn.imageName = @"btn_traffic_on"; break; + case TrafficManager::TrafficState::WaitingData: + iv.animationImages = imagesWithName(@"btn_traffic_update"); iv.animationDuration = 0.8; - iv.image = images.lastObject; + iv.image = iv.animationImages.lastObject; [iv startAnimating]; break; + case TrafficManager::TrafficState::Outdated: btn.imageName = @"btn_traffic_outdated"; break; + case TrafficManager::TrafficState::NetworkError: + [MWMTrafficManager enableTraffic:NO]; + [[MWMAlertViewController activeAlertController] presentNoConnectionAlert]; + break; + case TrafficManager::TrafficState::NoData: + [MWMToast showWithText:L(@"traffic_state_no_data")]; + break; + case TrafficManager::TrafficState::ExpiredApp: + [MWMToast showWithText:L(@"traffic_state_expired_app")]; + break; + case TrafficManager::TrafficState::ExpiredData: + [MWMToast showWithText:L(@"traffic_state_expired_data")]; + break; } - } } +- (IBAction)buttonTouchUpInside +{ + if ([MWMTrafficManager state] == TrafficManager::TrafficState::Disabled) + [MWMTrafficManager enableTraffic:YES]; + else + [MWMTrafficManager enableTraffic:NO]; +} + +#pragma mark - MWMTrafficManagerObserver +- (void)onTrafficStateUpdated { [self refreshAppearance]; } @end diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.xib b/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.xib index d498ba4a9a..47256ff3af 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.xib +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/TrafficButton/MWMTrafficButtonViewController.xib @@ -22,7 +22,10 @@ <constraint firstAttribute="width" constant="56" id="hko-xz-hRz"/> </constraints> <state key="normal" image="btn_traffic_on_light"/> - <point key="canvasLocation" x="-57" y="-113"/> + <connections> + <action selector="buttonTouchUpInside" destination="-1" eventType="touchUpInside" id="fKZ-g8-4ML"/> + </connections> + <point key="canvasLocation" x="0.0" y="0.0"/> </button> </objects> <resources> |