| 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/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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 CollectionViewItem<ContentSuggestionIdentification>; | 37 CollectionViewItem<ContentSuggestionIdentification>; |
| 38 using CSCollectionViewModel = CollectionViewModel<CSCollectionViewItem*>; | 38 using CSCollectionViewModel = CollectionViewModel<CSCollectionViewItem*>; |
| 39 | 39 |
| 40 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. | 40 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. |
| 41 typedef NS_ENUM(NSInteger, ItemType) { | 41 typedef NS_ENUM(NSInteger, ItemType) { |
| 42 ItemTypeArticle = kItemTypeEnumZero, | 42 ItemTypeArticle = kItemTypeEnumZero, |
| 43 ItemTypeFooter, | 43 ItemTypeFooter, |
| 44 ItemTypeHeader, | 44 ItemTypeHeader, |
| 45 ItemTypeEmpty, | 45 ItemTypeEmpty, |
| 46 ItemTypeReadingList, | 46 ItemTypeReadingList, |
| 47 ItemTypeMostVisited, |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 50 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 50 SectionIdentifierArticles = kSectionIdentifierEnumZero, | 51 SectionIdentifierArticles = kSectionIdentifierEnumZero, |
| 51 SectionIdentifierReadingList, | 52 SectionIdentifierReadingList, |
| 53 SectionIdentifierMostVisited, |
| 52 SectionIdentifierDefault, | 54 SectionIdentifierDefault, |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 // Update ContentSuggestionTypeForItemType if you update this function. | 57 // Update ContentSuggestionTypeForItemType if you update this function. |
| 56 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) { | 58 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) { |
| 57 switch (type) { | 59 switch (type) { |
| 58 case ContentSuggestionTypeArticle: | 60 case ContentSuggestionTypeArticle: |
| 59 return ItemTypeArticle; | 61 return ItemTypeArticle; |
| 60 case ContentSuggestionTypeEmpty: | 62 case ContentSuggestionTypeEmpty: |
| 61 return ItemTypeEmpty; | 63 return ItemTypeEmpty; |
| 62 case ContentSuggestionTypeReadingList: | 64 case ContentSuggestionTypeReadingList: |
| 63 return ItemTypeReadingList; | 65 return ItemTypeReadingList; |
| 66 case ContentSuggestionTypeMostVisited: |
| 67 return ItemTypeMostVisited; |
| 64 } | 68 } |
| 65 } | 69 } |
| 66 | 70 |
| 67 ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) { | 71 ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) { |
| 68 if (type == ItemTypeArticle) | 72 if (type == ItemTypeArticle) |
| 69 return ContentSuggestionTypeArticle; | 73 return ContentSuggestionTypeArticle; |
| 70 if (type == ItemTypeEmpty) | 74 if (type == ItemTypeEmpty) |
| 71 return ContentSuggestionTypeEmpty; | 75 return ContentSuggestionTypeEmpty; |
| 72 if (type == ItemTypeReadingList) | 76 if (type == ItemTypeReadingList) |
| 73 return ContentSuggestionTypeReadingList; | 77 return ContentSuggestionTypeReadingList; |
| 78 if (type == ItemTypeMostVisited) |
| 79 return ContentSuggestionTypeMostVisited; |
| 74 // Add new type here | 80 // Add new type here |
| 75 | 81 |
| 76 // Default type. | 82 // Default type. |
| 77 return ContentSuggestionTypeEmpty; | 83 return ContentSuggestionTypeEmpty; |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Returns the section identifier corresponding to the section |info|. | 86 // Returns the section identifier corresponding to the section |info|. |
| 81 SectionIdentifier SectionIdentifierForInfo( | 87 SectionIdentifier SectionIdentifierForInfo( |
| 82 ContentSuggestionsSectionInformation* info) { | 88 ContentSuggestionsSectionInformation* info) { |
| 83 switch (info.sectionID) { | 89 switch (info.sectionID) { |
| 84 case ContentSuggestionsSectionArticles: | 90 case ContentSuggestionsSectionArticles: |
| 85 return SectionIdentifierArticles; | 91 return SectionIdentifierArticles; |
| 86 | 92 |
| 87 case ContentSuggestionsSectionReadingList: | 93 case ContentSuggestionsSectionReadingList: |
| 88 return SectionIdentifierReadingList; | 94 return SectionIdentifierReadingList; |
| 89 | 95 |
| 96 case ContentSuggestionsSectionMostVisited: |
| 97 return SectionIdentifierMostVisited; |
| 98 |
| 90 case ContentSuggestionsSectionUnknown: | 99 case ContentSuggestionsSectionUnknown: |
| 91 return SectionIdentifierDefault; | 100 return SectionIdentifierDefault; |
| 92 } | 101 } |
| 93 } | 102 } |
| 94 | 103 |
| 95 } // namespace | 104 } // namespace |
| 96 | 105 |
| 97 @interface ContentSuggestionsCollectionUpdater ()< | 106 @interface ContentSuggestionsCollectionUpdater ()< |
| 98 ContentSuggestionsArticleItemDelegate, | 107 ContentSuggestionsArticleItemDelegate, |
| 99 ContentSuggestionsDataSink> | 108 ContentSuggestionsDataSink> |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 201 } |
| 193 | 202 |
| 194 - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo { | 203 - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo { |
| 195 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo); | 204 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo); |
| 196 NSInteger section = [self.collectionViewController.collectionViewModel | 205 NSInteger section = [self.collectionViewController.collectionViewModel |
| 197 sectionIdentifierForSection:sectionIdentifier]; | 206 sectionIdentifierForSection:sectionIdentifier]; |
| 198 | 207 |
| 199 [self.collectionViewController dismissSection:section]; | 208 [self.collectionViewController dismissSection:section]; |
| 200 } | 209 } |
| 201 | 210 |
| 211 - (void)reloadSection:(ContentSuggestionsSectionInformation*)sectionInfo { |
| 212 // TODO(crbug.com/707754): implement this method. |
| 213 } |
| 214 |
| 215 - (void)faviconAvailableForURL:(const GURL&)URL { |
| 216 // TODO(crbug.com/707754): implement this method. |
| 217 } |
| 218 |
| 202 #pragma mark - Public methods | 219 #pragma mark - Public methods |
| 203 | 220 |
| 204 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { | 221 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { |
| 205 NSNumber* identifier = @([self.collectionViewController.collectionViewModel | 222 NSNumber* identifier = @([self.collectionViewController.collectionViewModel |
| 206 sectionIdentifierForSection:section]); | 223 sectionIdentifierForSection:section]); |
| 207 ContentSuggestionsSectionInformation* sectionInformation = | 224 ContentSuggestionsSectionInformation* sectionInformation = |
| 208 self.sectionInfoBySectionIdentifier[identifier]; | 225 self.sectionInfoBySectionIdentifier[identifier]; |
| 209 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom; | 226 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom; |
| 210 } | 227 } |
| 211 | 228 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 readingListItem.title = suggestion.title; | 288 readingListItem.title = suggestion.title; |
| 272 readingListItem.subtitle = suggestion.publisher; | 289 readingListItem.subtitle = suggestion.publisher; |
| 273 | 290 |
| 274 readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier; | 291 readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier; |
| 275 | 292 |
| 276 NSIndexPath* addedIndexPath = [self addItem:readingListItem | 293 NSIndexPath* addedIndexPath = [self addItem:readingListItem |
| 277 toSectionWithIdentifier:sectionIdentifier]; | 294 toSectionWithIdentifier:sectionIdentifier]; |
| 278 [indexPaths addObject:addedIndexPath]; | 295 [indexPaths addObject:addedIndexPath]; |
| 279 break; | 296 break; |
| 280 } | 297 } |
| 298 case ContentSuggestionTypeMostVisited: { |
| 299 // TODO(crbug.com/707754): Add the most visited item. |
| 300 break; |
| 301 } |
| 281 } | 302 } |
| 282 } | 303 } |
| 283 | 304 |
| 284 return indexPaths; | 305 return indexPaths; |
| 285 } | 306 } |
| 286 | 307 |
| 287 - (NSIndexSet*)addSectionsForSuggestionsToModel: | 308 - (NSIndexSet*)addSectionsForSuggestionsToModel: |
| 288 (NSArray<ContentSuggestion*>*)suggestions { | 309 (NSArray<ContentSuggestion*>*)suggestions { |
| 289 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; | 310 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; |
| 290 | 311 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 [model sectionIdentifierForSection:sectionNumber]; | 521 [model sectionIdentifierForSection:sectionNumber]; |
| 501 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { | 522 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { |
| 502 [self.collectionViewController | 523 [self.collectionViewController |
| 503 reconfigureCellsForItems:@[ item ] | 524 reconfigureCellsForItems:@[ item ] |
| 504 inSectionWithIdentifier:sectionIdentifier]; | 525 inSectionWithIdentifier:sectionIdentifier]; |
| 505 } | 526 } |
| 506 } | 527 } |
| 507 } | 528 } |
| 508 | 529 |
| 509 @end | 530 @end |
| OLD | NEW |