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

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

Issue 2877513003: ContentSuggestionsDataSource returns CollectionViewItem (Closed)
Patch Set: Address comments Created 3 years, 7 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_view_cont roller.h" 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 8 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_ite m.h" 11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_ite m.h"
12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h" 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h"
14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h" 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h"
15 #include "url/gurl.h" 14 #include "url/gurl.h"
16 15
17 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
18 #error "This file requires ARC support." 17 #error "This file requires ARC support."
19 #endif 18 #endif
20 19
20 namespace {
21 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
22 }
23
21 @interface ContentSuggestionsViewController () 24 @interface ContentSuggestionsViewController ()
22 25
23 @property(nonatomic, strong) 26 @property(nonatomic, strong)
24 ContentSuggestionsCollectionUpdater* collectionUpdater; 27 ContentSuggestionsCollectionUpdater* collectionUpdater;
25 28
26 @end 29 @end
27 30
28 @implementation ContentSuggestionsViewController 31 @implementation ContentSuggestionsViewController
29 32
30 @synthesize suggestionCommandHandler = _suggestionCommandHandler; 33 @synthesize suggestionCommandHandler = _suggestionCommandHandler;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 [self.collectionView performBatchUpdates:^{ 77 [self.collectionView performBatchUpdates:^{
75 [self.collectionViewModel removeSectionWithIdentifier:sectionIdentifier]; 78 [self.collectionViewModel removeSectionWithIdentifier:sectionIdentifier];
76 [self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:section]]; 79 [self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:section]];
77 } 80 }
78 completion:^(BOOL) { 81 completion:^(BOOL) {
79 // The context menu could be displayed for the deleted entries. 82 // The context menu could be displayed for the deleted entries.
80 [self.suggestionCommandHandler dismissContextMenu]; 83 [self.suggestionCommandHandler dismissContextMenu];
81 }]; 84 }];
82 } 85 }
83 86
84 - (void)addSuggestions:(NSArray<ContentSuggestion*>*)suggestions { 87 - (void)addSuggestions:(NSArray<CSCollectionViewItem*>*)suggestions
88 toSectionInfo:(ContentSuggestionsSectionInformation*)sectionInfo {
85 if (suggestions.count == 0) { 89 if (suggestions.count == 0) {
86 return; 90 return;
87 } 91 }
88 92
89 [self.collectionView performBatchUpdates:^{ 93 [self.collectionView performBatchUpdates:^{
90 NSIndexSet* addedSections = 94 NSIndexSet* addedSections = [self.collectionUpdater
91 [self.collectionUpdater addSectionsForSuggestionsToModel:suggestions]; 95 addSectionsForSectionInfoToModel:@[ sectionInfo ]];
92 [self.collectionView insertSections:addedSections]; 96 [self.collectionView insertSections:addedSections];
93 } 97 }
94 completion:nil]; 98 completion:nil];
95 99
96 [self.collectionView performBatchUpdates:^{ 100 [self.collectionView performBatchUpdates:^{
97 NSArray<NSIndexPath*>* addedItems = 101 NSArray<NSIndexPath*>* addedItems =
98 [self.collectionUpdater addSuggestionsToModel:suggestions]; 102 [self.collectionUpdater addSuggestionsToModel:suggestions
103 withSectionInfo:sectionInfo];
99 [self.collectionView insertItemsAtIndexPaths:addedItems]; 104 [self.collectionView insertItemsAtIndexPaths:addedItems];
100 } 105 }
101 completion:nil]; 106 completion:nil];
102 } 107 }
103 108
104 #pragma mark - UIViewController 109 #pragma mark - UIViewController
105 110
106 - (void)viewDidLoad { 111 - (void)viewDidLoad {
107 [super viewDidLoad]; 112 [super viewDidLoad];
108 113
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { 232 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section {
228 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) 233 if ([self.collectionViewModel numberOfItemsInSection:section] > 0)
229 return; 234 return;
230 235
231 NSIndexPath* emptyItem = 236 NSIndexPath* emptyItem =
232 [self.collectionUpdater addEmptyItemForSection:section]; 237 [self.collectionUpdater addEmptyItemForSection:section];
233 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; 238 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]];
234 } 239 }
235 240
236 @end 241 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698