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

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

Issue 2743643002: [ObjC ARC] Converts ios/chrome/browser/ui/collection_view:collection_view to ARC. (Closed)
Patch Set: cleanup 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
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_controller.h" 5 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #import "base/mac/scoped_nsobject.h"
10 #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"
11 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
12 #import "ios/chrome/browser/ui/material_components/utils.h" 11 #import "ios/chrome/browser/ui/material_components/utils.h"
13 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h" 12 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h"
14 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 13 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
15 14
16 @implementation CollectionViewController { 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 // The implementation of this controller follows the guidelines from 16 #error "This file requires ARC support."
18 // https://github.com/material-components/material-components-ios/tree/develop /components/AppBar 17 #endif
19 base::scoped_nsobject<MDCAppBar> _appBar; 18
20 base::scoped_nsobject<CollectionViewModel> _collectionViewModel; 19 // The implementation of this controller follows the guidelines from
21 } 20 // https://github.com/material-components/material-components-ios/tree/develop/c omponents/AppBar
21 @implementation CollectionViewController
22 @synthesize appBar = _appBar;
23 @synthesize collectionViewModel = _collectionViewModel;
22 24
23 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style { 25 - (instancetype)initWithStyle:(CollectionViewControllerStyle)style {
24 UICollectionViewLayout* layout = 26 UICollectionViewLayout* layout = [[MDCCollectionViewFlowLayout alloc] init];
25 [[[MDCCollectionViewFlowLayout alloc] init] autorelease];
26 self = [super initWithCollectionViewLayout:layout]; 27 self = [super initWithCollectionViewLayout:layout];
27 if (self) { 28 if (self) {
28 if (style == CollectionViewControllerStyleAppBar) { 29 if (style == CollectionViewControllerStyleAppBar) {
29 _appBar.reset([[MDCAppBar alloc] init]); 30 _appBar = [[MDCAppBar alloc] init];
30 [self addChildViewController:_appBar.get().headerViewController]; 31 [self addChildViewController:_appBar.headerViewController];
31 } 32 }
32 } 33 }
33 return self; 34 return self;
34 } 35 }
35 36
36 - (void)viewDidLoad { 37 - (void)viewDidLoad {
37 [super viewDidLoad]; 38 [super viewDidLoad];
38 39
39 // Configure the app bar, if there is one. 40 // Configure the app bar, if there is one.
40 if (self.appBar) { 41 if (self.appBar) {
41 // Configure the app bar style. 42 // Configure the app bar style.
42 ConfigureAppBarWithCardStyle(self.appBar); 43 ConfigureAppBarWithCardStyle(self.appBar);
43 // Set the header view's tracking scroll view. 44 // Set the header view's tracking scroll view.
44 self.appBar.headerViewController.headerView.trackingScrollView = 45 self.appBar.headerViewController.headerView.trackingScrollView =
45 self.collectionView; 46 self.collectionView;
46 // After all other views have been registered. 47 // After all other views have been registered.
47 [self.appBar addSubviewsToParent]; 48 [self.appBar addSubviewsToParent];
48 } 49 }
49 } 50 }
50 51
51 - (UIViewController*)childViewControllerForStatusBarHidden { 52 - (UIViewController*)childViewControllerForStatusBarHidden {
52 return self.appBar.headerViewController; 53 return self.appBar.headerViewController;
53 } 54 }
54 55
55 - (UIViewController*)childViewControllerForStatusBarStyle { 56 - (UIViewController*)childViewControllerForStatusBarStyle {
56 return self.appBar.headerViewController; 57 return self.appBar.headerViewController;
57 } 58 }
58 59
59 - (MDCAppBar*)appBar {
60 return _appBar.get();
61 }
62
63 - (CollectionViewModel*)collectionViewModel {
64 return _collectionViewModel.get();
65 }
66
67 - (void)loadModel { 60 - (void)loadModel {
68 _collectionViewModel.reset([[CollectionViewModel alloc] init]); 61 _collectionViewModel = [[CollectionViewModel alloc] init];
69 } 62 }
70 63
71 - (void)reconfigureCellsForItems:(NSArray*)items 64 - (void)reconfigureCellsForItems:(NSArray*)items
72 inSectionWithIdentifier:(NSInteger)sectionIdentifier { 65 inSectionWithIdentifier:(NSInteger)sectionIdentifier {
73 for (CollectionViewItem* item in items) { 66 for (CollectionViewItem* item in items) {
74 NSIndexPath* indexPath = 67 NSIndexPath* indexPath =
75 [self.collectionViewModel indexPathForItem:item 68 [self.collectionViewModel indexPathForItem:item
76 inSectionWithIdentifier:sectionIdentifier]; 69 inSectionWithIdentifier:sectionIdentifier];
77 [self reconfigureCellAtIndexPath:indexPath withItem:item]; 70 [self reconfigureCellAtIndexPath:indexPath withItem:item];
78 } 71 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 107
115 - (void)collectionView:(UICollectionView*)collectionView 108 - (void)collectionView:(UICollectionView*)collectionView
116 willMoveItemAtIndexPath:(NSIndexPath*)indexPath 109 willMoveItemAtIndexPath:(NSIndexPath*)indexPath
117 toIndexPath:(NSIndexPath*)newIndexPath { 110 toIndexPath:(NSIndexPath*)newIndexPath {
118 // Check that the parent class doesn't implement this method. Otherwise, it 111 // Check that the parent class doesn't implement this method. Otherwise, it
119 // would need to be called here. 112 // would need to be called here.
120 DCHECK([self isKindOfClass:[MDCCollectionViewController class]]); 113 DCHECK([self isKindOfClass:[MDCCollectionViewController class]]);
121 DCHECK(![MDCCollectionViewController instancesRespondToSelector:_cmd]); 114 DCHECK(![MDCCollectionViewController instancesRespondToSelector:_cmd]);
122 115
123 // Retain the item to be able to move it. 116 // Retain the item to be able to move it.
124 base::scoped_nsobject<CollectionViewItem> item( 117 CollectionViewItem* item =
125 [[self.collectionViewModel itemAtIndexPath:indexPath] retain]); 118 [self.collectionViewModel itemAtIndexPath:indexPath];
126 119
127 // Item coordinates. 120 // Item coordinates.
128 NSInteger sectionIdentifier = 121 NSInteger sectionIdentifier =
129 [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; 122 [self.collectionViewModel sectionIdentifierForSection:indexPath.section];
130 NSInteger itemType = 123 NSInteger itemType =
131 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 124 [self.collectionViewModel itemTypeForIndexPath:indexPath];
132 NSUInteger indexInItemType = 125 NSUInteger indexInItemType =
133 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; 126 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
134 127
135 // Move the item. 128 // Move the item.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::mac::ObjCCastStrict<MDCCollectionViewCell>( 271 base::mac::ObjCCastStrict<MDCCollectionViewCell>(
279 [self.collectionView cellForItemAtIndexPath:indexPath]); 272 [self.collectionView cellForItemAtIndexPath:indexPath]);
280 273
281 // |cell| may be nil if the row is not currently on screen. 274 // |cell| may be nil if the row is not currently on screen.
282 if (cell) { 275 if (cell) {
283 [item configureCell:cell]; 276 [item configureCell:cell];
284 } 277 }
285 } 278 }
286 279
287 @end 280 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698