| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" | 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
| 11 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" | 11 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" |
| 12 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 12 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 13 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art
icle_item.h" | 13 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art
icle_item.h" |
| 14 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_but
ton_item.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_but
ton_item.h" |
| 15 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_exp
andable_item.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_exp
andable_item.h" |
| 16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_fav
icon_item.h" | 16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_fav
icon_item.h" |
| 17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_foo
ter_item.h" | 17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_foo
ter_item.h" |
| 18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" | 18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" |
| 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
| 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" | 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" |
| 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" | 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" |
| 22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" | 22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" |
| 23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" | 23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
| 24 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
_identifier.h" | 24 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
_identifier.h" |
| 25 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" | 25 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" |
| 26 #include "ui/gfx/image/image.h" | |
| 27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 28 | 27 |
| 29 #if !defined(__has_feature) || !__has_feature(objc_arc) | 28 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 30 #error "This file requires ARC support." | 29 #error "This file requires ARC support." |
| 31 #endif | 30 #endif |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. | 34 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. |
| 36 typedef NS_ENUM(NSInteger, ItemType) { | 35 typedef NS_ENUM(NSInteger, ItemType) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 261 } |
| 263 | 262 |
| 264 #pragma mark - ContentSuggestionsArticleItemDelegate | 263 #pragma mark - ContentSuggestionsArticleItemDelegate |
| 265 | 264 |
| 266 - (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem { | 265 - (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem { |
| 267 NSInteger sectionIdentifier = | 266 NSInteger sectionIdentifier = |
| 268 SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo); | 267 SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo); |
| 269 | 268 |
| 270 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; | 269 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
| 271 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; | 270 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; |
| 272 void (^imageFetchedCallback)(const gfx::Image&) = ^(const gfx::Image& image) { | |
| 273 if (image.IsEmpty()) { | |
| 274 return; | |
| 275 } | |
| 276 | 271 |
| 272 void (^imageFetchedCallback)(UIImage*) = ^(UIImage* image) { |
| 277 ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; | 273 ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; |
| 278 ContentSuggestionsArticleItem* strongArticle = weakArticle; | 274 ContentSuggestionsArticleItem* strongArticle = weakArticle; |
| 279 if (!strongSelf || !strongArticle) { | 275 if (!strongSelf || !strongArticle) { |
| 280 return; | 276 return; |
| 281 } | 277 } |
| 282 | 278 |
| 283 strongArticle.image = image.CopyUIImage(); | 279 strongArticle.image = image; |
| 284 [strongSelf.collectionViewController | 280 [strongSelf.collectionViewController |
| 285 reconfigureCellsForItems:@[ strongArticle ] | 281 reconfigureCellsForItems:@[ strongArticle ] |
| 286 inSectionWithIdentifier:sectionIdentifier]; | 282 inSectionWithIdentifier:sectionIdentifier]; |
| 287 }; | 283 }; |
| 288 | 284 |
| 289 [self.dataSource.imageFetcher | 285 [self.dataSource.imageFetcher |
| 290 fetchImageForSuggestion:articleItem.suggestionIdentifier | 286 fetchImageForSuggestion:articleItem.suggestionIdentifier |
| 291 callback:imageFetchedCallback]; | 287 callback:imageFetchedCallback]; |
| 292 } | 288 } |
| 293 | 289 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 }]; | 358 }]; |
| 363 } | 359 } |
| 364 | 360 |
| 365 // Adds the |suggestions| to the collection view. All the suggestions must have | 361 // Adds the |suggestions| to the collection view. All the suggestions must have |
| 366 // the same sectionInfo. | 362 // the same sectionInfo. |
| 367 - (void)moreSuggestionsFetched:(NSArray<ContentSuggestion*>*)suggestions { | 363 - (void)moreSuggestionsFetched:(NSArray<ContentSuggestion*>*)suggestions { |
| 368 [self.collectionViewController addSuggestions:suggestions]; | 364 [self.collectionViewController addSuggestions:suggestions]; |
| 369 } | 365 } |
| 370 | 366 |
| 371 @end | 367 @end |
| OLD | NEW |