OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 // Expand or collapse the |cell|, if it is a ContentSuggestionsExpandableCell, | 33 // Expand or collapse the |cell|, if it is a ContentSuggestionsExpandableCell, |
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 @dynamic collectionViewModel; |
43 | 44 |
44 #pragma mark - Public | 45 #pragma mark - Public |
45 | 46 |
46 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style | 47 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style |
47 dataSource:(id<ContentSuggestionsDataSource>)dataSource { | 48 dataSource:(id<ContentSuggestionsDataSource>)dataSource { |
48 self = [super initWithStyle:style]; | 49 self = [super initWithStyle:style]; |
49 if (self) { | 50 if (self) { |
50 _collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] | 51 _collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] |
51 initWithDataSource:dataSource]; | 52 initWithDataSource:dataSource]; |
52 } | 53 } |
53 return self; | 54 return self; |
54 } | 55 } |
55 | 56 |
56 - (void)dismissEntryAtIndexPath:(NSIndexPath*)indexPath { | 57 - (void)dismissEntryAtIndexPath:(NSIndexPath*)indexPath { |
57 if (!indexPath || ![self.collectionViewModel hasItemAtIndexPath:indexPath]) { | 58 if (!indexPath || ![self.collectionViewModel hasItemAtIndexPath:indexPath]) { |
58 return; | 59 return; |
59 } | 60 } |
60 | 61 |
61 [self.collectionView performBatchUpdates:^{ | 62 [self.collectionView performBatchUpdates:^{ |
62 [self collectionView:self.collectionView | 63 [self collectionView:self.collectionView |
63 willDeleteItemsAtIndexPaths:@[ indexPath ]]; | 64 willDeleteItemsAtIndexPaths:@[ indexPath ]]; |
64 | 65 |
65 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; | 66 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
66 } | 67 } |
67 completion:nil]; | 68 completion:^(BOOL) { |
| 69 // The context menu could be displayed for the delete entry. |
| 70 [self.suggestionCommandHandler dismissContextMenu]; |
| 71 }]; |
68 } | 72 } |
69 | 73 |
70 #pragma mark - UIViewController | 74 #pragma mark - UIViewController |
71 | 75 |
72 - (void)viewDidLoad { | 76 - (void)viewDidLoad { |
73 [super viewDidLoad]; | 77 [super viewDidLoad]; |
74 | 78 |
75 _collectionUpdater.collectionViewController = self; | 79 _collectionUpdater.collectionViewController = self; |
76 | 80 |
77 self.collectionView.delegate = self; | 81 self.collectionView.delegate = self; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 ContentSuggestionsArticleItem* articleItem = | 217 ContentSuggestionsArticleItem* articleItem = |
214 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); | 218 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); |
215 | 219 |
216 [self.suggestionCommandHandler | 220 [self.suggestionCommandHandler |
217 displayContextMenuForArticle:articleItem | 221 displayContextMenuForArticle:articleItem |
218 atPoint:touchLocation | 222 atPoint:touchLocation |
219 atIndexPath:touchedItemIndexPath]; | 223 atIndexPath:touchedItemIndexPath]; |
220 } | 224 } |
221 | 225 |
222 @end | 226 @end |
OLD | NEW |