| OLD | NEW |
| 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 | 23 |
| 23 @end | 24 @end |
| 24 | 25 |
| 25 #pragma mark - ContentSuggestionsArticleItem | 26 #pragma mark - ContentSuggestionsArticleItem |
| 26 | 27 |
| 27 @implementation ContentSuggestionsArticleItem | 28 @implementation ContentSuggestionsArticleItem |
| 28 | 29 |
| 29 @synthesize title = _title; | 30 @synthesize title = _title; |
| 30 @synthesize subtitle = _subtitle; | 31 @synthesize subtitle = _subtitle; |
| 31 @synthesize image = _image; | 32 @synthesize image = _image; |
| 32 @synthesize articleURL = _articleURL; | 33 @synthesize articleURL = _articleURL; |
| 33 @synthesize publisher = _publisher; | 34 @synthesize publisher = _publisher; |
| 34 @synthesize publishDate = _publishDate; | 35 @synthesize publishDate = _publishDate; |
| 35 @synthesize suggestionIdentifier = _suggestionIdentifier; | 36 @synthesize suggestionIdentifier = _suggestionIdentifier; |
| 37 @synthesize delegate = _delegate; |
| 38 @synthesize imageBeingFetched = _imageBeingFetched; |
| 36 | 39 |
| 37 - (instancetype)initWithType:(NSInteger)type | 40 - (instancetype)initWithType:(NSInteger)type |
| 38 title:(NSString*)title | 41 title:(NSString*)title |
| 39 subtitle:(NSString*)subtitle | 42 subtitle:(NSString*)subtitle |
| 40 image:(UIImage*)image | 43 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate |
| 41 url:(const GURL&)url { | 44 url:(const GURL&)url { |
| 42 self = [super initWithType:type]; | 45 self = [super initWithType:type]; |
| 43 if (self) { | 46 if (self) { |
| 44 self.cellClass = [ContentSuggestionsArticleCell class]; | 47 self.cellClass = [ContentSuggestionsArticleCell class]; |
| 45 _title = [title copy]; | 48 _title = [title copy]; |
| 46 _subtitle = [subtitle copy]; | 49 _subtitle = [subtitle copy]; |
| 47 _image = image; | |
| 48 _articleURL = url; | 50 _articleURL = url; |
| 51 _delegate = delegate; |
| 49 } | 52 } |
| 50 return self; | 53 return self; |
| 51 } | 54 } |
| 52 | 55 |
| 53 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { | 56 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { |
| 54 [super configureCell:cell]; | 57 [super configureCell:cell]; |
| 58 if (!self.image && !self.imageBeingFetched) { |
| 59 [self.delegate loadImageForArticleItem:self]; |
| 60 } |
| 55 cell.titleLabel.text = _title; | 61 cell.titleLabel.text = _title; |
| 56 cell.subtitleLabel.text = _subtitle; | 62 cell.subtitleLabel.text = _subtitle; |
| 57 cell.imageView.image = _image; | 63 cell.imageView.image = _image; |
| 58 [cell setPublisherName:self.publisher date:self.publishDate]; | 64 [cell setPublisherName:self.publisher date:self.publishDate]; |
| 59 } | 65 } |
| 60 | 66 |
| 61 @end | 67 @end |
| 62 | 68 |
| 63 #pragma mark - ContentSuggestionsArticleCell | 69 #pragma mark - ContentSuggestionsArticleCell |
| 64 | 70 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); | 160 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); |
| 155 self.subtitleLabel.preferredMaxLayoutWidth = | 161 self.subtitleLabel.preferredMaxLayoutWidth = |
| 156 parentWidth - self.imageView.bounds.size.width - 3 * 8; | 162 parentWidth - self.imageView.bounds.size.width - 3 * 8; |
| 157 | 163 |
| 158 // Re-layout with the new preferred width to allow the label to adjust its | 164 // Re-layout with the new preferred width to allow the label to adjust its |
| 159 // height. | 165 // height. |
| 160 [super layoutSubviews]; | 166 [super layoutSubviews]; |
| 161 } | 167 } |
| 162 | 168 |
| 163 @end | 169 @end |
| OLD | NEW |