Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm

Issue 2865183003: Use the same design for all suggestions (Closed)
Patch Set: Address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_ite m.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/content_suggestion.h" 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h" 13 #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" 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h"
16 #include "url/gurl.h" 15 #include "url/gurl.h"
17 16
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 18 #error "This file requires ARC support."
20 #endif 19 #endif
21 20
22 @interface ContentSuggestionsViewController () 21 @interface ContentSuggestionsViewController ()
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 #pragma mark - UICollectionViewDelegate 122 #pragma mark - UICollectionViewDelegate
124 123
125 - (void)collectionView:(UICollectionView*)collectionView 124 - (void)collectionView:(UICollectionView*)collectionView
126 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 125 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
127 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 126 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
128 127
129 CollectionViewItem* item = 128 CollectionViewItem* item =
130 [self.collectionViewModel itemAtIndexPath:indexPath]; 129 [self.collectionViewModel itemAtIndexPath:indexPath];
131 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { 130 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) {
132 case ContentSuggestionTypeReadingList: 131 case ContentSuggestionTypeReadingList:
133 [self openReadingListItem:item];
134 break;
135 case ContentSuggestionTypeArticle: 132 case ContentSuggestionTypeArticle:
136 [self openArticle:item]; 133 [self openSuggestion:item];
137 break; 134 break;
138 case ContentSuggestionTypeMostVisited: 135 case ContentSuggestionTypeMostVisited:
139 // TODO(crbug.com/707754): Open the most visited site. 136 // TODO(crbug.com/707754): Open the most visited site.
140 break; 137 break;
141 case ContentSuggestionTypeEmpty: 138 case ContentSuggestionTypeEmpty:
142 break; 139 break;
143 } 140 }
144 } 141 }
145 142
146 #pragma mark - MDCCollectionViewStylingDelegate 143 #pragma mark - MDCCollectionViewStylingDelegate
(...skipping 30 matching lines...) Expand all
177 insetForSectionAtIndex:indexPath.section]; 174 insetForSectionAtIndex:indexPath.section];
178 175
179 return [MDCCollectionViewCell 176 return [MDCCollectionViewCell
180 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) - 177 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
181 inset.left - inset.right 178 inset.left - inset.right
182 forItem:item]; 179 forItem:item];
183 } 180 }
184 181
185 #pragma mark - Private 182 #pragma mark - Private
186 183
187 // Opens the Reading List entry associated with |item|. |item| must be a
188 // ContentSuggestionsReadingListItem.
189 - (void)openReadingListItem:(CollectionViewItem*)item {
190 ContentSuggestionsReadingListItem* readingListItem =
191 base::mac::ObjCCastStrict<ContentSuggestionsReadingListItem>(item);
192 [self.suggestionCommandHandler openURL:readingListItem.url];
193 }
194
195 // Opens the article associated with |item|. |item| must be a 184 // Opens the article associated with |item|. |item| must be a
196 // ContentSuggestionsArticleItem. 185 // ContentSuggestionsItem.
197 - (void)openArticle:(CollectionViewItem*)item { 186 - (void)openSuggestion:(CollectionViewItem*)item {
198 ContentSuggestionsArticleItem* article = 187 ContentSuggestionsItem* suggestion =
199 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); 188 base::mac::ObjCCastStrict<ContentSuggestionsItem>(item);
200 [self.suggestionCommandHandler openURL:article.articleURL]; 189 [self.suggestionCommandHandler openURL:suggestion.URL];
201 } 190 }
202 191
203 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { 192 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer {
204 if (self.editor.editing || 193 if (self.editor.editing ||
205 gestureRecognizer.state != UIGestureRecognizerStateBegan) { 194 gestureRecognizer.state != UIGestureRecognizerStateBegan) {
206 return; 195 return;
207 } 196 }
208 197
209 CGPoint touchLocation = 198 CGPoint touchLocation =
210 [gestureRecognizer locationOfTouch:0 inView:self.collectionView]; 199 [gestureRecognizer locationOfTouch:0 inView:self.collectionView];
211 NSIndexPath* touchedItemIndexPath = 200 NSIndexPath* touchedItemIndexPath =
212 [self.collectionView indexPathForItemAtPoint:touchLocation]; 201 [self.collectionView indexPathForItemAtPoint:touchLocation];
213 if (!touchedItemIndexPath || 202 if (!touchedItemIndexPath ||
214 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { 203 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) {
215 // Make sure there is an item at this position. 204 // Make sure there is an item at this position.
216 return; 205 return;
217 } 206 }
218 CollectionViewItem* touchedItem = 207 CollectionViewItem* touchedItem =
219 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; 208 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath];
220 209
221 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != 210 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] !=
222 ContentSuggestionTypeArticle) { 211 ContentSuggestionTypeArticle) {
223 // Only trigger context menu on articles. 212 // Only trigger context menu on articles.
224 return; 213 return;
225 } 214 }
226 215
227 ContentSuggestionsArticleItem* articleItem = 216 ContentSuggestionsItem* suggestionItem =
228 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); 217 base::mac::ObjCCastStrict<ContentSuggestionsItem>(touchedItem);
229 218
230 [self.suggestionCommandHandler 219 [self.suggestionCommandHandler
231 displayContextMenuForArticle:articleItem 220 displayContextMenuForArticle:suggestionItem
232 atPoint:touchLocation 221 atPoint:touchLocation
233 atIndexPath:touchedItemIndexPath]; 222 atIndexPath:touchedItemIndexPath];
234 } 223 }
235 224
236 // Checks if the |section| is empty and add an empty element if it is the case. 225 // Checks if the |section| is empty and add an empty element if it is the case.
237 // Must be called from inside a performBatchUpdates: block. 226 // Must be called from inside a performBatchUpdates: block.
238 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { 227 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section {
239 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) 228 if ([self.collectionViewModel numberOfItemsInSection:section] > 0)
240 return; 229 return;
241 230
242 NSIndexPath* emptyItem = 231 NSIndexPath* emptyItem =
243 [self.collectionUpdater addEmptyItemForSection:section]; 232 [self.collectionUpdater addEmptyItemForSection:section];
244 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; 233 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]];
245 } 234 }
246 235
247 @end 236 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698