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

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

Issue 2644123003: Move ios/ui/suggestions to ios/ui/content_suggestions (Closed)
Patch Set: Rebase Created 3 years, 11 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
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/suggestions/suggestions_collection_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 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 9 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
11 #import "ios/chrome/browser/ui/suggestions/suggestions_article_item.h" 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i tem.h"
12 #import "ios/chrome/browser/ui/suggestions/suggestions_expandable_item.h" 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl e_item.h"
13 #import "ios/chrome/browser/ui/suggestions/suggestions_favicon_item.h" 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i tem.h"
14 #import "ios/chrome/browser/ui/suggestions/suggestions_item.h" 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h"
15 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item.h" 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite m.h"
16 #import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h" 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
17 17
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 18 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 19 #error "This file requires ARC support."
20 #endif 20 #endif
21 21
22 @implementation SuggestionsCollectionUpdater 22 @implementation ContentSuggestionsCollectionUpdater
23 23
24 @synthesize collectionViewController = _collectionViewController; 24 @synthesize collectionViewController = _collectionViewController;
25 25
26 #pragma mark - Properties 26 #pragma mark - Properties
27 27
28 - (void)setCollectionViewController: 28 - (void)setCollectionViewController:
29 (SuggestionsViewController*)collectionViewController { 29 (ContentSuggestionsViewController*)collectionViewController {
30 _collectionViewController = collectionViewController; 30 _collectionViewController = collectionViewController;
31 [collectionViewController loadModel]; 31 [collectionViewController loadModel];
32 CollectionViewModel* model = collectionViewController.collectionViewModel; 32 CollectionViewModel* model = collectionViewController.collectionViewModel;
33 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; 33 NSInteger sectionIdentifier = kSectionIdentifierEnumZero;
34 34
35 // Stack Item. 35 // Stack Item.
36 [model addSectionWithIdentifier:sectionIdentifier]; 36 [model addSectionWithIdentifier:sectionIdentifier];
37 [model addItem:[[SuggestionsStackItem alloc] initWithType:ItemTypeStack 37 [model addItem:[[ContentSuggestionsStackItem alloc]
38 title:@"The title" 38 initWithType:ItemTypeStack
39 subtitle:@"The subtitle"] 39 title:@"The title"
40 subtitle:@"The subtitle"]
40 toSectionWithIdentifier:sectionIdentifier++]; 41 toSectionWithIdentifier:sectionIdentifier++];
41 42
42 // Favicon Item. 43 // Favicon Item.
43 [model addSectionWithIdentifier:sectionIdentifier]; 44 [model addSectionWithIdentifier:sectionIdentifier];
44 SuggestionsFaviconItem* faviconItem = 45 ContentSuggestionsFaviconItem* faviconItem =
45 [[SuggestionsFaviconItem alloc] initWithType:ItemTypeFavicon]; 46 [[ContentSuggestionsFaviconItem alloc] initWithType:ItemTypeFavicon];
46 for (NSInteger i = 0; i < 6; i++) { 47 for (NSInteger i = 0; i < 6; i++) {
47 [faviconItem addFavicon:[UIImage imageNamed:@"bookmark_gray_star"] 48 [faviconItem addFavicon:[UIImage imageNamed:@"bookmark_gray_star"]
48 withTitle:@"Super website! Incredible!"]; 49 withTitle:@"Super website! Incredible!"];
49 } 50 }
50 faviconItem.delegate = _collectionViewController; 51 faviconItem.delegate = _collectionViewController;
51 [model addItem:faviconItem toSectionWithIdentifier:sectionIdentifier++]; 52 [model addItem:faviconItem toSectionWithIdentifier:sectionIdentifier++];
52 53
53 for (NSInteger i = 0; i < 3; i++) { 54 for (NSInteger i = 0; i < 3; i++) {
54 [model addSectionWithIdentifier:sectionIdentifier]; 55 [model addSectionWithIdentifier:sectionIdentifier];
55 56
56 // Standard Item. 57 // Standard Item.
57 [model addItem:[[SuggestionsItem alloc] initWithType:ItemTypeText 58 [model addItem:[[ContentSuggestionsItem alloc] initWithType:ItemTypeText
58 title:@"The title" 59 title:@"The title"
59 subtitle:@"The subtitle"] 60 subtitle:@"The subtitle"]
60 toSectionWithIdentifier:sectionIdentifier]; 61 toSectionWithIdentifier:sectionIdentifier];
61 62
62 // Article Item. 63 // Article Item.
63 [model addItem:[[SuggestionsArticleItem alloc] 64 [model addItem:[[ContentSuggestionsArticleItem alloc]
64 initWithType:ItemTypeArticle 65 initWithType:ItemTypeArticle
65 title:@"Title of an Article" 66 title:@"Title of an Article"
66 subtitle:@"This is the subtitle of an article, can " 67 subtitle:@"This is the subtitle of an article, can "
67 @"spawn on multiple lines" 68 @"spawn on multiple lines"
68 image:[UIImage 69 image:[UIImage
69 imageNamed:@"distillation_success"]] 70 imageNamed:@"distillation_success"]]
70 toSectionWithIdentifier:sectionIdentifier]; 71 toSectionWithIdentifier:sectionIdentifier];
71 72
72 // Expandable Item. 73 // Expandable Item.
73 SuggestionsExpandableItem* expandableItem = 74 SuggestionsExpandableItem* expandableItem =
(...skipping 12 matching lines...) Expand all
86 sectionIdentifier++; 87 sectionIdentifier++;
87 } 88 }
88 } 89 }
89 90
90 #pragma mark - Public methods 91 #pragma mark - Public methods
91 92
92 - (void)addTextItem:(NSString*)title 93 - (void)addTextItem:(NSString*)title
93 subtitle:(NSString*)subtitle 94 subtitle:(NSString*)subtitle
94 toSection:(NSInteger)inputSection { 95 toSection:(NSInteger)inputSection {
95 DCHECK(_collectionViewController); 96 DCHECK(_collectionViewController);
96 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText 97 ContentSuggestionsItem* item =
97 title:title 98 [[ContentSuggestionsItem alloc] initWithType:ItemTypeText
98 subtitle:subtitle]; 99 title:title
100 subtitle:subtitle];
99 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection; 101 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection;
100 NSInteger sectionIndex = inputSection; 102 NSInteger sectionIndex = inputSection;
101 CollectionViewModel* model = _collectionViewController.collectionViewModel; 103 CollectionViewModel* model = _collectionViewController.collectionViewModel;
102 if ([model numberOfSections] <= inputSection) { 104 if ([model numberOfSections] <= inputSection) {
103 sectionIndex = [model numberOfSections]; 105 sectionIndex = [model numberOfSections];
104 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex; 106 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex;
105 [_collectionViewController.collectionView performBatchUpdates:^{ 107 [_collectionViewController.collectionView performBatchUpdates:^{
106 [_collectionViewController.collectionViewModel 108 [_collectionViewController.collectionViewModel
107 addSectionWithIdentifier:sectionIdentifier]; 109 addSectionWithIdentifier:sectionIdentifier];
108 [_collectionViewController.collectionView 110 [_collectionViewController.collectionView
(...skipping 12 matching lines...) Expand all
121 inSection:sectionIndex] ]]; 123 inSection:sectionIndex] ]];
122 } 124 }
123 completion:nil]; 125 completion:nil];
124 } 126 }
125 127
126 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { 128 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section {
127 return section == 0 || section == 1; 129 return section == 0 || section == 1;
128 } 130 }
129 131
130 @end 132 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698