OLD | NEW |
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 #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/content_suggestions/content_suggestion.h" | 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i
tem.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i
tem.h" |
13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" | 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" |
14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" |
15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl
e_item.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl
e_item.h" |
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i
tem.h" | 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i
tem.h" |
17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h" | |
18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i
nformation.h" | 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i
nformation.h" |
19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite
m.h" | 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite
m.h" |
| 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_text_item
.h" |
20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" | 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 #if !defined(__has_feature) || !__has_feature(objc_arc) | 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
24 #error "This file requires ARC support." | 24 #error "This file requires ARC support." |
25 #endif | 25 #endif |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. | 29 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 #pragma mark - ContentSuggestionsDataSink | 120 #pragma mark - ContentSuggestionsDataSink |
121 | 121 |
122 - (void)dataAvailable { | 122 - (void)dataAvailable { |
123 [self reloadData]; | 123 [self reloadData]; |
124 } | 124 } |
125 | 125 |
126 #pragma mark - Public methods | 126 #pragma mark - Public methods |
127 | 127 |
128 - (void)addTextItem:(NSString*)title | |
129 subtitle:(NSString*)subtitle | |
130 toSection:(NSInteger)inputSection { | |
131 DCHECK(self.collectionViewController); | |
132 ContentSuggestionsItem* item = | |
133 [[ContentSuggestionsItem alloc] initWithType:ItemTypeText | |
134 title:title | |
135 subtitle:subtitle]; | |
136 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection; | |
137 NSInteger sectionIndex = inputSection; | |
138 CollectionViewModel* model = | |
139 self.collectionViewController.collectionViewModel; | |
140 if ([model numberOfSections] <= inputSection) { | |
141 sectionIndex = [model numberOfSections]; | |
142 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex; | |
143 [self.collectionViewController.collectionView performBatchUpdates:^{ | |
144 [self.collectionViewController.collectionViewModel | |
145 addSectionWithIdentifier:sectionIdentifier]; | |
146 [self.collectionViewController.collectionView | |
147 insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]]; | |
148 } | |
149 completion:nil]; | |
150 } | |
151 NSInteger numberOfItemsInSection = | |
152 [model numberOfItemsInSection:sectionIndex]; | |
153 [self.collectionViewController.collectionViewModel addItem:item | |
154 toSectionWithIdentifier:sectionIdentifier]; | |
155 [self.collectionViewController.collectionView performBatchUpdates:^{ | |
156 [self.collectionViewController.collectionView | |
157 insertItemsAtIndexPaths:@[ [NSIndexPath | |
158 indexPathForRow:numberOfItemsInSection | |
159 inSection:sectionIndex] ]]; | |
160 } | |
161 completion:nil]; | |
162 } | |
163 | |
164 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { | 128 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { |
165 NSNumber* identifier = @([self.collectionViewController.collectionViewModel | 129 NSNumber* identifier = @([self.collectionViewController.collectionViewModel |
166 sectionIdentifierForSection:section]); | 130 sectionIdentifierForSection:section]); |
167 ContentSuggestionsSectionInformation* sectionInformation = | 131 ContentSuggestionsSectionInformation* sectionInformation = |
168 self.sectionInfoBySectionIdentifier[identifier]; | 132 self.sectionInfoBySectionIdentifier[identifier]; |
169 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom; | 133 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom; |
170 } | 134 } |
171 | 135 |
172 - (ContentSuggestionType)contentSuggestionTypeForItem: | 136 - (ContentSuggestionType)contentSuggestionTypeForItem: |
173 (CollectionViewItem*)item { | 137 (CollectionViewItem*)item { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 180 } |
217 return sectionIdentifier; | 181 return sectionIdentifier; |
218 } | 182 } |
219 | 183 |
220 - (void)resetModels { | 184 - (void)resetModels { |
221 [self.collectionViewController loadModel]; | 185 [self.collectionViewController loadModel]; |
222 self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init]; | 186 self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init]; |
223 } | 187 } |
224 | 188 |
225 @end | 189 @end |
OLD | NEW |