<commit_before>#import "MWMTrafficButtonViewController.h"
#import "MWMCommon.h"
#import "MWMAlertViewController.h"
#import "MWMButton.h"
#import "MWMMapViewControlsCommon.h"
#import "MWMMapViewControlsManager.h"
#import "MWMToast.h"
#import "MWMTrafficManager.h"
#import "MapViewController.h"

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 ()

@property(nonatomic) MWMTrafficButtonViewController * trafficButton;

@end

@interface MWMTrafficButtonViewController ()<MWMTrafficManagerObserver>

@property(nonatomic) NSLayoutConstraint * topOffset;
@property(nonatomic) NSLayoutConstraint * leftOffset;

@end

@implementation MWMTrafficButtonViewController

+ (MWMTrafficButtonViewController *)controller
{
  return [MWMMapViewControlsManager manager].trafficButton;
}

- (instancetype)init
{
  self = [super init];
  if (self)
  {
    MapViewController * ovc = [MapViewController controller];
    [ovc addChildViewController:self];
    [ovc.view addSubview:self.view];
    [self configLayout];
    [self refreshAppearance];
    [MWMTrafficManager addObserver:self];
  }
  return self;
}

- (void)configLayout
{
  UIView * sv = self.view;
  UIView * ov = sv.superview;

  self.topOffset = [NSLayoutConstraint constraintWithItem:sv
                                                attribute:NSLayoutAttributeTop
                                                relatedBy:NSLayoutRelationEqual
                                                   toItem:ov
                                                attribute:NSLayoutAttributeTop
                                               multiplier:1
                                                 constant:kTopOffset];
  self.leftOffset = [NSLayoutConstraint constraintWithItem:sv
                                                 attribute:NSLayoutAttributeLeading
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:ov
                                                 attribute:NSLayoutAttributeLeading
                                                multiplier:1
                                                  constant:kViewControlsOffsetToBounds];

  [ov addConstraints:@[ self.topOffset, self.leftOffset ]];
}

- (void)mwm_refreshUI
{
  [self.view mwm_refreshUI];
}

- (void)setHidden:(BOOL)hidden
{
  _hidden = hidden;
  [self refreshLayout];
}

- (void)setTopBound:(CGFloat)topBound
{
  if (_topBound == topBound)
    return;
  _topBound = topBound;
  [self refreshLayout];
}

- (void)setLeftBound:(CGFloat)leftBound
{
  if (_leftBound == leftBound)
    return;
  _leftBound = leftBound;
  [self refreshLayout];<commit_msg>[MAPSME-3823] [ios] Fixed traffic button coloring update.<commit_after>#import "MWMTrafficButtonViewController.h"
#import "MWMCommon.h"
#import "MWMAlertViewController.h"
#import "MWMButton.h"
#import "MWMMapViewControlsCommon.h"
#import "MWMMapViewControlsManager.h"
#import "MWMToast.h"
#import "MWMTrafficManager.h"
#import "MapViewController.h"

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 ()

@property(nonatomic) MWMTrafficButtonViewController * trafficButton;

@end

@interface MWMTrafficButtonViewController ()<MWMTrafficManagerObserver>

@property(nonatomic) NSLayoutConstraint * topOffset;
@property(nonatomic) NSLayoutConstraint * leftOffset;

@end

@implementation MWMTrafficButtonViewController

+ (MWMTrafficButtonViewController *)controller
{
  return [MWMMapViewControlsManager manager].trafficButton;
}

- (instancetype)init
{
  self = [super init];
  if (self)
  {
    MapViewController * ovc = [MapViewController controller];
    [ovc addChildViewController:self];
    [ovc.view addSubview:self.view];
    [self configLayout];
    [self refreshAppearance];
    [MWMTrafficManager addObserver:self];
  }
  return self;
}

- (void)configLayout
{
  UIView * sv = self.view;
  UIView * ov = sv.superview;

  self.topOffset = [NSLayoutConstraint constraintWithItem:sv
                                                attribute:NSLayoutAttributeTop
                                                relatedBy:NSLayoutRelationEqual
                                                   toItem:ov
                                                attribute:NSLayoutAttributeTop
                                               multiplier:1
                                                 constant:kTopOffset];
  self.leftOffset = [NSLayoutConstraint constraintWithItem:sv
                                                 attribute:NSLayoutAttributeLeading
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:ov
                                                 attribute:NSLayoutAttributeLeading
                                                multiplier:1
                                                  constant:kViewControlsOffsetToBounds];

  [ov addConstraints:@[ self.topOffset, self.leftOffset ]];
}

- (void)mwm_refreshUI
{
  [self.view mwm_refreshUI];
  [self refreshAppearance];
}

- (void)setHidden:(BOOL)hidden
{
  _hidden = hidden;
  [self refreshLayout];
}

- (void)setTopBound:(CGFloat)topBound
{
  if (_topBound == topBound)
    return;
  _topBound = topBound;
  [self refreshLayout];
}

- (void)setLeftBound:(CGFloat)leftBound
{
  if (_leftBound == leftBound)
    return;
  _leftBound = leftBound;
  [self refreshLayout];
{'fraction_non_alphanumeric': 0.09447983014861996, 'fraction_numerical': 0.003033060357901122, 'mean_word_length': 2.404749612803304, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6277465', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1760, 'n_words': 341}