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" |
11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art
icle_item.h" | 11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_art
icle_item.h" |
12 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_but
ton_item_actions.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_but
ton_item_actions.h" |
| 13 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_rea
ding_list_item.h" |
13 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item.h" |
14 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item_actions.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_sta
ck_item_actions.h" |
15 #import "ios/chrome/browser/ui/content_suggestions/cells/expandable_item.h" | 16 #import "ios/chrome/browser/ui/content_suggestions/cells/expandable_item.h" |
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" | 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" |
18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" | 19 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 22 #if !defined(__has_feature) || !__has_feature(objc_arc) |
22 #error "This file requires ARC support." | 23 #error "This file requires ARC support." |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 #pragma mark - UICollectionViewDelegate | 135 #pragma mark - UICollectionViewDelegate |
135 | 136 |
136 - (void)collectionView:(UICollectionView*)collectionView | 137 - (void)collectionView:(UICollectionView*)collectionView |
137 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 138 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
138 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 139 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
139 | 140 |
140 CollectionViewItem* item = | 141 CollectionViewItem* item = |
141 [self.collectionViewModel itemAtIndexPath:indexPath]; | 142 [self.collectionViewModel itemAtIndexPath:indexPath]; |
142 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { | 143 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { |
| 144 case ContentSuggestionTypeReadingList: |
| 145 [self openReadingListItem:item]; |
| 146 break; |
143 case ContentSuggestionTypeArticle: | 147 case ContentSuggestionTypeArticle: |
144 [self openArticle:item]; | 148 [self openArticle:item]; |
145 break; | 149 break; |
146 case ContentSuggestionTypeEmpty: | 150 case ContentSuggestionTypeEmpty: |
147 break; | 151 break; |
148 } | 152 } |
149 } | 153 } |
150 | 154 |
151 #pragma mark - ContentSuggestionsExpandableCellDelegate | 155 #pragma mark - ContentSuggestionsExpandableCellDelegate |
152 | 156 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 inSectionWithIdentifier:sectionIdentifier]; | 230 inSectionWithIdentifier:sectionIdentifier]; |
227 | 231 |
228 [UIView | 232 [UIView |
229 animateWithDuration:kAnimationDuration | 233 animateWithDuration:kAnimationDuration |
230 animations:^{ | 234 animations:^{ |
231 [self.collectionView.collectionViewLayout invalidateLayout]; | 235 [self.collectionView.collectionViewLayout invalidateLayout]; |
232 }]; | 236 }]; |
233 } | 237 } |
234 } | 238 } |
235 | 239 |
| 240 // Opens the Reading List entry associated with |item|. |item| must be a |
| 241 // ContentSuggestionsReadingListItem. |
| 242 - (void)openReadingListItem:(CollectionViewItem*)item { |
| 243 ContentSuggestionsReadingListItem* readingListItem = |
| 244 base::mac::ObjCCastStrict<ContentSuggestionsReadingListItem>(item); |
| 245 [self.suggestionCommandHandler openURL:readingListItem.url]; |
| 246 } |
| 247 |
| 248 // Opens the article associated with |item|. |item| must be a |
| 249 // ContentSuggestionsArticleItem. |
236 - (void)openArticle:(CollectionViewItem*)item { | 250 - (void)openArticle:(CollectionViewItem*)item { |
237 ContentSuggestionsArticleItem* article = | 251 ContentSuggestionsArticleItem* article = |
238 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); | 252 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); |
239 [self.suggestionCommandHandler openURL:article.articleURL]; | 253 [self.suggestionCommandHandler openURL:article.articleURL]; |
240 } | 254 } |
241 | 255 |
242 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { | 256 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { |
243 if (self.editor.editing || | 257 if (self.editor.editing || |
244 gestureRecognizer.state != UIGestureRecognizerStateBegan) { | 258 gestureRecognizer.state != UIGestureRecognizerStateBegan) { |
245 return; | 259 return; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { | 291 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { |
278 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) | 292 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) |
279 return; | 293 return; |
280 | 294 |
281 NSIndexPath* emptyItem = | 295 NSIndexPath* emptyItem = |
282 [self.collectionUpdater addEmptyItemForSection:section]; | 296 [self.collectionUpdater addEmptyItemForSection:section]; |
283 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; | 297 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; |
284 } | 298 } |
285 | 299 |
286 @end | 300 @end |
OLD | NEW |