Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_cell.mm

Issue 2887433002: Move the ContentSuggestions items to a new target (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_ite m.h" 5 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_cel l.h"
6 6
7 #include "base/time/time.h"
8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 7 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
9 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
10 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h"
11 #import "ios/chrome/browser/ui/favicon/favicon_view.h" 8 #import "ios/chrome/browser/ui/favicon/favicon_view.h"
12 #import "ios/chrome/browser/ui/uikit_ui_util.h" 9 #import "ios/chrome/browser/ui/uikit_ui_util.h"
13 #import "ios/chrome/browser/ui/util/i18n_string.h" 10 #import "ios/chrome/browser/ui/util/i18n_string.h"
14 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 11 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 12 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
16 #include "url/gurl.h"
17 13
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 14 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 15 #error "This file requires ARC support."
20 #endif 16 #endif
21 17
22 namespace { 18 namespace {
23 const CGFloat kImageSize = 72; 19 const CGFloat kImageSize = 72;
24 const CGFloat kStandardSpacing = 16; 20 const CGFloat kStandardSpacing = 16;
25 const CGFloat kSmallSpacing = 8; 21 const CGFloat kSmallSpacing = 8;
26 22
(...skipping 11 matching lines...) Expand all
38 // displayed. 34 // displayed.
39 NSString* const kNoImageIconName = @"content_suggestions_no_image"; 35 NSString* const kNoImageIconName = @"content_suggestions_no_image";
40 // No image icon percentage of white. 36 // No image icon percentage of white.
41 const CGFloat kNoImageIconWhite = 0.38; 37 const CGFloat kNoImageIconWhite = 0.38;
42 // No image background percentage of white. 38 // No image background percentage of white.
43 const CGFloat kNoImageBackgroundWhite = 0.95; 39 const CGFloat kNoImageBackgroundWhite = 0.95;
44 // Duration of the animation to display the image. 40 // Duration of the animation to display the image.
45 const CGFloat kAnimationDuration = 0.3; 41 const CGFloat kAnimationDuration = 0.3;
46 } 42 }
47 43
48 @interface ContentSuggestionsItem ()
49
50 @property(nonatomic, copy) NSString* subtitle;
51 // Used to check if the image has already been fetched. There is no way to
52 // discriminate between failed image download and nonexitent image. The
53 // suggestion tries to download the image only once.
54 @property(nonatomic, assign) BOOL imageFetched;
55
56 @end
57
58 #pragma mark - ContentSuggestionsItem
59
60 @implementation ContentSuggestionsItem
61
62 @synthesize title = _title;
63 @synthesize subtitle = _subtitle;
64 @synthesize image = _image;
65 @synthesize URL = _URL;
66 @synthesize publisher = _publisher;
67 @synthesize publishDate = _publishDate;
68 @synthesize suggestionIdentifier = _suggestionIdentifier;
69 @synthesize delegate = _delegate;
70 @synthesize imageFetched = _imageFetched;
71 @synthesize attributes = _attributes;
72 @synthesize hasImage = _hasImage;
73 @synthesize availableOffline = _availableOffline;
74
75 - (instancetype)initWithType:(NSInteger)type
76 title:(NSString*)title
77 subtitle:(NSString*)subtitle
78 url:(const GURL&)url {
79 self = [super initWithType:type];
80 if (self) {
81 self.cellClass = [ContentSuggestionsCell class];
82 _title = [title copy];
83 _subtitle = [subtitle copy];
84 _URL = url;
85 }
86 return self;
87 }
88
89 - (void)configureCell:(ContentSuggestionsCell*)cell {
90 [super configureCell:cell];
91 if (self.hasImage && !self.imageFetched) {
92 self.imageFetched = YES;
93 // Fetch the image. During the fetch the cell's image should still be set.
94 [self.delegate loadImageForSuggestedItem:self];
95 }
96 [cell.faviconView configureWithAttributes:self.attributes];
97 cell.titleLabel.text = self.title;
98 [cell setSubtitleText:self.subtitle];
99 cell.displayImage = self.hasImage;
100 [cell setContentImage:self.image];
101 [cell setAdditionalInformationWithPublisherName:self.publisher
102 date:self.publishDate
103 offlineAvailability:self.availableOffline];
104 }
105
106 @end
107
108 #pragma mark - ContentSuggestionsCell
109
110 @interface ContentSuggestionsCell () 44 @interface ContentSuggestionsCell ()
111 45
112 @property(nonatomic, strong) UILabel* additionalInformationLabel; 46 @property(nonatomic, strong) UILabel* additionalInformationLabel;
113 // Contains the no-image icon or the image. 47 // Contains the no-image icon or the image.
114 @property(nonatomic, strong) UIView* imageContainer; 48 @property(nonatomic, strong) UIView* imageContainer;
115 // The no-image icon displayed when there is no image. 49 // The no-image icon displayed when there is no image.
116 @property(nonatomic, strong) UIImageView* noImageIcon; 50 @property(nonatomic, strong) UIImageView* noImageIcon;
117 // Displays the image associated with this suggestion. It is added to the 51 // Displays the image associated with this suggestion. It is added to the
118 // imageContainer only if there is an image to display, hiding the no-image 52 // imageContainer only if there is an image to display, hiding the no-image
119 // icon. 53 // icon.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 self.contentImageView.alpha = 0; 150 self.contentImageView.alpha = 0;
217 self.contentImageView.hidden = NO; 151 self.contentImageView.hidden = NO;
218 152
219 [UIView animateWithDuration:kAnimationDuration 153 [UIView animateWithDuration:kAnimationDuration
220 animations:^{ 154 animations:^{
221 self.contentImageView.alpha = 1; 155 self.contentImageView.alpha = 1;
222 }]; 156 }];
223 } 157 }
224 158
225 - (void)setAdditionalInformationWithPublisherName:(NSString*)publisherName 159 - (void)setAdditionalInformationWithPublisherName:(NSString*)publisherName
226 date:(base::Time)publishDate 160 date:(NSDate*)date
227 offlineAvailability:(BOOL)availableOffline { 161 offlineAvailability:(BOOL)availableOffline {
228 NSDate* date = [NSDate dateWithTimeIntervalSince1970:publishDate.ToDoubleT()];
229 NSString* dateString = 162 NSString* dateString =
230 [NSDateFormatter localizedStringFromDate:date 163 [NSDateFormatter localizedStringFromDate:date
231 dateStyle:NSDateFormatterMediumStyle 164 dateStyle:NSDateFormatterMediumStyle
232 timeStyle:NSDateFormatterNoStyle]; 165 timeStyle:NSDateFormatterNoStyle];
233 166
234 NSString* publisherString = AdjustStringForLocaleDirection( 167 NSString* publisherString = AdjustStringForLocaleDirection(
235 [NSString stringWithFormat:@"%@ - %@ ", publisherName, dateString]); 168 [NSString stringWithFormat:@"%@ - %@ ", publisherName, dateString]);
236 169
237 NSMutableAttributedString* additionInformation = 170 NSMutableAttributedString* additionInformation =
238 [[NSMutableAttributedString alloc] initWithString:publisherString 171 [[NSMutableAttributedString alloc] initWithString:publisherString
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 @"title" : _titleLabel, 318 @"title" : _titleLabel,
386 @"text" : _subtitleLabel, 319 @"text" : _subtitleLabel,
387 @"additional" : _additionalInformationLabel, 320 @"additional" : _additionalInformationLabel,
388 @"favicon" : _faviconView, 321 @"favicon" : _faviconView,
389 }, 322 },
390 @{ @"space" : @(kStandardSpacing), 323 @{ @"space" : @(kStandardSpacing),
391 @"small" : @(kSmallSpacing) }); 324 @"small" : @(kSmallSpacing) });
392 } 325 }
393 326
394 @end 327 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698