| 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/content_suggestions/content_suggestions_view_cont
roller.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/expandable_item.h" | 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" |
| 12 #import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" |
| 13 #import "ios/chrome/browser/ui/suggestions/suggestions_commands.h" | 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item_acti
ons.h" |
| 14 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite
m.h" |
| 15 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite
m_actions.h" |
| 16 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item_actions.h" | 16 #import "ios/chrome/browser/ui/content_suggestions/expandable_item.h" |
| 17 | 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 const NSTimeInterval kAnimationDuration = 0.35; | 23 const NSTimeInterval kAnimationDuration = 0.35; |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 @interface SuggestionsViewController ()<SuggestionsItemActions, | 26 @interface ContentSuggestionsViewController ()<SuggestionsItemActions, |
| 27 SuggestionsStackItemActions> | 27 SuggestionsStackItemActions> |
| 28 | 28 |
| 29 @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater; | 29 @property(nonatomic, strong) |
| 30 ContentSuggestionsCollectionUpdater* collectionUpdater; |
| 30 | 31 |
| 31 // Expand or collapse the |cell|, if it is a SuggestionsExpandableCell, | 32 // Expand or collapse the |cell|, if it is a ContentSuggestionsExpandableCell, |
| 32 // according to |expand|. | 33 // according to |expand|. |
| 33 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell; | 34 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell; |
| 34 | 35 |
| 35 @end | 36 @end |
| 36 | 37 |
| 37 @implementation SuggestionsViewController | 38 @implementation ContentSuggestionsViewController |
| 38 | 39 |
| 39 @synthesize suggestionCommandHandler = _suggestionCommandHandler; | 40 @synthesize suggestionCommandHandler = _suggestionCommandHandler; |
| 40 @synthesize collectionUpdater = _collectionUpdater; | 41 @synthesize collectionUpdater = _collectionUpdater; |
| 41 | 42 |
| 42 #pragma mark - UIViewController | 43 #pragma mark - UIViewController |
| 43 | 44 |
| 44 - (void)viewDidLoad { | 45 - (void)viewDidLoad { |
| 45 [super viewDidLoad]; | 46 [super viewDidLoad]; |
| 46 | 47 |
| 47 _collectionUpdater = [[SuggestionsCollectionUpdater alloc] init]; | 48 _collectionUpdater = [[ContentSuggestionsCollectionUpdater alloc] init]; |
| 48 _collectionUpdater.collectionViewController = self; | 49 _collectionUpdater.collectionViewController = self; |
| 49 | 50 |
| 50 self.collectionView.delegate = self; | 51 self.collectionView.delegate = self; |
| 51 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 52 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 52 } | 53 } |
| 53 | 54 |
| 54 #pragma mark - UICollectionViewDelegate | 55 #pragma mark - UICollectionViewDelegate |
| 55 | 56 |
| 56 - (void)collectionView:(UICollectionView*)collectionView | 57 - (void)collectionView:(UICollectionView*)collectionView |
| 57 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 58 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 58 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 59 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 59 | 60 |
| 60 CollectionViewItem* item = | 61 CollectionViewItem* item = |
| 61 [self.collectionViewModel itemAtIndexPath:indexPath]; | 62 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 62 if (item.type == ItemTypeStack) { | 63 if (item.type == ItemTypeStack) { |
| 63 [self.suggestionCommandHandler openReadingList]; | 64 [self.suggestionCommandHandler openReadingList]; |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 | 67 |
| 67 #pragma mark - SuggestionsExpandableCellDelegate | 68 #pragma mark - ContentSuggestionsExpandableCellDelegate |
| 68 | 69 |
| 69 - (void)collapseCell:(UICollectionViewCell*)cell { | 70 - (void)collapseCell:(UICollectionViewCell*)cell { |
| 70 [self expand:NO cell:cell]; | 71 [self expand:NO cell:cell]; |
| 71 } | 72 } |
| 72 | 73 |
| 73 - (void)expandCell:(UICollectionViewCell*)cell { | 74 - (void)expandCell:(UICollectionViewCell*)cell { |
| 74 [self expand:YES cell:cell]; | 75 [self expand:YES cell:cell]; |
| 75 } | 76 } |
| 76 | 77 |
| 77 #pragma mark - SuggestionsItemActions | 78 #pragma mark - SuggestionsItemActions |
| 78 | 79 |
| 79 - (void)addNewItem:(id)sender { | 80 - (void)addNewItem:(id)sender { |
| 80 [self.suggestionCommandHandler addEmptyItem]; | 81 [self.suggestionCommandHandler addEmptyItem]; |
| 81 } | 82 } |
| 82 | 83 |
| 83 #pragma mark - SuggestionsCollectionUpdater forwarding | 84 #pragma mark - ContentSuggestionsCollectionUpdater forwarding |
| 84 | 85 |
| 85 - (void)addTextItem:(NSString*)title | 86 - (void)addTextItem:(NSString*)title |
| 86 subtitle:(NSString*)subtitle | 87 subtitle:(NSString*)subtitle |
| 87 toSection:(NSInteger)inputSection { | 88 toSection:(NSInteger)inputSection { |
| 88 [self.collectionUpdater addTextItem:title | 89 [self.collectionUpdater addTextItem:title |
| 89 subtitle:subtitle | 90 subtitle:subtitle |
| 90 toSection:inputSection]; | 91 toSection:inputSection]; |
| 91 } | 92 } |
| 92 | 93 |
| 93 #pragma mark - SuggestionsStackItemActions | 94 #pragma mark - SuggestionsStackItemActions |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 inset.left - inset.right | 130 inset.left - inset.right |
| 130 forItem:item]; | 131 forItem:item]; |
| 131 } | 132 } |
| 132 | 133 |
| 133 #pragma mark - Private | 134 #pragma mark - Private |
| 134 | 135 |
| 135 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell { | 136 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell { |
| 136 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell]; | 137 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell]; |
| 137 CollectionViewItem* item = | 138 CollectionViewItem* item = |
| 138 [self.collectionViewModel itemAtIndexPath:indexPath]; | 139 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 139 if ([item conformsToProtocol:@protocol(SuggestionsExpandableArticle)]) { | 140 if ([item conformsToProtocol:@protocol(ExpandableItem)]) { |
| 140 id<SuggestionsExpandableArticle> expandableItem = | 141 id<ExpandableItem> expandableItem = (id<ExpandableItem>)item; |
| 141 (id<SuggestionsExpandableArticle>)item; | |
| 142 | 142 |
| 143 NSInteger sectionIdentifier = [self.collectionViewModel | 143 NSInteger sectionIdentifier = [self.collectionViewModel |
| 144 sectionIdentifierForSection:indexPath.section]; | 144 sectionIdentifierForSection:indexPath.section]; |
| 145 | 145 |
| 146 expandableItem.expanded = expand; | 146 expandableItem.expanded = expand; |
| 147 [self reconfigureCellsForItems:@[ item ] | 147 [self reconfigureCellsForItems:@[ item ] |
| 148 inSectionWithIdentifier:sectionIdentifier]; | 148 inSectionWithIdentifier:sectionIdentifier]; |
| 149 | 149 |
| 150 [UIView | 150 [UIView |
| 151 animateWithDuration:kAnimationDuration | 151 animateWithDuration:kAnimationDuration |
| 152 animations:^{ | 152 animations:^{ |
| 153 [self.collectionView.collectionViewLayout invalidateLayout]; | 153 [self.collectionView.collectionViewLayout invalidateLayout]; |
| 154 }]; | 154 }]; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 @end | 158 @end |
| OLD | NEW |