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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm

Issue 2644123003: Move ios/ui/suggestions to ios/ui/content_suggestions (Closed)
Patch Set: Rebase 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/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 - SuggestionsFaviconCellDelegate 78 #pragma mark - ContentSuggestionsFaviconCellDelegate
78 79
79 - (void)openFaviconAtIndexPath:(NSIndexPath*)innerIndexPath { 80 - (void)openFaviconAtIndexPath:(NSIndexPath*)innerIndexPath {
80 [self.suggestionCommandHandler openFaviconAtIndex:innerIndexPath.item]; 81 [self.suggestionCommandHandler openFaviconAtIndex:innerIndexPath.item];
81 } 82 }
82 83
83 #pragma mark - SuggestionsItemActions 84 #pragma mark - SuggestionsItemActions
84 85
85 - (void)addNewItem:(id)sender { 86 - (void)addNewItem:(id)sender {
86 [self.suggestionCommandHandler addEmptyItem]; 87 [self.suggestionCommandHandler addEmptyItem];
87 } 88 }
88 89
89 #pragma mark - SuggestionsCollectionUpdater forwarding 90 #pragma mark - ContentSuggestionsCollectionUpdater forwarding
90 91
91 - (void)addTextItem:(NSString*)title 92 - (void)addTextItem:(NSString*)title
92 subtitle:(NSString*)subtitle 93 subtitle:(NSString*)subtitle
93 toSection:(NSInteger)inputSection { 94 toSection:(NSInteger)inputSection {
94 [self.collectionUpdater addTextItem:title 95 [self.collectionUpdater addTextItem:title
95 subtitle:subtitle 96 subtitle:subtitle
96 toSection:inputSection]; 97 toSection:inputSection];
97 } 98 }
98 99
99 #pragma mark - SuggestionsStackItemActions 100 #pragma mark - SuggestionsStackItemActions
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 inset.left - inset.right 136 inset.left - inset.right
136 forItem:item]; 137 forItem:item];
137 } 138 }
138 139
139 #pragma mark - Private 140 #pragma mark - Private
140 141
141 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell { 142 - (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell {
142 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell]; 143 NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell];
143 CollectionViewItem* item = 144 CollectionViewItem* item =
144 [self.collectionViewModel itemAtIndexPath:indexPath]; 145 [self.collectionViewModel itemAtIndexPath:indexPath];
145 if ([item conformsToProtocol:@protocol(SuggestionsExpandableArticle)]) { 146 if ([item conformsToProtocol:@protocol(ExpandableItem)]) {
146 id<SuggestionsExpandableArticle> expandableItem = 147 id<ExpandableItem> expandableItem = (id<ExpandableItem>)item;
147 (id<SuggestionsExpandableArticle>)item;
148 148
149 NSInteger sectionIdentifier = [self.collectionViewModel 149 NSInteger sectionIdentifier = [self.collectionViewModel
150 sectionIdentifierForSection:indexPath.section]; 150 sectionIdentifierForSection:indexPath.section];
151 151
152 expandableItem.expanded = expand; 152 expandableItem.expanded = expand;
153 [self reconfigureCellsForItems:@[ item ] 153 [self reconfigureCellsForItems:@[ item ]
154 inSectionWithIdentifier:sectionIdentifier]; 154 inSectionWithIdentifier:sectionIdentifier];
155 155
156 [UIView 156 [UIView
157 animateWithDuration:kAnimationDuration 157 animateWithDuration:kAnimationDuration
158 animations:^{ 158 animations:^{
159 [self.collectionView.collectionViewLayout invalidateLayout]; 159 [self.collectionView.collectionViewLayout invalidateLayout];
160 }]; 160 }];
161 } 161 }
162 } 162 }
163 163
164 @end 164 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698