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/cells/collection_view_text_cell.h
" |
10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 11 #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" | 12 #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_rea
ding_list_item.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/content_suggestion.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" |
14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" |
15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" | 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" |
| 17 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 18 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
16 #include "url/gurl.h" | 19 #include "url/gurl.h" |
17 | 20 |
18 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
19 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
20 #endif | 23 #endif |
21 | 24 |
22 @interface ContentSuggestionsViewController () | 25 @interface ContentSuggestionsViewController () |
23 | 26 |
24 @property(nonatomic, strong) | 27 @property(nonatomic, strong) |
25 ContentSuggestionsCollectionUpdater* collectionUpdater; | 28 ContentSuggestionsCollectionUpdater* collectionUpdater; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 116 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
114 | 117 |
115 UILongPressGestureRecognizer* longPressRecognizer = | 118 UILongPressGestureRecognizer* longPressRecognizer = |
116 [[UILongPressGestureRecognizer alloc] | 119 [[UILongPressGestureRecognizer alloc] |
117 initWithTarget:self | 120 initWithTarget:self |
118 action:@selector(handleLongPress:)]; | 121 action:@selector(handleLongPress:)]; |
119 longPressRecognizer.numberOfTouchesRequired = 1; | 122 longPressRecognizer.numberOfTouchesRequired = 1; |
120 [self.collectionView addGestureRecognizer:longPressRecognizer]; | 123 [self.collectionView addGestureRecognizer:longPressRecognizer]; |
121 } | 124 } |
122 | 125 |
| 126 #pragma mark - UICollectionViewDataSource |
| 127 |
| 128 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 129 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 130 UICollectionViewCell* cell = |
| 131 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 132 |
| 133 if ([cell isKindOfClass:[CollectionViewTextCell class]]) { |
| 134 CollectionViewTextCell* textCell = |
| 135 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell); |
| 136 textCell.textLabel.font = [MDCTypography body2Font]; |
| 137 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 138 textCell.detailTextLabel.font = [MDCTypography body1Font]; |
| 139 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 140 } |
| 141 return cell; |
| 142 } |
| 143 |
123 #pragma mark - UICollectionViewDelegate | 144 #pragma mark - UICollectionViewDelegate |
124 | 145 |
125 - (void)collectionView:(UICollectionView*)collectionView | 146 - (void)collectionView:(UICollectionView*)collectionView |
126 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 147 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
127 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 148 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
128 | 149 |
129 CollectionViewItem* item = | 150 CollectionViewItem* item = |
130 [self.collectionViewModel itemAtIndexPath:indexPath]; | 151 [self.collectionViewModel itemAtIndexPath:indexPath]; |
131 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { | 152 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { |
132 case ContentSuggestionTypeReadingList: | 153 case ContentSuggestionTypeReadingList: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { | 259 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { |
239 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) | 260 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) |
240 return; | 261 return; |
241 | 262 |
242 NSIndexPath* emptyItem = | 263 NSIndexPath* emptyItem = |
243 [self.collectionUpdater addEmptyItemForSection:section]; | 264 [self.collectionUpdater addEmptyItemForSection:section]; |
244 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; | 265 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; |
245 } | 266 } |
246 | 267 |
247 @end | 268 @end |
OLD | NEW |