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

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

Issue 2736653002: Suggested Articles can be dismissed (Closed)
Patch Set: Cleanup Created 3 years, 9 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"
(...skipping 23 matching lines...) Expand all
34 // according to |expand|. 34 // according to |expand|.
35 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell; 35 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell;
36 36
37 @end 37 @end
38 38
39 @implementation ContentSuggestionsViewController 39 @implementation ContentSuggestionsViewController
40 40
41 @synthesize suggestionCommandHandler = _suggestionCommandHandler; 41 @synthesize suggestionCommandHandler = _suggestionCommandHandler;
42 @synthesize collectionUpdater = _collectionUpdater; 42 @synthesize collectionUpdater = _collectionUpdater;
43 43
44 #pragma mark - Public
45
44 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style 46 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style
45 dataSource:(id<ContentSuggestionsDataSource>)dataSource { 47 dataSource:(id<ContentSuggestionsDataSource>)dataSource {
46 self = [super initWithStyle:style]; 48 self = [super initWithStyle:style];
47 if (self) { 49 if (self) {
48 _collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] 50 _collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc]
49 initWithDataSource:dataSource]; 51 initWithDataSource:dataSource];
50 } 52 }
51 return self; 53 return self;
52 } 54 }
53 55
56 - (void)dismissEntryAtIndexPath:(NSIndexPath*)indexPath {
57 if (!indexPath)
58 return;
59
60 [self.collectionView performBatchUpdates:^{
61 [self collectionView:self.collectionView
62 willDeleteItemsAtIndexPaths:@[ indexPath ]];
lpromero 2017/03/06 10:29:00 Why do you call this? So that the item is removed
gambard 2017/03/06 12:16:00 I use performBatchUpdates defensively because the
lpromero 2017/03/06 13:02:30 Can -dismissEntryAtIndexPath: be called several ti
gambard 2017/03/06 17:25:33 For now it should not be called in the same turn o
63
64 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]];
65 }
66 completion:nil];
67 }
68
54 #pragma mark - UIViewController 69 #pragma mark - UIViewController
55 70
56 - (void)viewDidLoad { 71 - (void)viewDidLoad {
57 [super viewDidLoad]; 72 [super viewDidLoad];
58 73
59 _collectionUpdater.collectionViewController = self; 74 _collectionUpdater.collectionViewController = self;
60 75
61 self.collectionView.delegate = self; 76 self.collectionView.delegate = self;
62 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 77 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
63 78
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 205
191 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != 206 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] !=
192 ContentSuggestionTypeArticle) { 207 ContentSuggestionTypeArticle) {
193 // Only trigger context menu on articles. 208 // Only trigger context menu on articles.
194 return; 209 return;
195 } 210 }
196 211
197 ContentSuggestionsArticleItem* articleItem = 212 ContentSuggestionsArticleItem* articleItem =
198 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); 213 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem);
199 214
200 [self.suggestionCommandHandler displayContextMenuForArticle:articleItem 215 [self.suggestionCommandHandler
201 atPoint:touchLocation]; 216 displayContextMenuForArticle:articleItem
217 atPoint:touchLocation
218 atIndexPath:touchedItemIndexPath];
202 } 219 }
203 220
204 @end 221 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698