| 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/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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 249 } |
| 250 | 250 |
| 251 #pragma mark Query index paths from items | 251 #pragma mark Query index paths from items |
| 252 | 252 |
| 253 - (BOOL)hasItem:(CollectionViewItem*)item | 253 - (BOOL)hasItem:(CollectionViewItem*)item |
| 254 inSectionWithIdentifier:(NSInteger)sectionIdentifier { | 254 inSectionWithIdentifier:(NSInteger)sectionIdentifier { |
| 255 return [[self itemsInSectionWithIdentifier:sectionIdentifier] | 255 return [[self itemsInSectionWithIdentifier:sectionIdentifier] |
| 256 indexOfObject:item] != NSNotFound; | 256 indexOfObject:item] != NSNotFound; |
| 257 } | 257 } |
| 258 | 258 |
| 259 - (NSIndexPath*)indexPathForItem:(CollectionViewItem*)item | 259 - (BOOL)hasItem:(CollectionViewItem*)item { |
| 260 inSectionWithIdentifier:(NSInteger)sectionIdentifier { | 260 for (NSNumber* section in _sectionIdentifiers) { |
| 261 NSArray* itemsInSection = | 261 if ([self hasItem:item inSectionWithIdentifier:[section integerValue]]) |
| 262 [self itemsInSectionWithIdentifier:sectionIdentifier]; | 262 return YES; |
| 263 } |
| 264 return NO; |
| 265 } |
| 263 | 266 |
| 264 NSInteger section = [self sectionForSectionIdentifier:sectionIdentifier]; | 267 - (NSIndexPath*)indexPathForItem:(CollectionViewItem*)item { |
| 265 NSInteger itemIndex = [itemsInSection indexOfObject:item]; | 268 for (NSUInteger section = 0; section < _sections.count; section++) { |
| 266 DCHECK_NE(NSNotFound, itemIndex); | 269 NSInteger itemIndex = [_sections[section] indexOfObject:item]; |
| 267 return [NSIndexPath indexPathForItem:itemIndex inSection:section]; | 270 if (itemIndex != NSNotFound) { |
| 271 return [NSIndexPath indexPathForItem:itemIndex inSection:section]; |
| 272 } |
| 273 } |
| 274 NOTREACHED(); |
| 275 return nil; |
| 268 } | 276 } |
| 269 | 277 |
| 270 #pragma mark UICollectionView data sourcing | 278 #pragma mark UICollectionView data sourcing |
| 271 | 279 |
| 272 - (NSInteger)numberOfSections { | 280 - (NSInteger)numberOfSections { |
| 273 return [_sections count]; | 281 return [_sections count]; |
| 274 } | 282 } |
| 275 | 283 |
| 276 - (NSInteger)numberOfItemsInSection:(NSInteger)section { | 284 - (NSInteger)numberOfItemsInSection:(NSInteger)section { |
| 277 DCHECK_LT(static_cast<NSUInteger>(section), [_sections count]); | 285 DCHECK_LT(static_cast<NSUInteger>(section), [_sections count]); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 330 } |
| 323 if (sectionItem.type == item.type) { | 331 if (sectionItem.type == item.type) { |
| 324 indexInItemType++; | 332 indexInItemType++; |
| 325 } | 333 } |
| 326 } | 334 } |
| 327 DCHECK(found); | 335 DCHECK(found); |
| 328 return indexInItemType; | 336 return indexInItemType; |
| 329 } | 337 } |
| 330 | 338 |
| 331 @end | 339 @end |
| OLD | NEW |