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

Unified Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm

Issue 2782613004: Add FaviconAttributesProvider to ContentSuggestions (Closed)
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
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 e7d3eda6a3f4b1a9f1b1842eb5acc7b40af62080..3f2ceb697de87238914269a2a78fba21edf5e055 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
@@ -27,6 +27,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestions_section_information.h"
+#import "ios/chrome/browser/ui/favicon/favicon_attributes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
@@ -267,17 +268,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];
@@ -464,6 +455,43 @@ 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 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
@@ -477,4 +505,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

Powered by Google App Engine
This is Rietveld 408576698