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

Side by Side Diff: ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm

Issue 2619963004: Suggestions UI - Add Data Source and Item (Closed)
Patch Set: Change to property Created 3 years, 11 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/suggestions/suggestions_view_controller.h" 5 #import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h"
6 6
7 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 7 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.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 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 9 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
10 #import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.h"
10 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h" 11 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h"
11 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h" 12 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h"
12 13
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 14 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 15 #error "This file requires ARC support."
15 #endif 16 #endif
16 17
17 @interface SuggestionsViewController ()<SuggestionsItemActions> 18 @interface SuggestionsViewController ()<SuggestionsItemActions>
18 19
20 @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater;
21
19 @end 22 @end
20 23
21 @implementation SuggestionsViewController 24 @implementation SuggestionsViewController
22 25
23 @synthesize suggestionCommandHandler = _suggestionCommandHandler; 26 @synthesize suggestionCommandHandler = _suggestionCommandHandler;
27 @synthesize collectionUpdater = _collectionUpdater;
24 28
25 #pragma mark - UIViewController 29 #pragma mark - UIViewController
26 30
27 - (void)viewDidLoad { 31 - (void)viewDidLoad {
28 [super viewDidLoad]; 32 [super viewDidLoad];
29 33
34 _collectionUpdater = [[SuggestionsCollectionUpdater alloc]
35 initWithCollectionViewController:self];
36
30 self.collectionView.delegate = self; 37 self.collectionView.delegate = self;
31 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 38 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
32 } 39 }
33 40
34 #pragma mark - MDCCollectionViewStylingDelegate 41 #pragma mark - MDCCollectionViewStylingDelegate
35 42
36 - (CGFloat)collectionView:(UICollectionView*)collectionView 43 - (CGFloat)collectionView:(UICollectionView*)collectionView
37 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 44 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
38 CollectionViewItem* item = 45 CollectionViewItem* item =
39 [self.collectionViewModel itemAtIndexPath:indexPath]; 46 [self.collectionViewModel itemAtIndexPath:indexPath];
40 UIEdgeInsets inset = [self collectionView:collectionView 47 UIEdgeInsets inset = [self collectionView:collectionView
41 layout:collectionView.collectionViewLayout 48 layout:collectionView.collectionViewLayout
42 insetForSectionAtIndex:indexPath.section]; 49 insetForSectionAtIndex:indexPath.section];
43 50
44 return [MDCCollectionViewCell 51 return [MDCCollectionViewCell
45 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) - 52 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
46 inset.left - inset.right 53 inset.left - inset.right
47 forItem:item]; 54 forItem:item];
48 } 55 }
49 56
50 #pragma mark - SuggestionsItemActions 57 #pragma mark - SuggestionsItemActions
51 58
52 - (void)addNewItem:(id)sender { 59 - (void)addNewItem:(id)sender {
53 [self.suggestionCommandHandler addEmptyItem]; 60 [self.suggestionCommandHandler addEmptyItem];
54 } 61 }
55 62
63 #pragma mark - SuggestionsCollectionUpdater forwarding
64
65 - (void)addTextItem:(NSString*)title
66 subtitle:(NSString*)subtitle
67 toSection:(NSInteger)inputSection {
68 [self.collectionUpdater addTextItem:title
69 subtitle:subtitle
70 toSection:inputSection];
71 }
72
56 @end 73 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698