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

Side by Side Diff: ios/chrome/browser/ui/collection_view/collection_view_model.mm

Issue 2761263003: Allow CollectionViewModel/Controller queries without SectionIdentifier (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « ios/chrome/browser/ui/collection_view/collection_view_model.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/collection_view/collection_view_model.h" 5 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
9 9
10 #if !defined(__has_feature) || !__has_feature(objc_arc) 10 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 inSectionWithIdentifier:(NSInteger)sectionIdentifier { 260 inSectionWithIdentifier:(NSInteger)sectionIdentifier {
261 NSArray* itemsInSection = 261 NSArray* itemsInSection =
262 [self itemsInSectionWithIdentifier:sectionIdentifier]; 262 [self itemsInSectionWithIdentifier:sectionIdentifier];
263 263
264 NSInteger section = [self sectionForSectionIdentifier:sectionIdentifier]; 264 NSInteger section = [self sectionForSectionIdentifier:sectionIdentifier];
265 NSInteger itemIndex = [itemsInSection indexOfObject:item]; 265 NSInteger itemIndex = [itemsInSection indexOfObject:item];
266 DCHECK_NE(NSNotFound, itemIndex); 266 DCHECK_NE(NSNotFound, itemIndex);
267 return [NSIndexPath indexPathForItem:itemIndex inSection:section]; 267 return [NSIndexPath indexPathForItem:itemIndex inSection:section];
268 } 268 }
269 269
270 - (BOOL)hasItem:(CollectionViewItem*)item {
271 for (SectionItems* sectionItems in _sections) {
272 if ([sectionItems indexOfObject:item] != NSNotFound)
273 return YES;
274 }
275 return NO;
276 }
277
278 - (NSIndexPath*)indexPathForItem:(CollectionViewItem*)item {
279 for (NSUInteger section = 0; section < [_sections count]; section++) {
280 NSInteger itemIndex = [_sections[section] indexOfObject:item];
281 if (itemIndex != NSNotFound) {
282 return [NSIndexPath indexPathForItem:itemIndex inSection:section];
283 }
284 }
285 DCHECK(NO);
lpromero 2017/03/22 14:04:22 Use NOTREACHED.
286 return nil;
287 }
288
270 #pragma mark UICollectionView data sourcing 289 #pragma mark UICollectionView data sourcing
271 290
272 - (NSInteger)numberOfSections { 291 - (NSInteger)numberOfSections {
273 return [_sections count]; 292 return [_sections count];
274 } 293 }
275 294
276 - (NSInteger)numberOfItemsInSection:(NSInteger)section { 295 - (NSInteger)numberOfItemsInSection:(NSInteger)section {
277 DCHECK_LT(static_cast<NSUInteger>(section), [_sections count]); 296 DCHECK_LT(static_cast<NSUInteger>(section), [_sections count]);
278 SectionItems* items = [_sections objectAtIndex:section]; 297 SectionItems* items = [_sections objectAtIndex:section];
279 return items.count; 298 return items.count;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 341 }
323 if (sectionItem.type == item.type) { 342 if (sectionItem.type == item.type) {
324 indexInItemType++; 343 indexInItemType++;
325 } 344 }
326 } 345 }
327 DCHECK(found); 346 DCHECK(found);
328 return indexInItemType; 347 return indexInItemType;
329 } 348 }
330 349
331 @end 350 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/collection_view/collection_view_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698