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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "components/strings/grit/components_strings.h" 11 #include "components/strings/grit/components_strings.h"
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
13 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 13 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
15 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art icle_item.h" 15 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art icle_item.h"
16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_foo ter_item.h" 16 #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_mos t_visited.h"
18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_mos t_visited_item.h"
17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_rea ding_list_item.h" 19 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_rea ding_list_item.h"
18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex t_item.h" 20 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex t_item.h"
19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h" 22 #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" 23 #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" 24 #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" 25 #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" 26 #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" 27 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
26 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h" 28 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 (CollectionViewItem*)item { 231 (CollectionViewItem*)item {
230 return ContentSuggestionTypeForItemType(item.type); 232 return ContentSuggestionTypeForItemType(item.type);
231 } 233 }
232 234
233 - (NSArray<NSIndexPath*>*)addSuggestionsToModel: 235 - (NSArray<NSIndexPath*>*)addSuggestionsToModel:
234 (NSArray<ContentSuggestion*>*)suggestions { 236 (NSArray<ContentSuggestion*>*)suggestions {
235 if (suggestions.count == 0) { 237 if (suggestions.count == 0) {
236 return [NSArray array]; 238 return [NSArray array];
237 } 239 }
238 240
241 NSMutableArray<ContentSuggestionsMostVisited*>* mostVisitedToAdd =
242 [NSMutableArray array];
243
244 CSCollectionViewModel* model =
245 self.collectionViewController.collectionViewModel;
239 NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array]; 246 NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array];
240 for (ContentSuggestion* suggestion in suggestions) { 247 for (ContentSuggestion* suggestion in suggestions) {
241 ContentSuggestionsSectionInformation* sectionInfo = 248 ContentSuggestionsSectionInformation* sectionInfo =
242 suggestion.suggestionIdentifier.sectionInfo; 249 suggestion.suggestionIdentifier.sectionInfo;
243 NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo); 250 NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
244 CSCollectionViewModel* model =
245 self.collectionViewController.collectionViewModel;
246 251
247 if (![model hasSectionForSectionIdentifier:sectionIdentifier]) 252 if (![model hasSectionForSectionIdentifier:sectionIdentifier])
248 return [NSArray array]; 253 continue;
249 254
250 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; 255 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
251 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section]; 256 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
252 257
253 if (suggestion.type != ContentSuggestionTypeEmpty && 258 if (suggestion.type != ContentSuggestionTypeEmpty &&
254 [model hasItemAtIndexPath:indexPath] && 259 [model hasItemAtIndexPath:indexPath] &&
255 [model itemAtIndexPath:indexPath].type == ItemTypeEmpty) { 260 [model itemAtIndexPath:indexPath].type == ItemTypeEmpty) {
256 [self.collectionViewController dismissEntryAtIndexPath:indexPath]; 261 [self.collectionViewController dismissEntryAtIndexPath:indexPath];
257 } 262 }
258 263
(...skipping 22 matching lines...) Expand all
281 case ContentSuggestionTypeReadingList: { 286 case ContentSuggestionTypeReadingList: {
282 ContentSuggestionsReadingListItem* readingListItem = 287 ContentSuggestionsReadingListItem* readingListItem =
283 [self readingListItemForSuggestion:suggestion]; 288 [self readingListItemForSuggestion:suggestion];
284 289
285 NSIndexPath* addedIndexPath = [self addItem:readingListItem 290 NSIndexPath* addedIndexPath = [self addItem:readingListItem
286 toSectionWithIdentifier:sectionIdentifier]; 291 toSectionWithIdentifier:sectionIdentifier];
287 [indexPaths addObject:addedIndexPath]; 292 [indexPaths addObject:addedIndexPath];
288 break; 293 break;
289 } 294 }
290 case ContentSuggestionTypeMostVisited: { 295 case ContentSuggestionTypeMostVisited: {
291 // TODO(crbug.com/707754): Add the most visited item. 296 NSInteger section =
297 [model sectionForSectionIdentifier:SectionIdentifierMostVisited];
298 NSIndexPath* indexPath =
299 [NSIndexPath indexPathForItem:0 inSection:section];
300
301 if ([model numberOfItemsInSection:section] == 0) {
302 [model addItem:[[ContentSuggestionsMostVisitedItem alloc]
303 initWithType:ItemTypeMostVisited]
304 toSectionWithIdentifier:SectionIdentifierMostVisited];
305 [indexPaths addObject:indexPath];
306 }
307
308 ContentSuggestionsMostVisited* mostVisited =
309 [ContentSuggestionsMostVisited mostVisitedWithTitle:suggestion.title
310 attributes:nil];
311 [mostVisitedToAdd addObject:mostVisited];
292 break; 312 break;
293 } 313 }
294 } 314 }
295 } 315 }
296 316
317 if ([model hasSectionForSectionIdentifier:SectionIdentifierMostVisited]) {
318 NSInteger section =
319 [model sectionForSectionIdentifier:SectionIdentifierMostVisited];
320 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
321 ContentSuggestionsMostVisitedItem* item =
322 base::mac::ObjCCast<ContentSuggestionsMostVisitedItem>(
323 [model itemAtIndexPath:indexPath]);
324 item.suggestions = mostVisitedToAdd;
325 }
326
297 return indexPaths; 327 return indexPaths;
298 } 328 }
299 329
300 - (NSIndexSet*)addSectionsForSuggestionsToModel: 330 - (NSIndexSet*)addSectionsForSuggestionsToModel:
301 (NSArray<ContentSuggestion*>*)suggestions { 331 (NSArray<ContentSuggestion*>*)suggestions {
302 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; 332 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
303 333
304 CSCollectionViewModel* model = 334 CSCollectionViewModel* model =
305 self.collectionViewController.collectionViewModel; 335 self.collectionViewController.collectionViewModel;
306 for (ContentSuggestion* suggestion in suggestions) { 336 for (ContentSuggestion* suggestion in suggestions) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 CSCollectionViewModel* model = 575 CSCollectionViewModel* model =
546 self.collectionViewController.collectionViewModel; 576 self.collectionViewController.collectionViewModel;
547 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; 577 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
548 NSInteger itemNumber = [model numberOfItemsInSection:section]; 578 NSInteger itemNumber = [model numberOfItemsInSection:section];
549 [model addItem:item toSectionWithIdentifier:sectionIdentifier]; 579 [model addItem:item toSectionWithIdentifier:sectionIdentifier];
550 580
551 return [NSIndexPath indexPathForItem:itemNumber inSection:section]; 581 return [NSIndexPath indexPathForItem:itemNumber inSection:section];
552 } 582 }
553 583
554 @end 584 @end
OLDNEW
« 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