Chromium Code Reviews| 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 00daaae76b23a69668c80036f8e1ec1972d4c767..54c1a2e2cef136e3ad2eb414d329bed019b4a475 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 |
| @@ -14,6 +14,8 @@ |
| #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_article_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_footer_item.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_reading_list_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_text_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
| @@ -237,16 +239,19 @@ SectionIdentifier SectionIdentifierForInfo( |
| return [NSArray array]; |
| } |
| + NSMutableArray<ContentSuggestionsMostVisited*>* mostVisitedToAdd = |
| + [NSMutableArray array]; |
| + |
| + CSCollectionViewModel* model = |
| + self.collectionViewController.collectionViewModel; |
| NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array]; |
| for (ContentSuggestion* suggestion in suggestions) { |
| ContentSuggestionsSectionInformation* sectionInfo = |
| suggestion.suggestionIdentifier.sectionInfo; |
| NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo); |
| - CSCollectionViewModel* model = |
| - self.collectionViewController.collectionViewModel; |
| if (![model hasSectionForSectionIdentifier:sectionIdentifier]) |
| - return [NSArray array]; |
| + continue; |
| NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; |
| NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section]; |
| @@ -289,12 +294,37 @@ SectionIdentifier SectionIdentifierForInfo( |
| break; |
| } |
| case ContentSuggestionTypeMostVisited: { |
| + NSInteger section = |
| + [model sectionForSectionIdentifier:SectionIdentifierMostVisited]; |
| + NSIndexPath* indexPath = |
| + [NSIndexPath indexPathForItem:0 inSection:section]; |
| + |
| + if ([model numberOfItemsInSection:section] == 0) { |
| + [model addItem:[[ContentSuggestionsMostVisitedItem alloc] |
| + initWithType:ItemTypeMostVisited] |
| + toSectionWithIdentifier:SectionIdentifierMostVisited]; |
| + [indexPaths addObject:indexPath]; |
| + } |
| + |
| + ContentSuggestionsMostVisited* mostVisited = |
| + [ContentSuggestionsMostVisited mostVisitedWithTitle:suggestion.title |
| + attributes:nil]; |
| + [mostVisitedToAdd addObject:mostVisited]; |
| // TODO(crbug.com/707754): Add the most visited item. |
|
lpromero
2017/05/05 15:08:25
Remove.
gambard
2017/05/05 15:24:52
Done.
|
| break; |
| } |
| } |
| } |
| + NSInteger section = |
| + [model sectionForSectionIdentifier:SectionIdentifierMostVisited]; |
| + NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section]; |
| + ContentSuggestionsMostVisitedItem* item = |
| + (ContentSuggestionsMostVisitedItem*)[model itemAtIndexPath:indexPath]; |
|
lpromero
2017/05/05 15:08:25
base::mac::ObjCCast<ContentSuggestionsMostVisitedI
gambard
2017/05/05 15:24:52
Done.
|
| + item.suggestions = mostVisitedToAdd; |
| + |
| + [self.collectionViewController.collectionViewLayout invalidateLayout]; |
|
lpromero
2017/05/05 15:08:24
I don't think this belongs in this method. If nece
gambard
2017/05/05 15:24:52
Done.
|
| + |
| return indexPaths; |
| } |