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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm

Issue 2873503005: Create individual cells for MostVisited tiles (Closed)
Patch Set: Address comments 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 | « ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_unittest.mm ('k') | 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_mos t_visited_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_rea ding_list_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/cells/content_suggestions_tex t_item.h"
21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.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_sink .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_data_sour ce.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_image_fet cher.h"
25 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h" 24 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.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 _identifier.h"
27 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h" 26 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 (CollectionViewItem*)item { 230 (CollectionViewItem*)item {
232 return ContentSuggestionTypeForItemType(item.type); 231 return ContentSuggestionTypeForItemType(item.type);
233 } 232 }
234 233
235 - (NSArray<NSIndexPath*>*)addSuggestionsToModel: 234 - (NSArray<NSIndexPath*>*)addSuggestionsToModel:
236 (NSArray<ContentSuggestion*>*)suggestions { 235 (NSArray<ContentSuggestion*>*)suggestions {
237 if (suggestions.count == 0) { 236 if (suggestions.count == 0) {
238 return [NSArray array]; 237 return [NSArray array];
239 } 238 }
240 239
241 NSMutableArray<ContentSuggestionsMostVisited*>* mostVisitedToAdd =
242 [NSMutableArray array];
243
244 CSCollectionViewModel* model = 240 CSCollectionViewModel* model =
245 self.collectionViewController.collectionViewModel; 241 self.collectionViewController.collectionViewModel;
246 NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array]; 242 NSMutableArray<NSIndexPath*>* indexPaths = [NSMutableArray array];
247 for (ContentSuggestion* suggestion in suggestions) { 243 for (ContentSuggestion* suggestion in suggestions) {
248 ContentSuggestionsSectionInformation* sectionInfo = 244 ContentSuggestionsSectionInformation* sectionInfo =
249 suggestion.suggestionIdentifier.sectionInfo; 245 suggestion.suggestionIdentifier.sectionInfo;
250 NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo); 246 NSInteger sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
251 247
252 if (![model hasSectionForSectionIdentifier:sectionIdentifier]) 248 if (![model hasSectionForSectionIdentifier:sectionIdentifier])
253 continue; 249 continue;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 case ContentSuggestionTypeReadingList: { 282 case ContentSuggestionTypeReadingList: {
287 ContentSuggestionsReadingListItem* readingListItem = 283 ContentSuggestionsReadingListItem* readingListItem =
288 [self readingListItemForSuggestion:suggestion]; 284 [self readingListItemForSuggestion:suggestion];
289 285
290 NSIndexPath* addedIndexPath = [self addItem:readingListItem 286 NSIndexPath* addedIndexPath = [self addItem:readingListItem
291 toSectionWithIdentifier:sectionIdentifier]; 287 toSectionWithIdentifier:sectionIdentifier];
292 [indexPaths addObject:addedIndexPath]; 288 [indexPaths addObject:addedIndexPath];
293 break; 289 break;
294 } 290 }
295 case ContentSuggestionTypeMostVisited: { 291 case ContentSuggestionTypeMostVisited: {
296 NSInteger section = 292 ContentSuggestionsMostVisitedItem* mostVisitedItem =
297 [model sectionForSectionIdentifier:SectionIdentifierMostVisited]; 293 [[ContentSuggestionsMostVisitedItem alloc]
298 NSIndexPath* indexPath = 294 initWithType:ItemTypeMostVisited];
299 [NSIndexPath indexPathForItem:0 inSection:section]; 295 mostVisitedItem.title = suggestion.title;
300 296 [model addItem:mostVisitedItem
301 if ([model numberOfItemsInSection:section] == 0) { 297 toSectionWithIdentifier:SectionIdentifierMostVisited];
302 [model addItem:[[ContentSuggestionsMostVisitedItem alloc] 298 [indexPaths addObject:indexPath];
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];
312 break; 299 break;
313 } 300 }
314 } 301 }
315 } 302 }
316 303
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
327 return indexPaths; 304 return indexPaths;
328 } 305 }
329 306
330 - (NSIndexSet*)addSectionsForSuggestionsToModel: 307 - (NSIndexSet*)addSectionsForSuggestionsToModel:
331 (NSArray<ContentSuggestion*>*)suggestions { 308 (NSArray<ContentSuggestion*>*)suggestions {
332 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; 309 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
333 310
334 CSCollectionViewModel* model = 311 CSCollectionViewModel* model =
335 self.collectionViewController.collectionViewModel; 312 self.collectionViewController.collectionViewModel;
336 for (ContentSuggestion* suggestion in suggestions) { 313 for (ContentSuggestion* suggestion in suggestions) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 CSCollectionViewModel* model = 552 CSCollectionViewModel* model =
576 self.collectionViewController.collectionViewModel; 553 self.collectionViewController.collectionViewModel;
577 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; 554 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
578 NSInteger itemNumber = [model numberOfItemsInSection:section]; 555 NSInteger itemNumber = [model numberOfItemsInSection:section];
579 [model addItem:item toSectionWithIdentifier:sectionIdentifier]; 556 [model addItem:item toSectionWithIdentifier:sectionIdentifier];
580 557
581 return [NSIndexPath indexPathForItem:itemNumber inSection:section]; 558 return [NSIndexPath indexPathForItem:itemNumber inSection:section];
582 } 559 }
583 560
584 @end 561 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698