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

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

Issue 2782613004: Add FaviconAttributesProvider to ContentSuggestions (Closed)
Patch Set: Address comments 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 38aebe6e64301b71c5782d9c62d92d66b4e31d11..e4362c6b0f91f8c3583b922a660f46145ab82dd1 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
@@ -25,6 +25,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"
@@ -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,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
@@ -434,4 +462,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