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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 - (void)dismissEntryAtIndexPath:(NSIndexPath*)indexPath { | 58 - (void)dismissEntryAtIndexPath:(NSIndexPath*)indexPath { |
59 if (!indexPath || ![self.collectionViewModel hasItemAtIndexPath:indexPath]) { | 59 if (!indexPath || ![self.collectionViewModel hasItemAtIndexPath:indexPath]) { |
60 return; | 60 return; |
61 } | 61 } |
62 | 62 |
63 [self.collectionView performBatchUpdates:^{ | 63 [self.collectionView performBatchUpdates:^{ |
64 [self collectionView:self.collectionView | 64 [self collectionView:self.collectionView |
65 willDeleteItemsAtIndexPaths:@[ indexPath ]]; | 65 willDeleteItemsAtIndexPaths:@[ indexPath ]]; |
66 | 66 |
67 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; | 67 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
68 | |
69 // Check if the section is now empty. | |
70 [self checkEmptySection:indexPath.section]; | |
lpromero
2017/03/23 10:54:37
Can you update the name of the method, as it does
gambard
2017/03/23 15:25:49
Done.
| |
68 } | 71 } |
69 completion:^(BOOL) { | 72 completion:^(BOOL) { |
70 // The context menu could be displayed for the deleted entry. | 73 // The context menu could be displayed for the deleted entry. |
71 [self.suggestionCommandHandler dismissContextMenu]; | 74 [self.suggestionCommandHandler dismissContextMenu]; |
72 }]; | 75 }]; |
73 } | 76 } |
74 | 77 |
75 - (void)dismissSection:(NSInteger)section { | 78 - (void)dismissSection:(NSInteger)section { |
76 if (section >= [self numberOfSectionsInCollectionView:self.collectionView]) { | 79 if (section >= [self numberOfSectionsInCollectionView:self.collectionView]) { |
77 return; | 80 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 - (void)collectionView:(UICollectionView*)collectionView | 136 - (void)collectionView:(UICollectionView*)collectionView |
134 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 137 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
135 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 138 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
136 | 139 |
137 CollectionViewItem* item = | 140 CollectionViewItem* item = |
138 [self.collectionViewModel itemAtIndexPath:indexPath]; | 141 [self.collectionViewModel itemAtIndexPath:indexPath]; |
139 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { | 142 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { |
140 case ContentSuggestionTypeArticle: | 143 case ContentSuggestionTypeArticle: |
141 [self openArticle:item]; | 144 [self openArticle:item]; |
142 break; | 145 break; |
146 case ContentSuggestionTypeEmpty: | |
147 break; | |
143 } | 148 } |
144 } | 149 } |
145 | 150 |
146 #pragma mark - ContentSuggestionsExpandableCellDelegate | 151 #pragma mark - ContentSuggestionsExpandableCellDelegate |
147 | 152 |
148 - (void)collapseCell:(UICollectionViewCell*)cell { | 153 - (void)collapseCell:(UICollectionViewCell*)cell { |
149 [self expand:NO cell:cell]; | 154 [self expand:NO cell:cell]; |
150 } | 155 } |
151 | 156 |
152 - (void)expandCell:(UICollectionViewCell*)cell { | 157 - (void)expandCell:(UICollectionViewCell*)cell { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 | 265 |
261 ContentSuggestionsArticleItem* articleItem = | 266 ContentSuggestionsArticleItem* articleItem = |
262 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); | 267 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); |
263 | 268 |
264 [self.suggestionCommandHandler | 269 [self.suggestionCommandHandler |
265 displayContextMenuForArticle:articleItem | 270 displayContextMenuForArticle:articleItem |
266 atPoint:touchLocation | 271 atPoint:touchLocation |
267 atIndexPath:touchedItemIndexPath]; | 272 atIndexPath:touchedItemIndexPath]; |
268 } | 273 } |
269 | 274 |
275 // Checks if the |section| is empty and add an empty element if it is the case. | |
276 // Must be called from inside a performBatchUpdates: block. | |
277 - (void)checkEmptySection:(NSInteger)section { | |
278 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) | |
279 return; | |
280 [self.collectionUpdater addEmptyItemForSection:section]; | |
281 NSIndexPath* emptyItem = [NSIndexPath indexPathForItem:0 inSection:section]; | |
lpromero
2017/03/23 10:54:37
Use the return value of –addEmptyItemForSection: o
gambard
2017/03/23 15:25:49
Done.
| |
282 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; | |
283 } | |
284 | |
270 @end | 285 @end |
OLD | NEW |