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

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: Created 3 years, 8 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 (CollectionViewItem*)item { 232 (CollectionViewItem*)item {
231 return ContentSuggestionTypeForItemType(item.type); 233 return ContentSuggestionTypeForItemType(item.type);
232 } 234 }
233 235
234 - (NSArray<NSIndexPath*>*)addSuggestionsToModel: 236 - (NSArray<NSIndexPath*>*)addSuggestionsToModel:
235 (NSArray<ContentSuggestion*>*)suggestions { 237 (NSArray<ContentSuggestion*>*)suggestions {
236 if (suggestions.count == 0) { 238 if (suggestions.count == 0) {
237 return [NSArray array]; 239 return [NSArray array];
238 } 240 }
239 241
242 NSMutableArray<ContentSuggestionsMostVisited*>* mostVisitedToAdd =
243 [NSMutableArray array];
244
245 CSCollectionViewModel* model =
246 self.collectionViewController.collectionViewModel;
240 NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array]; 247 NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array];
241 for (ContentSuggestion* suggestion in suggestions) { 248 for (ContentSuggestion* suggestion in suggestions) {
242 ContentSuggestionsSectionInformation* sectionInfo = 249 ContentSuggestionsSectionInformation* sectionInfo =
243 suggestion.suggestionIdentifier.sectionInfo; 250 suggestion.suggestionIdentifier.sectionInfo;
244 NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo); 251 NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
245 CSCollectionViewModel* model =
246 self.collectionViewController.collectionViewModel;
247 252
248 if (![model hasSectionForSectionIdentifier:sectionIdentifier]) 253 if (![model hasSectionForSectionIdentifier:sectionIdentifier])
249 return [NSArray array]; 254 continue;
250 255
251 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; 256 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
252 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section]; 257 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
253 258
254 if (suggestion.type != ContentSuggestionTypeEmpty && 259 if (suggestion.type != ContentSuggestionTypeEmpty &&
255 [model hasItemAtIndexPath:indexPath] && 260 [model hasItemAtIndexPath:indexPath] &&
256 [model itemAtIndexPath:indexPath].type == ItemTypeEmpty) { 261 [model itemAtIndexPath:indexPath].type == ItemTypeEmpty) {
257 [self.collectionViewController dismissEntryAtIndexPath:indexPath]; 262 [self.collectionViewController dismissEntryAtIndexPath:indexPath];
258 } 263 }
259 264
(...skipping 22 matching lines...) Expand all
282 case ContentSuggestionTypeReadingList: { 287 case ContentSuggestionTypeReadingList: {
283 ContentSuggestionsReadingListItem* readingListItem = 288 ContentSuggestionsReadingListItem* readingListItem =
284 [self readingListItemForSuggestion:suggestion]; 289 [self readingListItemForSuggestion:suggestion];
285 290
286 NSIndexPath* addedIndexPath = [self addItem:readingListItem 291 NSIndexPath* addedIndexPath = [self addItem:readingListItem
287 toSectionWithIdentifier:sectionIdentifier]; 292 toSectionWithIdentifier:sectionIdentifier];
288 [indexPaths addObject:addedIndexPath]; 293 [indexPaths addObject:addedIndexPath];
289 break; 294 break;
290 } 295 }
291 case ContentSuggestionTypeMostVisited: { 296 case ContentSuggestionTypeMostVisited: {
297 NSInteger section =
298 [model sectionForSectionIdentifier:SectionIdentifierMostVisited];
299 NSIndexPath* indexPath =
300 [NSIndexPath indexPathForItem:0 inSection:section];
301
302 if ([model numberOfItemsInSection:section] == 0) {
303 [model addItem:[[ContentSuggestionsMostVisitedItem alloc]
304 initWithType:ItemTypeMostVisited]
305 toSectionWithIdentifier:SectionIdentifierMostVisited];
306 [indexPaths addObject:indexPath];
307 }
308
309 ContentSuggestionsMostVisited* mostVisited =
310 [ContentSuggestionsMostVisited mostVisitedWithTitle:suggestion.title
311 attributes:nil];
312 [mostVisitedToAdd addObject:mostVisited];
292 // TODO(crbug.com/707754): Add the most visited item. 313 // 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.
293 break; 314 break;
294 } 315 }
295 } 316 }
296 } 317 }
297 318
319 NSInteger section =
320 [model sectionForSectionIdentifier:SectionIdentifierMostVisited];
321 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
322 ContentSuggestionsMostVisitedItem* item =
323 (ContentSuggestionsMostVisitedItem*)[model itemAtIndexPath:indexPath];
lpromero 2017/05/05 15:08:25 base::mac::ObjCCast<ContentSuggestionsMostVisitedI
gambard 2017/05/05 15:24:52 Done.
324 item.suggestions = mostVisitedToAdd;
325
326 [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.
327
298 return indexPaths; 328 return indexPaths;
299 } 329 }
300 330
301 - (NSIndexSet*)addSectionsForSuggestionsToModel: 331 - (NSIndexSet*)addSectionsForSuggestionsToModel:
302 (NSArray<ContentSuggestion*>*)suggestions { 332 (NSArray<ContentSuggestion*>*)suggestions {
303 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; 333 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
304 334
305 CSCollectionViewModel* model = 335 CSCollectionViewModel* model =
306 self.collectionViewController.collectionViewModel; 336 self.collectionViewController.collectionViewModel;
307 for (ContentSuggestion* suggestion in suggestions) { 337 for (ContentSuggestion* suggestion in suggestions) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 [model sectionIdentifierForSection:sectionNumber]; 583 [model sectionIdentifierForSection:sectionNumber];
554 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { 584 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) {
555 [self.collectionViewController 585 [self.collectionViewController
556 reconfigureCellsForItems:@[ item ] 586 reconfigureCellsForItems:@[ item ]
557 inSectionWithIdentifier:sectionIdentifier]; 587 inSectionWithIdentifier:sectionIdentifier];
558 } 588 }
559 } 589 }
560 } 590 }
561 591
562 @end 592 @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