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

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

Issue 2798563002: Add MostVistedSites to ContentSuggestionsMediator (Closed)
Patch Set: Reviewable 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/strings/sys_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 typedef NS_ENUM(NSInteger, ItemType) { 45 typedef NS_ENUM(NSInteger, ItemType) {
46 ItemTypeText = kItemTypeEnumZero, 46 ItemTypeText = kItemTypeEnumZero,
47 ItemTypeArticle, 47 ItemTypeArticle,
48 ItemTypeExpand, 48 ItemTypeExpand,
49 ItemTypeStack, 49 ItemTypeStack,
50 ItemTypeFavicon, 50 ItemTypeFavicon,
51 ItemTypeFooter, 51 ItemTypeFooter,
52 ItemTypeHeader, 52 ItemTypeHeader,
53 ItemTypeEmpty, 53 ItemTypeEmpty,
54 ItemTypeReadingList, 54 ItemTypeReadingList,
55 ItemTypeMostVisited,
55 }; 56 };
56 57
57 typedef NS_ENUM(NSInteger, SectionIdentifier) { 58 typedef NS_ENUM(NSInteger, SectionIdentifier) {
58 SectionIdentifierBookmarks = kSectionIdentifierEnumZero, 59 SectionIdentifierBookmarks = kSectionIdentifierEnumZero,
59 SectionIdentifierArticles, 60 SectionIdentifierArticles,
60 SectionIdentifierReadingList, 61 SectionIdentifierReadingList,
62 SectionIdentifierMostVisited,
61 SectionIdentifierDefault, 63 SectionIdentifierDefault,
62 }; 64 };
63 65
64 // Update ContentSuggestionTypeForItemType if you update this function. 66 // Update ContentSuggestionTypeForItemType if you update this function.
65 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) { 67 ItemType ItemTypeForContentSuggestionType(ContentSuggestionType type) {
66 switch (type) { 68 switch (type) {
67 case ContentSuggestionTypeArticle: 69 case ContentSuggestionTypeArticle:
68 return ItemTypeArticle; 70 return ItemTypeArticle;
69 case ContentSuggestionTypeEmpty: 71 case ContentSuggestionTypeEmpty:
70 return ItemTypeEmpty; 72 return ItemTypeEmpty;
71 case ContentSuggestionTypeReadingList: 73 case ContentSuggestionTypeReadingList:
72 return ItemTypeReadingList; 74 return ItemTypeReadingList;
75 case ContentSuggestionTypeMostVisited:
76 return ItemTypeMostVisited;
73 } 77 }
74 } 78 }
75 79
76 ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) { 80 ContentSuggestionType ContentSuggestionTypeForItemType(NSInteger type) {
77 if (type == ItemTypeArticle) 81 if (type == ItemTypeArticle)
78 return ContentSuggestionTypeArticle; 82 return ContentSuggestionTypeArticle;
79 if (type == ItemTypeEmpty) 83 if (type == ItemTypeEmpty)
80 return ContentSuggestionTypeEmpty; 84 return ContentSuggestionTypeEmpty;
81 if (type == ItemTypeReadingList) 85 if (type == ItemTypeReadingList)
82 return ContentSuggestionTypeReadingList; 86 return ContentSuggestionTypeReadingList;
87 if (type == ItemTypeMostVisited)
88 return ContentSuggestionTypeMostVisited;
83 // Add new type here 89 // Add new type here
84 90
85 // Default type. 91 // Default type.
86 return ContentSuggestionTypeEmpty; 92 return ContentSuggestionTypeEmpty;
87 } 93 }
88 94
89 // Returns the section identifier corresponding to the section |info|. 95 // Returns the section identifier corresponding to the section |info|.
90 SectionIdentifier SectionIdentifierForInfo( 96 SectionIdentifier SectionIdentifierForInfo(
91 ContentSuggestionsSectionInformation* info) { 97 ContentSuggestionsSectionInformation* info) {
92 switch (info.sectionID) { 98 switch (info.sectionID) {
93 case ContentSuggestionsSectionBookmarks: 99 case ContentSuggestionsSectionBookmarks:
94 return SectionIdentifierBookmarks; 100 return SectionIdentifierBookmarks;
95 101
96 case ContentSuggestionsSectionArticles: 102 case ContentSuggestionsSectionArticles:
97 return SectionIdentifierArticles; 103 return SectionIdentifierArticles;
98 104
99 case ContentSuggestionsSectionReadingList: 105 case ContentSuggestionsSectionReadingList:
100 return SectionIdentifierReadingList; 106 return SectionIdentifierReadingList;
101 107
108 case ContentSuggestionsSectionMostVisited:
109 return SectionIdentifierMostVisited;
110
102 case ContentSuggestionsSectionUnknown: 111 case ContentSuggestionsSectionUnknown:
103 return SectionIdentifierDefault; 112 return SectionIdentifierDefault;
104 } 113 }
105 } 114 }
106 115
107 } // namespace 116 } // namespace
108 117
109 @interface ContentSuggestionsCollectionUpdater ()< 118 @interface ContentSuggestionsCollectionUpdater ()<
110 ContentSuggestionsArticleItemDelegate, 119 ContentSuggestionsArticleItemDelegate,
111 ContentSuggestionsDataSink> 120 ContentSuggestionsDataSink>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 213 }
205 214
206 - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo { 215 - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo {
207 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo); 216 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
208 NSInteger section = [self.collectionViewController.collectionViewModel 217 NSInteger section = [self.collectionViewController.collectionViewModel
209 sectionIdentifierForSection:sectionIdentifier]; 218 sectionIdentifierForSection:sectionIdentifier];
210 219
211 [self.collectionViewController dismissSection:section]; 220 [self.collectionViewController dismissSection:section];
212 } 221 }
213 222
223 - (void)reloadSection:(ContentSuggestionsSectionInformation*)sectionInfo {
224 // TODO(crbug.com/707754): implement this method.
225 }
226
227 - (void)faviconAvailableForURL:(const GURL&)URL {
228 // TODO(crbug.com/707754): implement this method.
229 }
230
214 #pragma mark - Public methods 231 #pragma mark - Public methods
215 232
216 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { 233 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section {
217 NSNumber* identifier = @([self.collectionViewController.collectionViewModel 234 NSNumber* identifier = @([self.collectionViewController.collectionViewModel
218 sectionIdentifierForSection:section]); 235 sectionIdentifierForSection:section]);
219 ContentSuggestionsSectionInformation* sectionInformation = 236 ContentSuggestionsSectionInformation* sectionInformation =
220 self.sectionInfoBySectionIdentifier[identifier]; 237 self.sectionInfoBySectionIdentifier[identifier];
221 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom; 238 return sectionInformation.layout == ContentSuggestionsSectionLayoutCustom;
222 } 239 }
223 240
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 readingListItem.title = suggestion.title; 300 readingListItem.title = suggestion.title;
284 readingListItem.subtitle = suggestion.publisher; 301 readingListItem.subtitle = suggestion.publisher;
285 302
286 readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier; 303 readingListItem.suggestionIdentifier = suggestion.suggestionIdentifier;
287 304
288 NSIndexPath* addedIndexPath = [self addItem:readingListItem 305 NSIndexPath* addedIndexPath = [self addItem:readingListItem
289 toSectionWithIdentifier:sectionIdentifier]; 306 toSectionWithIdentifier:sectionIdentifier];
290 [indexPaths addObject:addedIndexPath]; 307 [indexPaths addObject:addedIndexPath];
291 break; 308 break;
292 } 309 }
310 case ContentSuggestionTypeMostVisited: {
311 // TODO(crbug.com/707754): Add the most visited item.
312 break;
313 }
293 } 314 }
294 } 315 }
295 316
296 return indexPaths; 317 return indexPaths;
297 } 318 }
298 319
299 - (NSIndexSet*)addSectionsForSuggestionsToModel: 320 - (NSIndexSet*)addSectionsForSuggestionsToModel:
300 (NSArray<ContentSuggestion*>*)suggestions { 321 (NSArray<ContentSuggestion*>*)suggestions {
301 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet]; 322 NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
302 323
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 [model sectionIdentifierForSection:sectionNumber]; 533 [model sectionIdentifierForSection:sectionNumber];
513 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) { 534 if ([model hasItem:item inSectionWithIdentifier:sectionIdentifier]) {
514 [self.collectionViewController 535 [self.collectionViewController
515 reconfigureCellsForItems:@[ item ] 536 reconfigureCellsForItems:@[ item ]
516 inSectionWithIdentifier:sectionIdentifier]; 537 inSectionWithIdentifier:sectionIdentifier];
517 } 538 }
518 } 539 }
519 } 540 }
520 541
521 @end 542 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698