| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #import <UIKit/UIKit.h> | 9 #import <UIKit/UIKit.h> |
| 10 | 10 |
| 11 #import "remoting/ios/app/host_collection_view_cell.h" | 11 #import "remoting/ios/app/host_collection_view_cell.h" |
| 12 | 12 |
| 13 #import "ios/third_party/material_components_ios/src/components/ShadowElevations
/src/MaterialShadowElevations.h" | |
| 14 #import "ios/third_party/material_components_ios/src/components/ShadowLayer/src/
MaterialShadowLayer.h" | |
| 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 16 #import "remoting/ios/domain/host_info.h" | 14 #import "remoting/ios/domain/host_info.h" |
| 17 | 15 |
| 18 static const CGFloat kLinePadding = 2.f; | 16 static const CGFloat kLinePadding = 2.f; |
| 19 static const CGFloat kHostCardIconInset = 10.f; | 17 static const CGFloat kHostCardIconInset = 10.f; |
| 20 static const CGFloat kHostCardPadding = 4.f; | 18 static const CGFloat kHostCardPadding = 4.f; |
| 21 static const CGFloat kHostCardIconSize = 45.f; | 19 static const CGFloat kHostCardIconSize = 45.f; |
| 22 | 20 |
| 23 @interface HostCollectionViewCell () { | 21 @interface HostCollectionViewCell () { |
| 24 UIImageView* _imageView; | 22 UIImageView* _imageView; |
| 25 UILabel* _statusLabel; | 23 UILabel* _statusLabel; |
| 26 UILabel* _titleLabel; | 24 UILabel* _titleLabel; |
| 27 UIView* _cellView; | 25 UIView* _labelView; |
| 28 } | 26 } |
| 29 @end | 27 @end |
| 30 | 28 |
| 31 // | 29 // |
| 32 // This is the implementation of the info card for a host's status shown in | 30 // This is the implementation of the info card for a host's status shown in |
| 33 // the host list. This will also be the selection for which host to connect | 31 // the host list. This will also be the selection for which host to connect |
| 34 // to and other managements actions for a host in this list. | 32 // to and other managements actions for a host in this list. |
| 35 // | 33 // |
| 36 @implementation HostCollectionViewCell | 34 @implementation HostCollectionViewCell |
| 37 | 35 |
| 38 @synthesize hostInfo = _hostInfo; | 36 @synthesize hostInfo = _hostInfo; |
| 39 | 37 |
| 40 + (Class)layerClass { | |
| 41 return [MDCShadowLayer class]; | |
| 42 } | |
| 43 | |
| 44 - (id)initWithFrame:(CGRect)frame { | 38 - (id)initWithFrame:(CGRect)frame { |
| 45 self = [super initWithFrame:frame]; | 39 self = [super initWithFrame:frame]; |
| 46 if (self) { | 40 if (self) { |
| 47 self.backgroundColor = [UIColor clearColor]; | 41 self.backgroundColor = [UIColor clearColor]; |
| 48 [self commonInit]; | 42 [self commonInit]; |
| 49 } | 43 } |
| 50 return self; | 44 return self; |
| 51 } | 45 } |
| 52 | 46 |
| 53 - (void)commonInit { | 47 - (void)commonInit { |
| 54 _cellView = [[UIView alloc] initWithFrame:self.bounds]; | 48 _imageView = [[UIImageView alloc] init]; |
| 55 _cellView.autoresizingMask = | 49 _imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| 56 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| 57 _cellView.backgroundColor = [UIColor whiteColor]; | |
| 58 _cellView.clipsToBounds = YES; | |
| 59 [self addSubview:_cellView]; | |
| 60 | |
| 61 MDCShadowLayer* shadowLayer = (MDCShadowLayer*)self.layer; | |
| 62 shadowLayer.shadowMaskEnabled = NO; | |
| 63 [shadowLayer setElevation:MDCShadowElevationCardResting]; | |
| 64 | |
| 65 CGRect imageViewFrame = | |
| 66 CGRectMake(kHostCardIconInset, | |
| 67 self.frame.size.height / 2.f - kHostCardIconSize / 2.f, | |
| 68 kHostCardIconSize, kHostCardIconSize); | |
| 69 _imageView = [[UIImageView alloc] initWithFrame:imageViewFrame]; | |
| 70 _imageView.contentMode = UIViewContentModeCenter; | 50 _imageView.contentMode = UIViewContentModeCenter; |
| 71 _imageView.alpha = 0.87f; | 51 _imageView.alpha = 0.87f; |
| 72 _imageView.backgroundColor = UIColor.lightGrayColor; | 52 _imageView.backgroundColor = UIColor.lightGrayColor; |
| 73 _imageView.layer.cornerRadius = kHostCardIconSize / 2.f; | 53 _imageView.layer.cornerRadius = kHostCardIconSize / 2.f; |
| 74 _imageView.layer.masksToBounds = YES; | 54 _imageView.layer.masksToBounds = YES; |
| 75 [_cellView addSubview:_imageView]; | 55 [self.contentView addSubview:_imageView]; |
| 56 |
| 57 // Holds both of the labels. |
| 58 _labelView = [[UIView alloc] init]; |
| 59 _labelView.translatesAutoresizingMaskIntoConstraints = NO; |
| 60 [self.contentView addSubview:_labelView]; |
| 76 | 61 |
| 77 _titleLabel = [[UILabel alloc] init]; | 62 _titleLabel = [[UILabel alloc] init]; |
| 63 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 78 _titleLabel.font = [MDCTypography titleFont]; | 64 _titleLabel.font = [MDCTypography titleFont]; |
| 79 _titleLabel.alpha = [MDCTypography titleFontOpacity]; | 65 _titleLabel.alpha = [MDCTypography titleFontOpacity]; |
| 80 _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f]; | 66 _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f]; |
| 81 _titleLabel.frame = CGRectMake( | 67 [_labelView addSubview:_titleLabel]; |
| 82 imageViewFrame.origin.x + imageViewFrame.size.width + kHostCardIconInset, | |
| 83 (self.frame.size.height / 2.f) - | |
| 84 (_titleLabel.font.pointSize + kHostCardPadding / 2.f), | |
| 85 self.frame.size.width, _titleLabel.font.pointSize + kLinePadding); | |
| 86 [_cellView addSubview:_titleLabel]; | |
| 87 | 68 |
| 88 _statusLabel = [[UILabel alloc] init]; | 69 _statusLabel = [[UILabel alloc] init]; |
| 70 _statusLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 89 _statusLabel.font = [MDCTypography captionFont]; | 71 _statusLabel.font = [MDCTypography captionFont]; |
| 90 _statusLabel.alpha = [MDCTypography captionFontOpacity]; | 72 _statusLabel.alpha = [MDCTypography captionFontOpacity]; |
| 91 _statusLabel.textColor = [UIColor colorWithWhite:0 alpha:0.60f]; | 73 _statusLabel.textColor = [UIColor colorWithWhite:0 alpha:0.60f]; |
| 92 _statusLabel.frame = CGRectMake( | 74 [_labelView addSubview:_statusLabel]; |
| 93 imageViewFrame.origin.x + imageViewFrame.size.width + kHostCardIconInset, | 75 |
| 94 (self.frame.size.height / 2.f) + kHostCardPadding / 2.f, | 76 // Constraints |
| 95 self.frame.size.width, _statusLabel.font.pointSize + kLinePadding); | 77 NSArray* constraints = @[ |
| 96 [_cellView addSubview:_statusLabel]; | 78 // +------------+---------------+ |
| 79 // | +--------+ | | |
| 80 // | | | | [Host Name] | |
| 81 // | | Icon | | - - - - - - - | <- Center Y |
| 82 // | | | | [Host Status] | |
| 83 // | +---^----+ | | |
| 84 // +-----|------+-------^-------+ |
| 85 // | | |
| 86 // Image View Label View |
| 87 [[_imageView leadingAnchor] |
| 88 constraintEqualToAnchor:[self.contentView leadingAnchor] |
| 89 constant:kHostCardIconInset], |
| 90 [[_imageView centerYAnchor] |
| 91 constraintEqualToAnchor:[self.contentView centerYAnchor]], |
| 92 [[_imageView widthAnchor] constraintEqualToConstant:kHostCardIconSize], |
| 93 [[_imageView heightAnchor] constraintEqualToConstant:kHostCardIconSize], |
| 94 |
| 95 [[_labelView leadingAnchor] |
| 96 constraintEqualToAnchor:[_imageView trailingAnchor] |
| 97 constant:kHostCardIconInset], |
| 98 [[_labelView trailingAnchor] |
| 99 constraintEqualToAnchor:[self.contentView trailingAnchor] |
| 100 constant:-kHostCardPadding / 2.f], |
| 101 [[_labelView topAnchor] |
| 102 constraintEqualToAnchor:[self.contentView topAnchor]], |
| 103 [[_labelView bottomAnchor] |
| 104 constraintEqualToAnchor:[self.contentView bottomAnchor]], |
| 105 |
| 106 // Put titleLable and statusLable symmetrically around centerY. |
| 107 [[_titleLabel leadingAnchor] |
| 108 constraintEqualToAnchor:[_labelView leadingAnchor]], |
| 109 [[_titleLabel trailingAnchor] |
| 110 constraintEqualToAnchor:[_labelView trailingAnchor]], |
| 111 [[_titleLabel bottomAnchor] |
| 112 constraintEqualToAnchor:[_labelView centerYAnchor]], |
| 113 |
| 114 [[_statusLabel leadingAnchor] |
| 115 constraintEqualToAnchor:[_labelView leadingAnchor]], |
| 116 [[_statusLabel trailingAnchor] |
| 117 constraintEqualToAnchor:[_labelView trailingAnchor]], |
| 118 [[_statusLabel topAnchor] constraintEqualToAnchor:[_labelView centerYAnchor] |
| 119 constant:kLinePadding], |
| 120 ]; |
| 121 |
| 122 [NSLayoutConstraint activateConstraints:constraints]; |
| 97 } | 123 } |
| 98 | 124 |
| 99 #pragma mark - HostCollectionViewCell Public | 125 #pragma mark - HostCollectionViewCell Public |
| 100 | 126 |
| 101 - (void)populateContentWithHostInfo:(HostInfo*)hostInfo { | 127 - (void)populateContentWithHostInfo:(HostInfo*)hostInfo { |
| 102 _hostInfo = hostInfo; | 128 _hostInfo = hostInfo; |
| 103 | 129 |
| 104 _titleLabel.text = _hostInfo.hostName; | 130 _titleLabel.text = _hostInfo.hostName; |
| 105 | 131 |
| 106 _imageView.image = [UIImage imageNamed:@"ic_desktop"]; | 132 _imageView.image = [UIImage imageNamed:@"ic_desktop"]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 #pragma mark - UICollectionReusableView | 146 #pragma mark - UICollectionReusableView |
| 121 | 147 |
| 122 - (void)prepareForReuse { | 148 - (void)prepareForReuse { |
| 123 [super prepareForReuse]; | 149 [super prepareForReuse]; |
| 124 _hostInfo = nil; | 150 _hostInfo = nil; |
| 125 _statusLabel.text = nil; | 151 _statusLabel.text = nil; |
| 126 _titleLabel.text = nil; | 152 _titleLabel.text = nil; |
| 127 } | 153 } |
| 128 | 154 |
| 129 @end | 155 @end |
| OLD | NEW |