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

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: Fix tests 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 // Used to check if the image has already been fetched. There is no way to
23 // discriminate between failed image download and nonexitent image. The article
24 // tries to download the image only once.
25 @property(nonatomic, assign) BOOL imageFetched;
23 26
24 @end 27 @end
25 28
26 #pragma mark - ContentSuggestionsArticleItem 29 #pragma mark - ContentSuggestionsArticleItem
27 30
28 @implementation ContentSuggestionsArticleItem 31 @implementation ContentSuggestionsArticleItem
29 32
30 @synthesize title = _title; 33 @synthesize title = _title;
31 @synthesize subtitle = _subtitle; 34 @synthesize subtitle = _subtitle;
32 @synthesize image = _image; 35 @synthesize image = _image;
33 @synthesize articleURL = _articleURL; 36 @synthesize articleURL = _articleURL;
34 @synthesize publisher = _publisher; 37 @synthesize publisher = _publisher;
35 @synthesize publishDate = _publishDate; 38 @synthesize publishDate = _publishDate;
36 @synthesize suggestionIdentifier = _suggestionIdentifier; 39 @synthesize suggestionIdentifier = _suggestionIdentifier;
37 @synthesize delegate = _delegate; 40 @synthesize delegate = _delegate;
38 @synthesize imageBeingFetched = _imageBeingFetched; 41 @synthesize imageFetched = _imageFetched;
39 42
40 - (instancetype)initWithType:(NSInteger)type 43 - (instancetype)initWithType:(NSInteger)type
41 title:(NSString*)title 44 title:(NSString*)title
42 subtitle:(NSString*)subtitle 45 subtitle:(NSString*)subtitle
43 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate 46 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate
44 url:(const GURL&)url { 47 url:(const GURL&)url {
45 self = [super initWithType:type]; 48 self = [super initWithType:type];
46 if (self) { 49 if (self) {
47 self.cellClass = [ContentSuggestionsArticleCell class]; 50 self.cellClass = [ContentSuggestionsArticleCell class];
48 _title = [title copy]; 51 _title = [title copy];
49 _subtitle = [subtitle copy]; 52 _subtitle = [subtitle copy];
50 _articleURL = url; 53 _articleURL = url;
51 _delegate = delegate; 54 _delegate = delegate;
52 } 55 }
53 return self; 56 return self;
54 } 57 }
55 58
56 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { 59 - (void)configureCell:(ContentSuggestionsArticleCell*)cell {
57 [super configureCell:cell]; 60 [super configureCell:cell];
58 if (!self.image && !self.imageBeingFetched) { 61 if (!self.image && !self.imageFetched) {
62 self.imageFetched = YES;
63 // Fetch the image. During the fetch the cell's image should still be set to
64 // nil.
59 [self.delegate loadImageForArticleItem:self]; 65 [self.delegate loadImageForArticleItem:self];
60 } 66 }
61 cell.titleLabel.text = _title; 67 cell.titleLabel.text = _title;
62 cell.subtitleLabel.text = _subtitle; 68 cell.subtitleLabel.text = _subtitle;
63 cell.imageView.image = _image; 69 cell.imageView.image = _image;
64 [cell setPublisherName:self.publisher date:self.publishDate]; 70 [cell setPublisherName:self.publisher date:self.publishDate];
65 } 71 }
66 72
67 @end 73 @end
68 74
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); 166 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
161 self.subtitleLabel.preferredMaxLayoutWidth = 167 self.subtitleLabel.preferredMaxLayoutWidth =
162 parentWidth - self.imageView.bounds.size.width - 3 * 8; 168 parentWidth - self.imageView.bounds.size.width - 3 * 8;
163 169
164 // Re-layout with the new preferred width to allow the label to adjust its 170 // Re-layout with the new preferred width to allow the label to adjust its
165 // height. 171 // height.
166 [super layoutSubviews]; 172 [super layoutSubviews];
167 } 173 }
168 174
169 @end 175 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698