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

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

Issue 2815023003: Add Most Visited tiles to ContentSuggestions (Closed)
Patch Set: Fix tests Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a1489168ca873bae768e17c7828c5141e2453aba..cc7a8113ac083a193b388689a02712c752252d67 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"
@@ -236,16 +238,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];
@@ -288,12 +293,37 @@ SectionIdentifier SectionIdentifierForInfo(
break;
}
case ContentSuggestionTypeMostVisited: {
- // TODO(crbug.com/707754): Add the most visited item.
+ 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];
break;
}
}
}
+ if ([model hasSectionForSectionIdentifier:SectionIdentifierMostVisited]) {
+ NSInteger section =
+ [model sectionForSectionIdentifier:SectionIdentifierMostVisited];
+ NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
+ ContentSuggestionsMostVisitedItem* item =
+ base::mac::ObjCCast<ContentSuggestionsMostVisitedItem>(
+ [model itemAtIndexPath:indexPath]);
+ item.suggestions = mostVisitedToAdd;
+ }
+
return indexPaths;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698