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" |
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_but
ton_item.h" | |
17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_exp
andable_item.h" | |
18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_fav
icon_item.h" | |
19 #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" |
20 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_rea
ding_list_item.h" | 17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_rea
ding_list_item.h" |
21 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" | |
22 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex
t_item.h" | 18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex
t_item.h" |
23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
24 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" | 20 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink
.h" |
25 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" | 21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour
ce.h" |
26 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" | 22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet
cher.h" |
27 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" | 23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
28 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
_identifier.h" | 24 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
_identifier.h" |
29 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" | 25 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" |
30 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h" | 26 #import "ios/chrome/browser/ui/favicon/favicon_attributes.h" |
31 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
32 #include "url/gurl.h" | 28 #include "url/gurl.h" |
33 | 29 |
34 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
35 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
36 #endif | 32 #endif |
37 | 33 |
38 namespace { | 34 namespace { |
39 | 35 |
40 using CSCollectionViewItem = | 36 using CSCollectionViewItem = |
41 CollectionViewItem<ContentSuggestionIdentification>; | 37 CollectionViewItem<ContentSuggestionIdentification>; |
42 using CSCollectionViewModel = CollectionViewModel<CSCollectionViewItem*>; | 38 using CSCollectionViewModel = CollectionViewModel<CSCollectionViewItem*>; |
43 | 39 |
44 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. | 40 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. |
45 typedef NS_ENUM(NSInteger, ItemType) { | 41 typedef NS_ENUM(NSInteger, ItemType) { |
46 ItemTypeText = kItemTypeEnumZero, | 42 ItemTypeArticle = kItemTypeEnumZero, |
47 ItemTypeArticle, | |
48 ItemTypeExpand, | |
49 ItemTypeStack, | |
50 ItemTypeFavicon, | |
51 ItemTypeFooter, | 43 ItemTypeFooter, |
52 ItemTypeHeader, | 44 ItemTypeHeader, |
53 ItemTypeEmpty, | 45 ItemTypeEmpty, |
54 ItemTypeReadingList, | 46 ItemTypeReadingList, |
55 }; | 47 }; |
56 | 48 |
57 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 49 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
58 SectionIdentifierBookmarks = kSectionIdentifierEnumZero, | 50 SectionIdentifierArticles = kSectionIdentifierEnumZero, |
59 SectionIdentifierArticles, | |
60 SectionIdentifierReadingList, | 51 SectionIdentifierReadingList, |
61 SectionIdentifierDefault, | 52 SectionIdentifierDefault, |
62 }; | 53 }; |
63 | 54 |
64 // Update ContentSuggestionTypeForItemType if you update this function. | 55 // Update ContentSuggestionTypeForItemType if you update this function. |
65 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) { | 56 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) { |
66 switch (type) { | 57 switch (type) { |
67 case ContentSuggestionTypeArticle: | 58 case ContentSuggestionTypeArticle: |
68 return ItemTypeArticle; | 59 return ItemTypeArticle; |
69 case ContentSuggestionTypeEmpty: | 60 case ContentSuggestionTypeEmpty: |
(...skipping 13 matching lines...) Expand all Loading... |
83 // Add new type here | 74 // Add new type here |
84 | 75 |
85 // Default type. | 76 // Default type. |
86 return ContentSuggestionTypeEmpty; | 77 return ContentSuggestionTypeEmpty; |
87 } | 78 } |
88 | 79 |
89 // Returns the section identifier corresponding to the section |info|. | 80 // Returns the section identifier corresponding to the section |info|. |
90 SectionIdentifier SectionIdentifierForInfo( | 81 SectionIdentifier SectionIdentifierForInfo( |
91 ContentSuggestionsSectionInformation* info) { | 82 ContentSuggestionsSectionInformation* info) { |
92 switch (info.sectionID) { | 83 switch (info.sectionID) { |
93 case ContentSuggestionsSectionBookmarks: | |
94 return SectionIdentifierBookmarks; | |
95 | |
96 case ContentSuggestionsSectionArticles: | 84 case ContentSuggestionsSectionArticles: |
97 return SectionIdentifierArticles; | 85 return SectionIdentifierArticles; |
98 | 86 |
99 case ContentSuggestionsSectionReadingList: | 87 case ContentSuggestionsSectionReadingList: |
100 return SectionIdentifierReadingList; | 88 return SectionIdentifierReadingList; |
101 | 89 |
102 case ContentSuggestionsSectionUnknown: | 90 case ContentSuggestionsSectionUnknown: |
103 return SectionIdentifierDefault; | 91 return SectionIdentifierDefault; |
104 } | 92 } |
105 } | 93 } |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 [model sectionIdentifierForSection:sectionNumber]; | 500 [model sectionIdentifierForSection:sectionNumber]; |
513 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { | 501 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { |
514 [self.collectionViewController | 502 [self.collectionViewController |
515 reconfigureCellsForItems:@[ item ] | 503 reconfigureCellsForItems:@[ item ] |
516 inSectionWithIdentifier:sectionIdentifier]; | 504 inSectionWithIdentifier:sectionIdentifier]; |
517 } | 505 } |
518 } | 506 } |
519 } | 507 } |
520 | 508 |
521 @end | 509 @end |
OLD | NEW |