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 38aebe6e64301b71c5782d9c62d92d66b4e31d11..fcb8938192fa22cf03da6219ff7bcae3f3e9c558 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 |
| @@ -8,6 +8,7 @@ |
| #include "base/mac/foundation_util.h" |
| #include "base/time/time.h" |
| #include "components/strings/grit/components_strings.h" |
| +#import "ios/chrome/browser/favicon/favicon_attributes_provider.h" |
| #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" |
| @@ -240,17 +241,7 @@ SectionIdentifier SectionIdentifierForInfo( |
| } |
| case ContentSuggestionTypeArticle: { |
| 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; |
| + [self articleItemForSuggestion:suggestion]; |
| NSIndexPath* addedIndexPath = [self addItem:articleItem |
| toSectionWithIdentifier:sectionIdentifier]; |
| @@ -421,6 +412,44 @@ SectionIdentifier SectionIdentifierForInfo( |
| return item; |
| } |
| +// Returns an article build with the |suggestion|. |
| +- (ContentSuggestionsArticleItem*)articleItemForSuggestion: |
| + (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 ContentSuggestionsCollectionUpdater* weakSelf = self; |
| + __weak ContentSuggestionsArticleItem* weakItem = articleItem; |
| + void (^completionBlock)(FaviconAttributes* attributes) = |
| + ^(FaviconAttributes* attributes) { |
| + ContentSuggestionsArticleItem* strongItem = weakItem; |
| + ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; |
| + if (!strongSelf || !strongItem) { |
| + return; |
| + } |
| + |
| + strongItem.attributes = attributes; |
| + |
| + [strongSelf reconfigure:strongItem]; |
| + }; |
| + |
| + [self.dataSource.attributesProvider |
|
lpromero
2017/03/29 13:32:07
I would abstract this in a data source method.
gambard
2017/03/30 08:07:11
Done.
|
| + fetchFaviconAttributesForURL:articleItem.articleURL |
| + completion:completionBlock]; |
| + |
| + return articleItem; |
| +} |
| + |
| // Adds |item| to |sectionIdentifier| section of the model of the |
| // CollectionView. Returns the IndexPath of the newly added item. |
| - (NSIndexPath*)addItem:(CSCollectionViewItem*)item |
| @@ -434,4 +463,21 @@ SectionIdentifier SectionIdentifierForInfo( |
| return [NSIndexPath indexPathForItem:itemNumber inSection:section]; |
| } |
| +// Reconfigures the |item| in the collection view. |
| +- (void)reconfigure:(CSCollectionViewItem*)item { |
| + CSCollectionViewModel* model = |
| + self.collectionViewController.collectionViewModel; |
| + |
| + for (NSInteger sectionNumber = 0; sectionNumber < [model numberOfSections]; |
| + sectionNumber++) { |
| + NSInteger sectionIdentifier = |
| + [model sectionIdentifierForSection:sectionNumber]; |
| + if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { |
| + [self.collectionViewController |
| + reconfigureCellsForItems:@[ item ] |
| + inSectionWithIdentifier:sectionIdentifier]; |
| + } |
| + } |
| +} |
| + |
| @end |