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

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

Issue 2625693002: Suggestions UI - expandable item (Closed)
Patch Set: Update tests 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 #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"
8 #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"
9 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
10 #import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.h" 11 #import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.h"
11 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h" 12 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h"
12 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h" 13 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h"
13 14
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 16 #error "This file requires ARC support."
16 #endif 17 #endif
17 18
18 @interface SuggestionsViewController ()<SuggestionsItemActions> 19 @interface SuggestionsViewController ()<SuggestionsItemActions>
19 20
20 @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater; 21 @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater;
21 22
23 // Applies |interaction| to the item corresponding to |cell| if it is a
marq (ping after 24h) 2017/01/16 17:16:42 |interaction| isn't defined.
gambard 2017/01/17 09:59:00 Done.
24 // SuggestionsExpandableCell.
25 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell;
26
22 @end 27 @end
23 28
24 @implementation SuggestionsViewController 29 @implementation SuggestionsViewController
25 30
26 @synthesize suggestionCommandHandler = _suggestionCommandHandler; 31 @synthesize suggestionCommandHandler = _suggestionCommandHandler;
27 @synthesize collectionUpdater = _collectionUpdater; 32 @synthesize collectionUpdater = _collectionUpdater;
28 33
29 #pragma mark - UIViewController 34 #pragma mark - UIViewController
30 35
31 - (void)viewDidLoad { 36 - (void)viewDidLoad {
(...skipping 15 matching lines...) Expand all
47 UIEdgeInsets inset = [self collectionView:collectionView 52 UIEdgeInsets inset = [self collectionView:collectionView
48 layout:collectionView.collectionViewLayout 53 layout:collectionView.collectionViewLayout
49 insetForSectionAtIndex:indexPath.section]; 54 insetForSectionAtIndex:indexPath.section];
50 55
51 return [MDCCollectionViewCell 56 return [MDCCollectionViewCell
52 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) - 57 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
53 inset.left - inset.right 58 inset.left - inset.right
54 forItem:item]; 59 forItem:item];
55 } 60 }
56 61
62 #pragma mark - SuggestionsExpandableCellDelegate
63
64 - (void)retractCell:(UICollectionViewCell*)cell {
65 [self expand:NO cell:cell];
66 }
67
68 - (void)expandCell:(UICollectionViewCell*)cell {
69 [self expand:YES cell:cell];
70 }
71
57 #pragma mark - SuggestionsItemActions 72 #pragma mark - SuggestionsItemActions
58 73
59 - (void)addNewItem:(id)sender { 74 - (void)addNewItem:(id)sender {
60 [self.suggestionCommandHandler addEmptyItem]; 75 [self.suggestionCommandHandler addEmptyItem];
61 } 76 }
62 77
63 #pragma mark - SuggestionsCollectionUpdater forwarding 78 #pragma mark - SuggestionsCollectionUpdater forwarding
64 79
65 - (void)addTextItem:(NSString*)title 80 - (void)addTextItem:(NSString*)title
66 subtitle:(NSString*)subtitle 81 subtitle:(NSString*)subtitle
67 toSection:(NSInteger)inputSection { 82 toSection:(NSInteger)inputSection {
68 [self.collectionUpdater addTextItem:title 83 [self.collectionUpdater addTextItem:title
69 subtitle:subtitle 84 subtitle:subtitle
70 toSection:inputSection]; 85 toSection:inputSection];
71 } 86 }
72 87
88 #pragma mark - Private
89
90 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell {
91 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell];
92 CollectionViewItem* item =
93 [self.collectionViewModel itemAtIndexPath:indexPath];
94 if ([item isKindOfClass:[SuggestionsExpandableItem class]]) {
marq (ping after 24h) 2017/01/16 17:16:42 As soon as you start checking for class membership
gambard 2017/01/17 09:59:00 Done.
lpromero 2017/01/17 10:38:49 This should just check the item type.
gambard 2017/01/17 11:55:29 As I am checking if it conforms to protocol, the i
marq (ping after 24h) 2017/01/17 13:42:16 Part of the benefit of the protocol is that you do
gambard 2017/01/17 14:46:56 Yes, I was meaning different objects conforming to
95 SuggestionsExpandableItem* expandableItem =
96 base::mac::ObjCCast<SuggestionsExpandableItem>(item);
97
98 NSInteger sectionIdentifier = [self.collectionViewModel
99 sectionIdentifierForSection:indexPath.section];
100
101 expandableItem.expanded = expand;
marq (ping after 24h) 2017/01/16 17:16:42 lpromero@ -- The cycle of: - Collection item chan
lpromero 2017/01/17 10:38:49 It is a design decision to have the controller exp
marq (ping after 24h) 2017/01/17 13:42:16 I was thinking more of some way for the view item
102 [self reconfigureCellsForItems:@[ expandableItem ]
103 inSectionWithIdentifier:sectionIdentifier];
104
105 [UIView
106 animateWithDuration:1
marq (ping after 24h) 2017/01/16 17:16:42 use a constant for animation duration. one second
gambard 2017/01/17 09:59:00 Done.
107 animations:^{
108 [self.collectionView.collectionViewLayout invalidateLayout];
109 }];
110 }
111 }
112
73 @end 113 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698