| 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 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" | 10 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" |
| 11 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 11 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
| 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion_identifier
.h" |
| 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i
tem.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i
tem.h" |
| 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" |
| 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" | 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" |
| 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl
e_item.h" | 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl
e_item.h" |
| 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i
tem.h" | 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i
tem.h" |
| 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_section_i
nformation.h" | 19 #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" | 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite
m.h" |
| 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_text_item
.h" | 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_text_item
.h" |
| 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" | 22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 #pragma mark - Private methods | 143 #pragma mark - Private methods |
| 143 | 144 |
| 144 - (void)reloadData { | 145 - (void)reloadData { |
| 145 [self resetModels]; | 146 [self resetModels]; |
| 146 CollectionViewModel* model = | 147 CollectionViewModel* model = |
| 147 self.collectionViewController.collectionViewModel; | 148 self.collectionViewController.collectionViewModel; |
| 148 | 149 |
| 149 NSArray<ContentSuggestion*>* suggestions = [self.dataSource allSuggestions]; | 150 NSArray<ContentSuggestion*>* suggestions = [self.dataSource allSuggestions]; |
| 150 | 151 |
| 151 for (ContentSuggestion* suggestion in suggestions) { | 152 for (ContentSuggestion* suggestion in suggestions) { |
| 152 NSInteger sectionIdentifier = [self addSectionIfNeeded:suggestion.section]; | 153 NSInteger sectionIdentifier = |
| 154 [self addSectionIfNeeded:suggestion.suggestionIdentifier.sectionInfo]; |
| 153 ContentSuggestionsArticleItem* articleItem = | 155 ContentSuggestionsArticleItem* articleItem = |
| 154 [[ContentSuggestionsArticleItem alloc] | 156 [[ContentSuggestionsArticleItem alloc] |
| 155 initWithType:ItemTypeForContentSuggestionType(suggestion.type) | 157 initWithType:ItemTypeForContentSuggestionType(suggestion.type) |
| 156 title:suggestion.title | 158 title:suggestion.title |
| 157 subtitle:suggestion.text | 159 subtitle:suggestion.text |
| 158 image:suggestion.image | 160 image:suggestion.image |
| 159 url:suggestion.url]; | 161 url:suggestion.url]; |
| 162 |
| 160 articleItem.publisher = suggestion.publisher; | 163 articleItem.publisher = suggestion.publisher; |
| 161 articleItem.publishDate = suggestion.publishDate; | 164 articleItem.publishDate = suggestion.publishDate; |
| 162 | 165 |
| 166 articleItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| 167 |
| 163 [model addItem:articleItem toSectionWithIdentifier:sectionIdentifier]; | 168 [model addItem:articleItem toSectionWithIdentifier:sectionIdentifier]; |
| 164 } | 169 } |
| 165 | 170 |
| 166 if ([self.collectionViewController isViewLoaded]) { | 171 if ([self.collectionViewController isViewLoaded]) { |
| 167 [self.collectionViewController.collectionView reloadData]; | 172 [self.collectionViewController.collectionView reloadData]; |
| 168 } | 173 } |
| 169 } | 174 } |
| 170 | 175 |
| 171 - (NSInteger)addSectionIfNeeded: | 176 - (NSInteger)addSectionIfNeeded: |
| 172 (ContentSuggestionsSectionInformation*)sectionInformation { | 177 (ContentSuggestionsSectionInformation*)sectionInformation { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 183 } | 188 } |
| 184 return sectionIdentifier; | 189 return sectionIdentifier; |
| 185 } | 190 } |
| 186 | 191 |
| 187 - (void)resetModels { | 192 - (void)resetModels { |
| 188 [self.collectionViewController loadModel]; | 193 [self.collectionViewController loadModel]; |
| 189 self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init]; | 194 self.sectionInfoBySectionIdentifier = [[NSMutableDictionary alloc] init]; |
| 190 } | 195 } |
| 191 | 196 |
| 192 @end | 197 @end |
| OLD | NEW |