| Index: ios/chrome/browser/ui/settings/cells/account_signin_item.mm
|
| diff --git a/ios/chrome/browser/ui/settings/cells/account_signin_item.mm b/ios/chrome/browser/ui/settings/cells/account_signin_item.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..911fb4dc87c5d94bc65176a6e64c611278fc8671
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/settings/cells/account_signin_item.mm
|
| @@ -0,0 +1,175 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/browser/ui/settings/cells/account_signin_item.h"
|
| +
|
| +#include "ios/chrome/grit/ios_chromium_strings.h"
|
| +#include "ios/chrome/grit/ios_strings.h"
|
| +#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
|
| +#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +namespace {
|
| +// Padding used on the leading and trailing edges of the cell.
|
| +const CGFloat kHorizontalPadding = 16;
|
| +
|
| +// Padding used between the image and text.
|
| +const CGFloat kHorizontalPaddingBetweenImageAndText = 10;
|
| +
|
| +// Image fixed horizontal size.
|
| +const CGFloat kHorizontalImageFixedSize = 40;
|
| +}
|
| +
|
| +@implementation AccountSignInItem
|
| +
|
| +@synthesize image = _image;
|
| +
|
| +- (instancetype)initWithType:(NSInteger)type {
|
| + self = [super initWithType:type];
|
| + if (self) {
|
| + self.cellClass = [AccountSignInCell class];
|
| + self.accessibilityTraits |= UIAccessibilityTraitButton;
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +#pragma mark - CollectionViewItem
|
| +
|
| +- (void)configureCell:(AccountSignInCell*)cell {
|
| + [super configureCell:cell];
|
| + cell.textLabel.text =
|
| + l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_TITLE);
|
| + cell.detailTextLabel.text =
|
| + l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_SUBTITLE);
|
| + cell.imageView.image = self.image;
|
| +}
|
| +
|
| +@end
|
| +
|
| +@implementation AccountSignInCell
|
| +
|
| +@synthesize textLabel = _textLabel;
|
| +@synthesize detailTextLabel = _detailTextLabel;
|
| +@synthesize imageView = _imageView;
|
| +
|
| +- (instancetype)initWithFrame:(CGRect)frame {
|
| + self = [super initWithFrame:frame];
|
| + if (self) {
|
| + self.isAccessibilityElement = YES;
|
| + [self addSubviews];
|
| + [self setDefaultViewStyling];
|
| + [self setViewConstraints];
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +// Create and add subviews.
|
| +- (void)addSubviews {
|
| + UIView* contentView = self.contentView;
|
| + contentView.clipsToBounds = YES;
|
| +
|
| + _imageView = [[UIImageView alloc] init];
|
| + _imageView.translatesAutoresizingMaskIntoConstraints = NO;
|
| + [contentView addSubview:_imageView];
|
| +
|
| + _textLabel = [[UILabel alloc] init];
|
| + _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
| + [contentView addSubview:_textLabel];
|
| +
|
| + _detailTextLabel = [[UILabel alloc] init];
|
| + _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
| + [_detailTextLabel setNumberOfLines:3];
|
| + [contentView addSubview:_detailTextLabel];
|
| +}
|
| +
|
| +- (void)setDefaultViewStyling {
|
| + _imageView.contentMode = UIViewContentModeCenter;
|
| + _imageView.layer.masksToBounds = YES;
|
| + _imageView.contentMode = UIViewContentModeScaleAspectFit;
|
| + _textLabel.font = [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
|
| + _textLabel.textColor = [[MDCPalette greyPalette] tint900];
|
| + _detailTextLabel.font =
|
| + [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14];
|
| + _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500];
|
| +}
|
| +
|
| +- (void)setViewConstraints {
|
| + UIView* contentView = self.contentView;
|
| +
|
| + // This view is used to center the two leading textLabels.
|
| + UIView* verticalCenteringView = [[UIView alloc] init];
|
| + verticalCenteringView.translatesAutoresizingMaskIntoConstraints = NO;
|
| + [contentView addSubview:verticalCenteringView];
|
| +
|
| + [NSLayoutConstraint activateConstraints:@[
|
| + // Set leading anchors.
|
| + [_imageView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor
|
| + constant:kHorizontalPadding],
|
| + [_detailTextLabel.leadingAnchor
|
| + constraintEqualToAnchor:_textLabel.leadingAnchor],
|
| + [_textLabel.leadingAnchor
|
| + constraintEqualToAnchor:_imageView.trailingAnchor
|
| + constant:kHorizontalPaddingBetweenImageAndText],
|
| +
|
| + // Fix image widths.
|
| + [_imageView.widthAnchor
|
| + constraintEqualToConstant:kHorizontalImageFixedSize],
|
| +
|
| + // Set vertical anchors. This approach assumes the cell height is set by
|
| + // the view controller. Contents are pinned to centerY, rather than pushing
|
| + // against the top/bottom boundaries.
|
| + [_imageView.centerYAnchor
|
| + constraintEqualToAnchor:contentView.centerYAnchor],
|
| + [_textLabel.topAnchor
|
| + constraintEqualToAnchor:verticalCenteringView.topAnchor],
|
| + [_textLabel.bottomAnchor
|
| + constraintEqualToAnchor:_detailTextLabel.topAnchor],
|
| + [_detailTextLabel.bottomAnchor
|
| + constraintEqualToAnchor:verticalCenteringView.bottomAnchor],
|
| + [verticalCenteringView.centerYAnchor
|
| + constraintEqualToAnchor:contentView.centerYAnchor],
|
| + // Set trailing anchors.
|
| + [_detailTextLabel.trailingAnchor
|
| + constraintEqualToAnchor:contentView.trailingAnchor
|
| + constant:-kHorizontalPadding],
|
| + [_textLabel.trailingAnchor
|
| + constraintLessThanOrEqualToAnchor:contentView.trailingAnchor
|
| + constant:-kHorizontalPadding],
|
| + ]];
|
| +
|
| + // This is needed so the image doesn't get pushed out if both text and detail
|
| + // are long.
|
| + [_textLabel
|
| + setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
|
| + forAxis:UILayoutConstraintAxisHorizontal];
|
| + [_detailTextLabel
|
| + setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
|
| + forAxis:UILayoutConstraintAxisHorizontal];
|
| +}
|
| +
|
| +#pragma mark - UICollectionReusableView
|
| +
|
| +- (void)prepareForReuse {
|
| + [super prepareForReuse];
|
| + _imageView.image = nil;
|
| + self.textLabel.text = nil;
|
| + self.detailTextLabel.text = nil;
|
| +}
|
| +
|
| +#pragma mark - NSObject(Accessibility)
|
| +
|
| +- (NSString*)accessibilityLabel {
|
| + return l10n_util::GetNSString(IDS_IOS_SIGN_IN_TO_CHROME_SETTING_TITLE);
|
| +}
|
| +
|
| +- (NSString*)accessibilityValue {
|
| + return [NSString stringWithFormat:@"%@, %@", self.textLabel.text,
|
| + self.detailTextLabel.text];
|
| +}
|
| +
|
| +@end
|
|
|