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

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

Issue 2630313004: Suggestions UI - stack item (Closed)
Patch Set: Cleanup 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 #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/suggestions/suggestions_collection_updater.h" 11 #import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.h"
12 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h" 12 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h"
13 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h" 13 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h"
14 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item.h"
15 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item_actions.h"
14 16
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 18 #error "This file requires ARC support."
17 #endif 19 #endif
18 20
19 @interface SuggestionsViewController ()<SuggestionsItemActions> 21 @interface SuggestionsViewController ()<SuggestionsItemActions,
22 SuggestionsStackItemActions>
20 23
21 @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater; 24 @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater;
22 25
23 // Applies |interaction| to the item corresponding to |cell| if it is a 26 // Applies |interaction| to the item corresponding to |cell| if it is a
24 // SuggestionsExpandableCell. 27 // SuggestionsExpandableCell.
25 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell; 28 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell;
26 29
27 @end 30 @end
28 31
29 @implementation SuggestionsViewController 32 @implementation SuggestionsViewController
30 33
31 @synthesize suggestionCommandHandler = _suggestionCommandHandler; 34 @synthesize suggestionCommandHandler = _suggestionCommandHandler;
32 @synthesize collectionUpdater = _collectionUpdater; 35 @synthesize collectionUpdater = _collectionUpdater;
33 36
34 #pragma mark - UIViewController 37 #pragma mark - UIViewController
35 38
36 - (void)viewDidLoad { 39 - (void)viewDidLoad {
37 [super viewDidLoad]; 40 [super viewDidLoad];
38 41
39 _collectionUpdater = [[SuggestionsCollectionUpdater alloc] 42 _collectionUpdater = [[SuggestionsCollectionUpdater alloc] init];
40 initWithCollectionViewController:self]; 43 _collectionUpdater.collectionViewController = self;
41 44
42 self.collectionView.delegate = self; 45 self.collectionView.delegate = self;
43 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 46 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
44 } 47 }
45 48
46 #pragma mark - MDCCollectionViewStylingDelegate 49 #pragma mark - UICollectionViewDelegate
47 50
48 - (CGFloat)collectionView:(UICollectionView*)collectionView 51 - (void)collectionView:(UICollectionView*)collectionView
49 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 52 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
50 CollectionViewItem* item = 53 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
51 [self.collectionViewModel itemAtIndexPath:indexPath]; 54 if ([[self.collectionViewModel itemAtIndexPath:indexPath]
52 UIEdgeInsets inset = [self collectionView:collectionView 55 isKindOfClass:[SuggestionsStackItem class]]) {
marq (ping after 24h) 2017/01/16 18:04:42 I don't like the runtime class membership test.
lpromero 2017/01/16 18:17:55 This should test the itemType property of the item
gambard 2017/01/17 13:28:11 I used the item type.
gambard 2017/01/17 13:28:11 The ItemType property is unique per class for now
53 layout:collectionView.collectionViewLayout 56 [self.suggestionCommandHandler openReadingList];
54 insetForSectionAtIndex:indexPath.section]; 57 }
55
56 return [MDCCollectionViewCell
57 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
58 inset.left - inset.right
59 forItem:item];
60 } 58 }
61 59
62 #pragma mark - SuggestionsExpandableCellDelegate 60 #pragma mark - SuggestionsExpandableCellDelegate
63 61
64 - (void)retractCell:(UICollectionViewCell*)cell { 62 - (void)retractCell:(UICollectionViewCell*)cell {
65 [self expand:NO cell:cell]; 63 [self expand:NO cell:cell];
66 } 64 }
67 65
68 - (void)expandCell:(UICollectionViewCell*)cell { 66 - (void)expandCell:(UICollectionViewCell*)cell {
69 [self expand:YES cell:cell]; 67 [self expand:YES cell:cell];
70 } 68 }
71 69
72 #pragma mark - SuggestionsItemActions 70 #pragma mark - SuggestionsItemActions
73 71
74 - (void)addNewItem:(id)sender { 72 - (void)addNewItem:(id)sender {
75 [self.suggestionCommandHandler addEmptyItem]; 73 [self.suggestionCommandHandler addEmptyItem];
76 } 74 }
77 75
78 #pragma mark - SuggestionsCollectionUpdater forwarding 76 #pragma mark - SuggestionsCollectionUpdater forwarding
79 77
80 - (void)addTextItem:(NSString*)title 78 - (void)addTextItem:(NSString*)title
81 subtitle:(NSString*)subtitle 79 subtitle:(NSString*)subtitle
82 toSection:(NSInteger)inputSection { 80 toSection:(NSInteger)inputSection {
83 [self.collectionUpdater addTextItem:title 81 [self.collectionUpdater addTextItem:title
84 subtitle:subtitle 82 subtitle:subtitle
85 toSection:inputSection]; 83 toSection:inputSection];
86 } 84 }
87 85
86 #pragma mark - SuggestionsStackItemActions
87
88 - (void)topOfStackPressed:(id)sender {
89 [self.suggestionCommandHandler openFirstPageOfReadingList];
90 }
91
92 #pragma mark - MDCCollectionViewStylingDelegate
93
94 - (nullable UIColor*)collectionView:(nonnull UICollectionView*)collectionView
marq (ping after 24h) 2017/01/16 18:04:42 I think we don't want nullability annotations on s
gambard 2017/01/17 13:28:11 Done.
95 cellBackgroundColorAtIndexPath:(nonnull NSIndexPath*)indexPath {
96 if ([self.collectionUpdater isCustomStyling:indexPath.section]) {
97 return [UIColor clearColor];
98 }
99 return [UIColor whiteColor];
100 }
101
102 - (BOOL)collectionView:(nonnull UICollectionView*)collectionView
103 shouldHideItemBackgroundAtIndexPath:(nonnull NSIndexPath*)indexPath {
104 if ([self.collectionUpdater isCustomStyling:indexPath.section]) {
105 return YES;
106 }
107 return NO;
108 }
109
110 - (CGFloat)collectionView:(UICollectionView*)collectionView
111 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
112 CollectionViewItem* item =
113 [self.collectionViewModel itemAtIndexPath:indexPath];
114 UIEdgeInsets inset = [self collectionView:collectionView
115 layout:collectionView.collectionViewLayout
116 insetForSectionAtIndex:indexPath.section];
117
118 return [MDCCollectionViewCell
119 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
marq (ping after 24h) 2017/01/16 18:04:42 Taking edge inset width into account for cell heig
lpromero 2017/01/16 18:17:55 This is dependent on the cellStyle this controller
gambard 2017/01/17 13:28:11 Maybe we should add a method to CollectionViewCont
marq (ping after 24h) 2017/01/17 14:36:06 I meant CollectionViewController, since this is a
120 inset.left - inset.right
121 forItem:item];
122 }
123
88 #pragma mark - Private 124 #pragma mark - Private
89 125
90 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell { 126 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell {
91 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell]; 127 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell];
92 CollectionViewItem* item = 128 CollectionViewItem* item =
93 [self.collectionViewModel itemAtIndexPath:indexPath]; 129 [self.collectionViewModel itemAtIndexPath:indexPath];
94 if ([item isKindOfClass:[SuggestionsExpandableItem class]]) { 130 if ([item isKindOfClass:[SuggestionsExpandableItem class]]) {
95 SuggestionsExpandableItem* expandableItem = 131 SuggestionsExpandableItem* expandableItem =
96 base::mac::ObjCCast<SuggestionsExpandableItem>(item); 132 base::mac::ObjCCast<SuggestionsExpandableItem>(item);
97 133
98 NSInteger sectionIdentifier = [self.collectionViewModel 134 NSInteger sectionIdentifier = [self.collectionViewModel
99 sectionIdentifierForSection:indexPath.section]; 135 sectionIdentifierForSection:indexPath.section];
100 136
101 expandableItem.expanded = expand; 137 expandableItem.expanded = expand;
102 [self reconfigureCellsForItems:@[ expandableItem ] 138 [self reconfigureCellsForItems:@[ expandableItem ]
103 inSectionWithIdentifier:sectionIdentifier]; 139 inSectionWithIdentifier:sectionIdentifier];
104 140
105 [UIView 141 [UIView
106 animateWithDuration:1 142 animateWithDuration:1
107 animations:^{ 143 animations:^{
108 [self.collectionView.collectionViewLayout invalidateLayout]; 144 [self.collectionView.collectionViewLayout invalidateLayout];
109 }]; 145 }];
110 } 146 }
111 } 147 }
112 148
113 @end 149 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698