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

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

Issue 2720423003: Get Suggestions image only if it is not empty (Closed)
Patch Set: Created 3 years, 9 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/content_suggestions_article_i tem.h" 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i tem.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #import "ios/chrome/browser/ui/uikit_ui_util.h" 8 #import "ios/chrome/browser/ui/uikit_ui_util.h"
9 9
10 #if !defined(__has_feature) || !__has_feature(objc_arc) 10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support." 11 #error "This file requires ARC support."
12 #endif 12 #endif
13 13
14 namespace { 14 namespace {
15 const CGFloat kImageSize = 100; 15 const CGFloat kImageSize = 100;
16 const CGFloat kStandardSpacing = 8; 16 const CGFloat kStandardSpacing = 8;
17 } 17 }
18 18
19 @interface ContentSuggestionsArticleItem () 19 @interface ContentSuggestionsArticleItem ()
20 20
21 @property(nonatomic, copy) NSString* subtitle; 21 @property(nonatomic, copy) NSString* subtitle;
22 @property(nonatomic, weak) id<ContentSuggestionsArticleItemDelegate> delegate; 22 @property(nonatomic, weak) id<ContentSuggestionsArticleItemDelegate> delegate;
23 // Used to check if the image has already been fetched. There is no way to
24 // discriminate between failed image download and nonexitent image. The article
25 // tries to download the image only once.
26 @property(nonatomic, assign) BOOL imageFetched;
23 27
24 @end 28 @end
25 29
26 #pragma mark - ContentSuggestionsArticleItem 30 #pragma mark - ContentSuggestionsArticleItem
27 31
28 @implementation ContentSuggestionsArticleItem 32 @implementation ContentSuggestionsArticleItem
29 33
30 @synthesize title = _title; 34 @synthesize title = _title;
31 @synthesize subtitle = _subtitle; 35 @synthesize subtitle = _subtitle;
32 @synthesize image = _image; 36 @synthesize image = _image;
33 @synthesize articleURL = _articleURL; 37 @synthesize articleURL = _articleURL;
34 @synthesize publisher = _publisher; 38 @synthesize publisher = _publisher;
35 @synthesize publishDate = _publishDate; 39 @synthesize publishDate = _publishDate;
36 @synthesize suggestionIdentifier = _suggestionIdentifier; 40 @synthesize suggestionIdentifier = _suggestionIdentifier;
37 @synthesize delegate = _delegate; 41 @synthesize delegate = _delegate;
38 @synthesize imageBeingFetched = _imageBeingFetched; 42 @synthesize imageFetched = _imageFetched;
39 43
40 - (instancetype)initWithType:(NSInteger)type 44 - (instancetype)initWithType:(NSInteger)type
41 title:(NSString*)title 45 title:(NSString*)title
42 subtitle:(NSString*)subtitle 46 subtitle:(NSString*)subtitle
43 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate 47 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate
44 url:(const GURL&)url { 48 url:(const GURL&)url {
45 self = [super initWithType:type]; 49 self = [super initWithType:type];
46 if (self) { 50 if (self) {
47 self.cellClass = [ContentSuggestionsArticleCell class]; 51 self.cellClass = [ContentSuggestionsArticleCell class];
48 _title = [title copy]; 52 _title = [title copy];
49 _subtitle = [subtitle copy]; 53 _subtitle = [subtitle copy];
50 _articleURL = url; 54 _articleURL = url;
51 _delegate = delegate; 55 _delegate = delegate;
52 } 56 }
53 return self; 57 return self;
54 } 58 }
55 59
56 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { 60 - (void)configureCell:(ContentSuggestionsArticleCell*)cell {
57 [super configureCell:cell]; 61 [super configureCell:cell];
58 if (!self.image && !self.imageBeingFetched) { 62 if (!self.image && !self.imageFetched) {
63 self.imageFetched = YES;
59 [self.delegate loadImageForArticleItem:self]; 64 [self.delegate loadImageForArticleItem:self];
Olivier 2017/03/01 08:33:56 This looks async. Is it OK to use _image just afte
gambard 2017/03/01 08:37:12 It is indeed async. This is only called if the ima
Olivier 2017/03/01 12:42:08 I think it would be worth add a comment for this b
gambard 2017/03/01 12:55:49 Done.
60 } 65 }
61 cell.titleLabel.text = _title; 66 cell.titleLabel.text = _title;
62 cell.subtitleLabel.text = _subtitle; 67 cell.subtitleLabel.text = _subtitle;
63 cell.imageView.image = _image; 68 cell.imageView.image = _image;
Olivier 2017/03/01 12:42:08 nit: use accessor here to be consistent with above
gambard 2017/03/01 12:55:48 It should be updated in another CL.
64 [cell setPublisherName:self.publisher date:self.publishDate]; 69 [cell setPublisherName:self.publisher date:self.publishDate];
65 } 70 }
66 71
67 @end 72 @end
68 73
69 #pragma mark - ContentSuggestionsArticleCell 74 #pragma mark - ContentSuggestionsArticleCell
70 75
71 @interface ContentSuggestionsArticleCell () 76 @interface ContentSuggestionsArticleCell ()
72 77
73 @property(nonatomic, strong) UILabel* publisherLabel; 78 @property(nonatomic, strong) UILabel* publisherLabel;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); 165 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
161 self.subtitleLabel.preferredMaxLayoutWidth = 166 self.subtitleLabel.preferredMaxLayoutWidth =
162 parentWidth - self.imageView.bounds.size.width - 3 * 8; 167 parentWidth - self.imageView.bounds.size.width - 3 * 8;
163 168
164 // Re-layout with the new preferred width to allow the label to adjust its 169 // Re-layout with the new preferred width to allow the label to adjust its
165 // height. 170 // height.
166 [super layoutSubviews]; 171 [super layoutSubviews];
167 } 172 }
168 173
169 @end 174 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698