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/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" | 21 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" |
22 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex
t_item.h" | 22 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex
t_item.h" |
23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
24 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" | 24 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" |
25 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" | 25 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" |
26 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" | 26 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" |
27 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" | 27 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
28 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
_identifier.h" | 28 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
_identifier.h" |
29 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" | 29 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/gfx/image/image.h" | |
32 #include "url/gurl.h" | 31 #include "url/gurl.h" |
33 | 32 |
34 #if !defined(__has_feature) || !__has_feature(objc_arc) | 33 #if !defined(__has_feature) || !__has_feature(objc_arc) |
35 #error "This file requires ARC support." | 34 #error "This file requires ARC support." |
36 #endif | 35 #endif |
37 | 36 |
38 namespace { | 37 namespace { |
39 | 38 |
40 using CSCollectionViewItem = | 39 using CSCollectionViewItem = |
41 CollectionViewItem<ContentSuggestionIdentification>; | 40 CollectionViewItem<ContentSuggestionIdentification>; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 344 } |
346 | 345 |
347 #pragma mark - ContentSuggestionsArticleItemDelegate | 346 #pragma mark - ContentSuggestionsArticleItemDelegate |
348 | 347 |
349 - (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem { | 348 - (void)loadImageForArticleItem:(ContentSuggestionsArticleItem*)articleItem { |
350 NSInteger sectionIdentifier = | 349 NSInteger sectionIdentifier = |
351 SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo); | 350 SectionIdentifierForInfo(articleItem.suggestionIdentifier.sectionInfo); |
352 | 351 |
353 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; | 352 __weak ContentSuggestionsCollectionUpdater* weakSelf = self; |
354 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; | 353 __weak ContentSuggestionsArticleItem* weakArticle = articleItem; |
355 void (^imageFetchedCallback)(const gfx::Image&) = ^(const gfx::Image& image) { | |
356 if (image.IsEmpty()) { | |
357 return; | |
358 } | |
359 | 354 |
| 355 void (^imageFetchedCallback)(UIImage*) = ^(UIImage* image) { |
360 ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; | 356 ContentSuggestionsCollectionUpdater* strongSelf = weakSelf; |
361 ContentSuggestionsArticleItem* strongArticle = weakArticle; | 357 ContentSuggestionsArticleItem* strongArticle = weakArticle; |
362 if (!strongSelf || !strongArticle) { | 358 if (!strongSelf || !strongArticle) { |
363 return; | 359 return; |
364 } | 360 } |
365 | 361 |
366 strongArticle.image = image.CopyUIImage(); | 362 strongArticle.image = image; |
367 [strongSelf.collectionViewController | 363 [strongSelf.collectionViewController |
368 reconfigureCellsForItems:@[ strongArticle ] | 364 reconfigureCellsForItems:@[ strongArticle ] |
369 inSectionWithIdentifier:sectionIdentifier]; | 365 inSectionWithIdentifier:sectionIdentifier]; |
370 }; | 366 }; |
371 | 367 |
372 [self.dataSource.imageFetcher | 368 [self.dataSource.imageFetcher |
373 fetchImageForSuggestion:articleItem.suggestionIdentifier | 369 fetchImageForSuggestion:articleItem.suggestionIdentifier |
374 callback:imageFetchedCallback]; | 370 callback:imageFetchedCallback]; |
375 } | 371 } |
376 | 372 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 CSCollectionViewModel* model = | 467 CSCollectionViewModel* model = |
472 self.collectionViewController.collectionViewModel; | 468 self.collectionViewController.collectionViewModel; |
473 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; | 469 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; |
474 NSInteger itemNumber = [model numberOfItemsInSection:section]; | 470 NSInteger itemNumber = [model numberOfItemsInSection:section]; |
475 [model addItem:item toSectionWithIdentifier:sectionIdentifier]; | 471 [model addItem:item toSectionWithIdentifier:sectionIdentifier]; |
476 | 472 |
477 return [NSIndexPath indexPathForItem:itemNumber inSection:section]; | 473 return [NSIndexPath indexPathForItem:itemNumber inSection:section]; |
478 } | 474 } |
479 | 475 |
480 @end | 476 @end |
OLD | NEW |