| 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 23 matching lines...) Expand all Loading... |
| 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 || ![self.collectionViewModel hasItemAtIndexPath:indexPath]) { |
| 58 return; |
| 59 } |
| 60 |
| 61 [self.collectionView performBatchUpdates:^{ |
| 62 [self collectionView:self.collectionView |
| 63 willDeleteItemsAtIndexPaths:@[ indexPath ]]; |
| 64 |
| 65 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
| 66 } |
| 67 completion:nil]; |
| 68 } |
| 69 |
| 54 #pragma mark - UIViewController | 70 #pragma mark - UIViewController |
| 55 | 71 |
| 56 - (void)viewDidLoad { | 72 - (void)viewDidLoad { |
| 57 [super viewDidLoad]; | 73 [super viewDidLoad]; |
| 58 | 74 |
| 59 _collectionUpdater.collectionViewController = self; | 75 _collectionUpdater.collectionViewController = self; |
| 60 | 76 |
| 61 self.collectionView.delegate = self; | 77 self.collectionView.delegate = self; |
| 62 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 78 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 63 | 79 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 206 |
| 191 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != | 207 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != |
| 192 ContentSuggestionTypeArticle) { | 208 ContentSuggestionTypeArticle) { |
| 193 // Only trigger context menu on articles. | 209 // Only trigger context menu on articles. |
| 194 return; | 210 return; |
| 195 } | 211 } |
| 196 | 212 |
| 197 ContentSuggestionsArticleItem* articleItem = | 213 ContentSuggestionsArticleItem* articleItem = |
| 198 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); | 214 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); |
| 199 | 215 |
| 200 [self.suggestionCommandHandler displayContextMenuForArticle:articleItem | 216 [self.suggestionCommandHandler |
| 201 atPoint:touchLocation]; | 217 displayContextMenuForArticle:articleItem |
| 218 atPoint:touchLocation |
| 219 atIndexPath:touchedItemIndexPath]; |
| 202 } | 220 } |
| 203 | 221 |
| 204 @end | 222 @end |
| OLD | NEW |