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

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

Issue 2755383002: Add ContentSuggestion for ReadingList (Closed)
Patch Set: Rebase Created 3 years, 8 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/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/time/time.h" 10 #include "base/time/time.h"
10 #include "components/strings/grit/components_strings.h" 11 #include "components/strings/grit/components_strings.h"
11 #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 "
12 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" 13 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
13 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
14 #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"
15 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_but ton_item.h" 16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_but ton_item.h"
16 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_exp andable_item.h" 17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_exp andable_item.h"
17 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_fav icon_item.h" 18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_fav icon_item.h"
18 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_foo ter_item.h" 19 #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"
19 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta ck_item.h" 21 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta ck_item.h"
20 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex t_item.h" 22 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex t_item.h"
21 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" 23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
22 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h" 24 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h"
23 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour ce.h" 25 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour ce.h"
24 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h" 26 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_image_fet cher.h"
25 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h" 27 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
26 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h" 28 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
27 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h" 29 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
28 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
(...skipping 13 matching lines...) Expand all
42 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater. 44 // Enum defining the ItemType of this ContentSuggestionsCollectionUpdater.
43 typedef NS_ENUM(NSInteger, ItemType) { 45 typedef NS_ENUM(NSInteger, ItemType) {
44 ItemTypeText = kItemTypeEnumZero, 46 ItemTypeText = kItemTypeEnumZero,
45 ItemTypeArticle, 47 ItemTypeArticle,
46 ItemTypeExpand, 48 ItemTypeExpand,
47 ItemTypeStack, 49 ItemTypeStack,
48 ItemTypeFavicon, 50 ItemTypeFavicon,
49 ItemTypeFooter, 51 ItemTypeFooter,
50 ItemTypeHeader, 52 ItemTypeHeader,
51 ItemTypeEmpty, 53 ItemTypeEmpty,
54 ItemTypeReadingList,
52 }; 55 };
53 56
54 typedef NS_ENUM(NSInteger, SectionIdentifier) { 57 typedef NS_ENUM(NSInteger, SectionIdentifier) {
55 SectionIdentifierBookmarks = kSectionIdentifierEnumZero, 58 SectionIdentifierBookmarks = kSectionIdentifierEnumZero,
56 SectionIdentifierArticles, 59 SectionIdentifierArticles,
60 SectionIdentifierReadingList,
57 SectionIdentifierDefault, 61 SectionIdentifierDefault,
58 }; 62 };
59 63
64 // Update ContentSuggestionTypeForItemType if you update this function.
60 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) { 65 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) {
61 switch (type) { 66 switch (type) {
62 case ContentSuggestionTypeArticle: 67 case ContentSuggestionTypeArticle:
63 return ItemTypeArticle; 68 return ItemTypeArticle;
64 case ContentSuggestionTypeEmpty: 69 case ContentSuggestionTypeEmpty:
65 return ItemTypeEmpty; 70 return ItemTypeEmpty;
71 case ContentSuggestionTypeReadingList:
72 return ItemTypeReadingList;
66 } 73 }
67 } 74 }
68 75
69 ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) { 76 ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) {
70 if (type == ItemTypeArticle) 77 if (type == ItemTypeArticle)
71 return ContentSuggestionTypeArticle; 78 return ContentSuggestionTypeArticle;
72 if (type == ItemTypeEmpty) 79 if (type == ItemTypeEmpty)
73 return ContentSuggestionTypeEmpty; 80 return ContentSuggestionTypeEmpty;
81 if (type == ItemTypeReadingList)
82 return ContentSuggestionTypeReadingList;
74 // Add new type here 83 // Add new type here
75 84
76 // Default type. 85 // Default type.
77 return ContentSuggestionTypeEmpty; 86 return ContentSuggestionTypeEmpty;
78 } 87 }
79 88
80 // Returns the section identifier corresponding to the section |info|. 89 // Returns the section identifier corresponding to the section |info|.
81 SectionIdentifier SectionIdentifierForInfo( 90 SectionIdentifier SectionIdentifierForInfo(
82 ContentSuggestionsSectionInformation* info) { 91 ContentSuggestionsSectionInformation* info) {
83 switch (info.sectionID) { 92 switch (info.sectionID) {
84 case ContentSuggestionsSectionBookmarks: 93 case ContentSuggestionsSectionBookmarks:
85 return SectionIdentifierBookmarks; 94 return SectionIdentifierBookmarks;
86 95
87 case ContentSuggestionsSectionArticles: 96 case ContentSuggestionsSectionArticles:
88 return SectionIdentifierArticles; 97 return SectionIdentifierArticles;
89 98
99 case ContentSuggestionsSectionReadingList:
100 return SectionIdentifierReadingList;
101
90 case ContentSuggestionsSectionUnknown: 102 case ContentSuggestionsSectionUnknown:
91 return SectionIdentifierDefault; 103 return SectionIdentifierDefault;
92 } 104 }
93 } 105 }
94 106
95 } // namespace 107 } // namespace
96 108
97 @interface ContentSuggestionsCollectionUpdater ()< 109 @interface ContentSuggestionsCollectionUpdater ()<
98 ContentSuggestionsArticleItemDelegate, 110 ContentSuggestionsArticleItemDelegate,
99 ContentSuggestionsDataSink> 111 ContentSuggestionsDataSink>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 articleItem.publisher = suggestion.publisher; 262 articleItem.publisher = suggestion.publisher;
251 articleItem.publishDate = suggestion.publishDate; 263 articleItem.publishDate = suggestion.publishDate;
252 264
253 articleItem.suggestionIdentifier = suggestion.suggestionIdentifier; 265 articleItem.suggestionIdentifier = suggestion.suggestionIdentifier;
254 266
255 NSIndexPath* addedIndexPath = [self addItem:articleItem 267 NSIndexPath* addedIndexPath = [self addItem:articleItem
256 toSectionWithIdentifier:sectionIdentifier]; 268 toSectionWithIdentifier:sectionIdentifier];
257 [indexPaths addObject:addedIndexPath]; 269 [indexPaths addObject:addedIndexPath];
258 break; 270 break;
259 } 271 }
272 case ContentSuggestionTypeReadingList: {
273 ContentSuggestionsReadingListItem* readingListItem =
274 [[ContentSuggestionsReadingListItem alloc]
275 initWithType:ItemTypeReadingList
276 url:suggestion.url
277 distillationState:ReadingListEntry::PROCESSING];
278 readingListItem.title = suggestion.title;
279 readingListItem.subtitle = suggestion.publisher;
280
281 readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier;
282
283 NSIndexPath* addedIndexPath = [self addItem:readingListItem
284 toSectionWithIdentifier:sectionIdentifier];
285 [indexPaths addObject:addedIndexPath];
286 break;
287 }
260 } 288 }
261 } 289 }
262 290
263 return indexPaths; 291 return indexPaths;
264 } 292 }
265 293
266 - (NSIndexSet*)addSectionsForSuggestionsToModel: 294 - (NSIndexSet*)addSectionsForSuggestionsToModel:
267 (NSArray<ContentSuggestion*>*)suggestions { 295 (NSArray<ContentSuggestion*>*)suggestions {
268 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; 296 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
269 297
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 CSCollectionViewModel* model = 456 CSCollectionViewModel* model =
429 self.collectionViewController.collectionViewModel; 457 self.collectionViewController.collectionViewModel;
430 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier]; 458 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
431 NSInteger itemNumber = [model numberOfItemsInSection:section]; 459 NSInteger itemNumber = [model numberOfItemsInSection:section];
432 [model addItem:item toSectionWithIdentifier:sectionIdentifier]; 460 [model addItem:item toSectionWithIdentifier:sectionIdentifier];
433 461
434 return [NSIndexPath indexPathForItem:itemNumber inSection:section]; 462 return [NSIndexPath indexPathForItem:itemNumber inSection:section];
435 } 463 }
436 464
437 @end 465 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698