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

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

Issue 2923973002: Reload the Most Visited section when it changes (Closed)
Patch Set: Add comment Created 3 years, 6 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo { 215 - (void)clearSection:(ContentSuggestionsSectionInformation*)sectionInfo {
216 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo); 216 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
217 NSInteger section = [self.collectionViewController.collectionViewModel 217 NSInteger section = [self.collectionViewController.collectionViewModel
218 sectionIdentifierForSection:sectionIdentifier]; 218 sectionIdentifierForSection:sectionIdentifier];
219 219
220 [self.collectionViewController dismissSection:section]; 220 [self.collectionViewController dismissSection:section];
221 } 221 }
222 222
223 - (void)reloadSection:(ContentSuggestionsSectionInformation*)sectionInfo { 223 - (void)reloadSection:(ContentSuggestionsSectionInformation*)sectionInfo {
224 // TODO(crbug.com/707754): implement this method. 224 CSCollectionViewModel* model =
225 self.collectionViewController.collectionViewModel;
226 SectionIdentifier sectionIdentifier = SectionIdentifierForInfo(sectionInfo);
227
228 if (![model hasSectionForSectionIdentifier:sectionIdentifier]) {
229 [self.collectionViewController
230 addSuggestions:[self.dataSource itemsForSectionInfo:sectionInfo]
231 toSectionInfo:sectionInfo];
232 return;
233 }
234
235 NSInteger section = [model sectionForSectionIdentifier:sectionIdentifier];
236
237 NSMutableArray* oldItems = [NSMutableArray array];
238 NSInteger numberOfItems = [model numberOfItemsInSection:section];
239 for (NSInteger i = 0; i < numberOfItems; i++) {
240 [oldItems addObject:[NSIndexPath indexPathForItem:i inSection:section]];
241 }
242 [self.collectionViewController
243 collectionView:self.collectionViewController.collectionView
244 willDeleteItemsAtIndexPaths:oldItems];
245
246 [self addSuggestionsToModel:[self.dataSource itemsForSectionInfo:sectionInfo]
247 withSectionInfo:sectionInfo];
248
249 [self.collectionViewController.collectionView
250 reloadSections:[NSIndexSet indexSetWithIndex:section]];
225 } 251 }
226 252
227 - (void)faviconAvailableForItem:(CollectionViewItem<SuggestedContent>*)item { 253 - (void)faviconAvailableForItem:(CollectionViewItem<SuggestedContent>*)item {
228 if ([self.collectionViewController.collectionViewModel hasItem:item]) { 254 if ([self.collectionViewController.collectionViewModel hasItem:item]) {
229 [self fetchFaviconForItem:item]; 255 [self fetchFaviconForItem:item];
230 } 256 }
231 } 257 }
232 258
233 #pragma mark - Public methods 259 #pragma mark - Public methods
234 260
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 615 }
590 616
591 // Returns the maximum number of Most Visited tiles to be displayed in the 617 // Returns the maximum number of Most Visited tiles to be displayed in the
592 // collection. 618 // collection.
593 - (NSInteger)mostVisitedPlaceCount { 619 - (NSInteger)mostVisitedPlaceCount {
594 return content_suggestions::numberOfTilesForWidth(self.collectionWidth) * 620 return content_suggestions::numberOfTilesForWidth(self.collectionWidth) *
595 kNumberOfMostVisitedLines; 621 kNumberOfMostVisitedLines;
596 } 622 }
597 623
598 @end 624 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698