Chromium Code Reviews| Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| index cc7a8113ac083a193b388689a02712c752252d67..ec33d0b7b2d6948a5f57bcdb107f85ea6dd81363 100644 |
| --- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm |
| @@ -12,11 +12,10 @@ |
| #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h" |
| #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" |
| #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| -#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_article_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_footer_item.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h" |
| -#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_reading_list_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_text_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink.h" |
| @@ -106,7 +105,7 @@ SectionIdentifier SectionIdentifierForInfo( |
| } // namespace |
| @interface ContentSuggestionsCollectionUpdater ()< |
| - ContentSuggestionsArticleItemDelegate, |
| + ContentSuggestionsItemDelegate, |
| ContentSuggestionsDataSink> |
| @property(nonatomic, weak) id<ContentSuggestionsDataSource> dataSource; |
| @@ -275,8 +274,30 @@ SectionIdentifier SectionIdentifierForInfo( |
| break; |
| } |
| case ContentSuggestionTypeArticle: { |
| - ContentSuggestionsArticleItem* articleItem = |
| - [self articleItemForSuggestion:suggestion]; |
| + ContentSuggestionsItem* articleItem = |
| + [self suggestionItemForSuggestion:suggestion]; |
| + |
| + articleItem.hasImage = YES; |
| + |
| + __weak ContentSuggestionsItem* weakItem = articleItem; |
| + [self fetchFaviconForItem:articleItem |
| + withURL:articleItem.URL |
| + callback:^void(FaviconAttributes* attributes) { |
| + weakItem.attributes = attributes; |
| + }]; |
| + |
| + __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
| + [self.dataSource |
| + fetchFaviconImageForSuggestion:articleItem.suggestionIdentifier |
| + completion:^void(UIImage* favicon) { |
| + if (!weakItem || !weakSelf) |
|
jif
2017/05/10 09:06:19
weakItem could be released after line 293; it shou
gambard
2017/05/10 09:23:27
Done.
|
| + return; |
| + |
| + weakItem.attributes = [FaviconAttributes |
| + attributesWithImage:favicon]; |
| + [weakSelf.collectionViewController |
| + reconfigureCellsForItems:@[ weakItem ]]; |
| + }]; |
| NSIndexPath* addedIndexPath = [self addItem:articleItem |
| toSectionWithIdentifier:sectionIdentifier]; |
| @@ -284,8 +305,15 @@ SectionIdentifier SectionIdentifierForInfo( |
| break; |
| } |
| case ContentSuggestionTypeReadingList: { |
| - ContentSuggestionsReadingListItem* readingListItem = |
| - [self readingListItemForSuggestion:suggestion]; |
| + ContentSuggestionsItem* readingListItem = |
| + [self suggestionItemForSuggestion:suggestion]; |
| + |
| + __weak ContentSuggestionsItem* weakItem = readingListItem; |
| + [self fetchFaviconForItem:readingListItem |
| + withURL:readingListItem.URL |
| + callback:^void(FaviconAttributes* attributes) { |
| + weakItem.attributes = attributes; |
| + }]; |
| NSIndexPath* addedIndexPath = [self addItem:readingListItem |
| toSectionWithIdentifier:sectionIdentifier]; |
| @@ -365,15 +393,15 @@ SectionIdentifier SectionIdentifierForInfo( |
| return [self addItem:item toSectionWithIdentifier:sectionIdentifier]; |
| } |
| -#pragma mark - ContentSuggestionsArticleItemDelegate |
| +#pragma mark - ContentSuggestionsItemDelegate |
| -- (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem { |
| +- (void)loadImageForSuggestionItem:(ContentSuggestionsItem*)suggestionItem { |
| __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
| - __weak ContentSuggestionsArticleItem* weakArticle = articleItem; |
| + __weak ContentSuggestionsItem* weakArticle = suggestionItem; |
| void (^imageFetchedCallback)(UIImage*) = ^(UIImage* image) { |
| ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; |
| - ContentSuggestionsArticleItem* strongArticle = weakArticle; |
| + ContentSuggestionsItem* strongArticle = weakArticle; |
| if (!strongSelf || !strongArticle) { |
| return; |
| } |
| @@ -384,7 +412,7 @@ SectionIdentifier SectionIdentifierForInfo( |
| }; |
| [self.dataSource.imageFetcher |
| - fetchImageForSuggestion:articleItem.suggestionIdentifier |
| + fetchImageForSuggestion:suggestionItem.suggestionIdentifier |
| callback:imageFetchedCallback]; |
| } |
| @@ -478,67 +506,23 @@ SectionIdentifier SectionIdentifierForInfo( |
| return item; |
| } |
| -// Returns an article built with the |suggestion|. |
| -- (ContentSuggestionsArticleItem*)articleItemForSuggestion: |
| +// Returns an suggestion item built with the |suggestion|. |
|
jif
2017/05/10 09:06:19
Returns a suggestion
gambard
2017/05/10 09:23:27
Done.
|
| +- (ContentSuggestionsItem*)suggestionItemForSuggestion: |
| (ContentSuggestion*)suggestion { |
| - ContentSuggestionsArticleItem* articleItem = |
| - [[ContentSuggestionsArticleItem alloc] |
| - initWithType:ItemTypeForContentSuggestionType(suggestion.type) |
| - title:suggestion.title |
| - subtitle:suggestion.text |
| - delegate:self |
| - url:suggestion.url]; |
| - |
| - articleItem.publisher = suggestion.publisher; |
| - articleItem.publishDate = suggestion.publishDate; |
| - |
| - articleItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| - |
| - __weak ContentSuggestionsArticleItem* weakItem = articleItem; |
| - [self fetchFaviconForItem:articleItem |
| - withURL:articleItem.articleURL |
| - callback:^void(FaviconAttributes* attributes) { |
| - weakItem.attributes = attributes; |
| - }]; |
| - |
| - __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
| - [self.dataSource |
| - fetchFaviconImageForSuggestion:articleItem.suggestionIdentifier |
| - completion:^void(UIImage* favicon) { |
| - if (!weakItem || !weakSelf) |
| - return; |
| - |
| - weakItem.attributes = |
| - [FaviconAttributes attributesWithImage:favicon]; |
| - [weakSelf.collectionViewController |
| - reconfigureCellsForItems:@[ weakItem ]]; |
| - }]; |
| - |
| - return articleItem; |
| -} |
| - |
| -// Returns a reading list item built with the |suggestion|. |
| -- (ContentSuggestionsReadingListItem*)readingListItemForSuggestion: |
| - (ContentSuggestion*)suggestion { |
| - ContentSuggestionsReadingListItem* readingListItem = |
| - [[ContentSuggestionsReadingListItem alloc] |
| - initWithType:ItemTypeReadingList |
| - url:suggestion.url |
| - distillationState:suggestion.readingListExtra.status]; |
| - |
| - readingListItem.title = suggestion.title; |
| - readingListItem.subtitle = suggestion.publisher; |
| + ContentSuggestionsItem* suggestionItem = [[ContentSuggestionsItem alloc] |
| + initWithType:ItemTypeForContentSuggestionType(suggestion.type) |
| + title:suggestion.title |
| + subtitle:suggestion.text |
| + delegate:self |
| + url:suggestion.url]; |
| - readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| + suggestionItem.publisher = suggestion.publisher; |
| + suggestionItem.publishDate = suggestion.publishDate; |
| + suggestionItem.availableOffline = suggestion.availableOffline; |
| - __weak ContentSuggestionsReadingListItem* weakItem = readingListItem; |
| - [self fetchFaviconForItem:readingListItem |
| - withURL:readingListItem.url |
| - callback:^void(FaviconAttributes* attributes) { |
| - weakItem.attributes = attributes; |
| - }]; |
| + suggestionItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| - return readingListItem; |
| + return suggestionItem; |
| } |
| // Fetches the favicon associated with the |URL|, call the |callback| with the |