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

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

Issue 2701833003: Fetch images for ContentSuggestions (Closed)
Patch Set: Address comments Created 3 years, 10 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 0c14da3a6868fa286676cc4153378560a5732568..96a0e9c2b55cc987b80d8fbd6cf25f2c1fabf83f 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
@@ -16,10 +16,12 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_source.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandable_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_item.h"
+#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fetcher.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_information.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_text_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
+#include "ui/gfx/image/image.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
@@ -76,7 +78,9 @@ SectionIdentifier SectionIdentifierForInfo(
} // namespace
-@interface ContentSuggestionsCollectionUpdater ()<ContentSuggestionsDataSink>
+@interface ContentSuggestionsCollectionUpdater ()<
+ ContentSuggestionsArticleItemDelegate,
+ ContentSuggestionsDataSink>
@property(nonatomic, weak) id<ContentSuggestionsDataSource> dataSource;
@property(nonatomic, strong)
@@ -140,6 +144,35 @@ SectionIdentifier SectionIdentifierForInfo(
return ContentSuggestionTypeForItemType(item.type);
}
+#pragma mark - ContentSuggestionsArticleItemDelegate
+
+- (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem {
+ NSInteger sectionIdentifier =
+ SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo);
+
+ __weak ContentSuggestionsCollectionUpdater* weakSelf = self;
+ __weak ContentSuggestionsArticleItem* weakArticle = articleItem;
+ void (^imageFetchedCallback)(const gfx::Image&) = ^(const gfx::Image& image) {
+ ContentSuggestionsCollectionUpdater* strongSelf = weakSelf;
+ ContentSuggestionsArticleItem* strongArticle = weakArticle;
+ if (!strongSelf || !strongArticle) {
+ return;
+ }
+
+ strongArticle.imageBeingFetched = NO;
+ strongArticle.image = image.CopyUIImage();
+ [strongSelf.collectionViewController
+ reconfigureCellsForItems:@[ strongArticle ]
+ inSectionWithIdentifier:sectionIdentifier];
+ };
+
+ articleItem.imageBeingFetched = YES;
+
+ [self.dataSource.imageFetcher
+ fetchImageForSuggestion:articleItem.suggestionIdentifier
+ callback:imageFetchedCallback];
+}
+
#pragma mark - Private methods
- (void)reloadData {
@@ -157,7 +190,7 @@ SectionIdentifier SectionIdentifierForInfo(
initWithType:ItemTypeForContentSuggestionType(suggestion.type)
title:suggestion.title
subtitle:suggestion.text
- image:suggestion.image
+ delegate:self
url:suggestion.url];
articleItem.publisher = suggestion.publisher;

Powered by Google App Engine
This is Rietveld 408576698