OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
6 #error "This file requires ARC support." | |
7 #endif | |
8 | |
9 #import <UIKit/UIKit.h> | |
10 | |
11 #import "remoting/client/ios/app/host_collection_view_cell.h" | |
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" | |
16 #import "remoting/client/ios/domain/host_info.h" | |
17 | |
18 static const CGFloat kLinePadding = 2.f; | |
19 static const CGFloat kHostCardIconInset = 10.f; | |
20 static const CGFloat kHostCardPadding = 4.f; | |
21 static const CGFloat kHostCardIconSize = 45.f; | |
22 | |
23 @interface HostCollectionViewCell () { | |
24 UIImageView* _imageView; | |
25 UILabel* _statusLabel; | |
26 UILabel* _titleLabel; | |
27 UIView* _cellView; | |
28 } | |
29 @end | |
30 | |
31 // | |
32 // 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 | |
34 // to and other managements actions for a host in this list. | |
35 // | |
36 @implementation HostCollectionViewCell | |
37 | |
38 @synthesize hostInfo = _hostInfo; | |
39 | |
40 + (Class)layerClass { | |
41 return [MDCShadowLayer class]; | |
42 } | |
43 | |
44 - (id)initWithFrame:(CGRect)frame { | |
45 self = [super initWithFrame:frame]; | |
46 if (self) { | |
47 self.backgroundColor = [UIColor clearColor]; | |
48 [self commonInit]; | |
49 } | |
50 return self; | |
51 } | |
52 | |
53 - (void)commonInit { | |
54 _cellView = [[UIView alloc] initWithFrame:self.bounds]; | |
55 _cellView.autoresizingMask = | |
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; | |
71 _imageView.alpha = 0.87f; | |
72 _imageView.backgroundColor = UIColor.lightGrayColor; | |
73 _imageView.layer.cornerRadius = kHostCardIconSize / 2.f; | |
74 _imageView.layer.masksToBounds = YES; | |
75 [_cellView addSubview:_imageView]; | |
76 | |
77 _titleLabel = [[UILabel alloc] init]; | |
78 _titleLabel.font = [MDCTypography titleFont]; | |
79 _titleLabel.alpha = [MDCTypography titleFontOpacity]; | |
80 _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f]; | |
81 _titleLabel.frame = CGRectMake( | |
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 | |
88 _statusLabel = [[UILabel alloc] init]; | |
89 _statusLabel.font = [MDCTypography captionFont]; | |
90 _statusLabel.alpha = [MDCTypography captionFontOpacity]; | |
91 _statusLabel.textColor = [UIColor colorWithWhite:0 alpha:0.60f]; | |
92 _statusLabel.frame = CGRectMake( | |
93 imageViewFrame.origin.x + imageViewFrame.size.width + kHostCardIconInset, | |
94 (self.frame.size.height / 2.f) + kHostCardPadding / 2.f, | |
95 self.frame.size.width, _statusLabel.font.pointSize + kLinePadding); | |
96 [_cellView addSubview:_statusLabel]; | |
97 } | |
98 | |
99 #pragma mark - HostCollectionViewCell Public | |
100 | |
101 - (void)populateContentWithHostInfo:(HostInfo*)hostInfo { | |
102 _hostInfo = hostInfo; | |
103 | |
104 _titleLabel.text = _hostInfo.hostName; | |
105 _statusLabel.text = _hostInfo.status; | |
106 | |
107 _imageView.image = [UIImage imageNamed:@"ic_desktop"]; | |
108 | |
109 // TODO(nicholss): These colors are incorrect for the final product. | |
110 // Need to update to the values in the mocks. | |
111 if ([_hostInfo.status isEqualToString:@"ONLINE"]) { | |
112 _imageView.backgroundColor = UIColor.greenColor; | |
113 } else { | |
114 _imageView.backgroundColor = UIColor.lightGrayColor; | |
115 } | |
116 } | |
117 | |
118 #pragma mark - UICollectionReusableView | |
119 | |
120 - (void)prepareForReuse { | |
121 [super prepareForReuse]; | |
122 _hostInfo = nil; | |
123 _statusLabel.text = nil; | |
124 _titleLabel.text = nil; | |
125 } | |
126 | |
127 @end | |
OLD | NEW |