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

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

Issue 2701833003: Fetch images for ContentSuggestions (Closed)
Patch Set: Reviewable Created 3 years, 10 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 #import "ios/chrome/browser/ui/uikit_ui_util.h" 7 #import "ios/chrome/browser/ui/uikit_ui_util.h"
8 8
9 #if !defined(__has_feature) || !__has_feature(objc_arc) 9 #if !defined(__has_feature) || !__has_feature(objc_arc)
10 #error "This file requires ARC support." 10 #error "This file requires ARC support."
11 #endif 11 #endif
12 12
13 namespace { 13 namespace {
14 const CGFloat kImageSize = 100; 14 const CGFloat kImageSize = 100;
15 const CGFloat kStandardSpacing = 8; 15 const CGFloat kStandardSpacing = 8;
16 } 16 }
17 17
18 @interface ContentSuggestionsArticleItem () 18 @interface ContentSuggestionsArticleItem ()
19 19
20 @property(nonatomic, copy) NSString* subtitle; 20 @property(nonatomic, copy) NSString* subtitle;
21 @property(nonatomic, weak) id<ContentSuggestionsArticleItemDelegate> delegate;
21 22
22 @end 23 @end
23 24
24 #pragma mark - ContentSuggestionsArticleItem 25 #pragma mark - ContentSuggestionsArticleItem
25 26
26 @implementation ContentSuggestionsArticleItem 27 @implementation ContentSuggestionsArticleItem
27 28
28 @synthesize title = _title; 29 @synthesize title = _title;
29 @synthesize subtitle = _subtitle; 30 @synthesize subtitle = _subtitle;
30 @synthesize image = _image; 31 @synthesize image = _image;
31 @synthesize articleURL = _articleURL; 32 @synthesize articleURL = _articleURL;
32 @synthesize suggestionID = _suggestionID; 33 @synthesize suggestionID = _suggestionID;
34 @synthesize delegate = _delegate;
35 @synthesize imageBeingFetched = _imageBeingFetched;
33 36
34 - (instancetype)initWithType:(NSInteger)type 37 - (instancetype)initWithType:(NSInteger)type
35 title:(NSString*)title 38 title:(NSString*)title
36 subtitle:(NSString*)subtitle 39 subtitle:(NSString*)subtitle
37 image:(UIImage*)image 40 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate
38 url:(const GURL&)url { 41 url:(const GURL&)url {
39 self = [super initWithType:type]; 42 self = [super initWithType:type];
40 if (self) { 43 if (self) {
41 self.cellClass = [ContentSuggestionsArticleCell class]; 44 self.cellClass = [ContentSuggestionsArticleCell class];
42 _title = [title copy]; 45 _title = [title copy];
43 _subtitle = [subtitle copy]; 46 _subtitle = [subtitle copy];
44 _image = image;
45 _articleURL = url; 47 _articleURL = url;
48 _delegate = delegate;
46 } 49 }
47 return self; 50 return self;
48 } 51 }
49 52
50 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { 53 - (void)configureCell:(ContentSuggestionsArticleCell*)cell {
51 [super configureCell:cell]; 54 [super configureCell:cell];
55 if (!self.image && !self.imageBeingFetched) {
56 self.imageBeingFetched = YES;
marq (ping after 24h) 2017/02/21 11:27:08 I think it would be better to set this to YES in t
gambard 2017/02/21 15:07:53 Done.
57 [self.delegate loadImageForArticleItem:self];
58 }
52 cell.titleLabel.text = _title; 59 cell.titleLabel.text = _title;
53 cell.subtitleLabel.text = _subtitle; 60 cell.subtitleLabel.text = _subtitle;
54 cell.imageView.image = _image; 61 cell.imageView.image = _image;
55 } 62 }
56 63
57 @end 64 @end
58 65
59 #pragma mark - ContentSuggestionsArticleCell 66 #pragma mark - ContentSuggestionsArticleCell
60 67
61 @implementation ContentSuggestionsArticleCell 68 @implementation ContentSuggestionsArticleCell
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // changes, for instance on screen rotation. 127 // changes, for instance on screen rotation.
121 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); 128 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
122 self.subtitleLabel.preferredMaxLayoutWidth = parentWidth - kImageSize - 3 * 8; 129 self.subtitleLabel.preferredMaxLayoutWidth = parentWidth - kImageSize - 3 * 8;
123 130
124 // Re-layout with the new preferred width to allow the label to adjust its 131 // Re-layout with the new preferred width to allow the label to adjust its
125 // height. 132 // height.
126 [super layoutSubviews]; 133 [super layoutSubviews];
127 } 134 }
128 135
129 @end 136 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698