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/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 |
| 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 Loading... |
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]]) { |
| 95 SuggestionsExpandableItem* expandableItem = |
| 96 base::mac::ObjCCast<SuggestionsExpandableItem>(item); |
| 97 |
| 98 NSInteger sectionIdentifier = [self.collectionViewModel |
| 99 sectionIdentifierForSection:indexPath.section]; |
| 100 |
| 101 expandableItem.expanded = expand; |
| 102 [self reconfigureCellsForItems:@[ expandableItem ] |
| 103 inSectionWithIdentifier:sectionIdentifier]; |
| 104 |
| 105 [UIView |
| 106 animateWithDuration:1 |
| 107 animations:^{ |
| 108 [self.collectionView.collectionViewLayout invalidateLayout]; |
| 109 }]; |
| 110 } |
| 111 } |
| 112 |
73 @end | 113 @end |
OLD | NEW |