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

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

Issue 2630313004: Suggestions UI - stack item (Closed)
Patch Set: Address comments 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_collection_updater.h" 5 #import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.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/collection_view_controller.h" 8 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
9 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 9 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
10 #import "ios/chrome/browser/ui/suggestions/suggestions_article_item.h" 10 #import "ios/chrome/browser/ui/suggestions/suggestions_article_item.h"
11 #import "ios/chrome/browser/ui/suggestions/suggestions_expandable_item.h" 11 #import "ios/chrome/browser/ui/suggestions/suggestions_expandable_item.h"
12 #import "ios/chrome/browser/ui/suggestions/suggestions_item.h" 12 #import "ios/chrome/browser/ui/suggestions/suggestions_item.h"
13 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item.h"
13 #import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h" 14 #import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h"
14 15
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 17 #error "This file requires ARC support."
17 #endif 18 #endif
18 19
19 namespace { 20 @implementation SuggestionsCollectionUpdater
20 typedef NS_ENUM(NSInteger, ItemType) {
21 ItemTypeText = kItemTypeEnumZero,
22 ItemTypeArticle,
23 ItemTypeExpand,
24 };
25 21
26 } // namespace 22 @synthesize collectionViewController = _collectionViewController;
27 23
28 @implementation SuggestionsCollectionUpdater { 24 #pragma mark - Properties
29 SuggestionsViewController* _collectionViewController;
30 }
31 25
32 - (instancetype)initWithCollectionViewController: 26 - (void)setCollectionViewController:
33 (SuggestionsViewController*)collectionViewController { 27 (SuggestionsViewController*)collectionViewController {
34 self = [super init]; 28 _collectionViewController = collectionViewController;
35 if (self) { 29 [collectionViewController loadModel];
36 _collectionViewController = collectionViewController; 30 CollectionViewModel* model = collectionViewController.collectionViewModel;
37 [collectionViewController loadModel]; 31 NSInteger sectionIdentifier = kSectionIdentifierEnumZero;
38 CollectionViewModel* model = collectionViewController.collectionViewModel; 32 [model addSectionWithIdentifier:sectionIdentifier];
39 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; 33 [model addItem:[[SuggestionsStackItem alloc] initWithType:ItemTypeStack
40 for (NSInteger i = 0; i < 3; i++) { 34 title:@"The title"
41 [model addSectionWithIdentifier:sectionIdentifier]; 35 subtitle:@"The subtitle"]
42 [model addItem:[[SuggestionsItem alloc] initWithType:ItemTypeText 36 toSectionWithIdentifier:sectionIdentifier++];
43 title:@"The title" 37
44 subtitle:@"The subtitle"] 38 for (NSInteger i = 0; i < 3; i++) {
45 toSectionWithIdentifier:sectionIdentifier]; 39 [model addSectionWithIdentifier:sectionIdentifier];
46 [model addItem: 40 [model addItem:[[SuggestionsItem alloc] initWithType:ItemTypeText
47 [[SuggestionsArticleItem alloc] 41 title:@"The title"
48 initWithType:ItemTypeArticle 42 subtitle:@"The subtitle"]
49 title:@"Title of an Article" 43 toSectionWithIdentifier:sectionIdentifier];
50 subtitle:@"This is the subtitle of an article, can " 44 [model addItem:[[SuggestionsArticleItem alloc]
51 @"spawn on multiple lines" 45 initWithType:ItemTypeArticle
52 image:[UIImage imageNamed:@"distillation_success"]] 46 title:@"Title of an Article"
53 toSectionWithIdentifier:sectionIdentifier]; 47 subtitle:@"This is the subtitle of an article, can "
54 SuggestionsExpandableItem* expandableItem = 48 @"spawn on multiple lines"
55 [[SuggestionsExpandableItem alloc] 49 image:[UIImage
56 initWithType:ItemTypeExpand 50 imageNamed:@"distillation_success"]]
57 title:@"Title of an Expandable Article" 51 toSectionWithIdentifier:sectionIdentifier];
58 subtitle:@"This Article can be expanded to display " 52 SuggestionsExpandableItem* expandableItem =
59 @"additional information or interaction " 53 [[SuggestionsExpandableItem alloc]
60 @"options" 54 initWithType:ItemTypeExpand
61 image:[UIImage imageNamed:@"distillation_fail"] 55 title:@"Title of an Expandable Article"
62 detailText:@"Details shown only when the article is " 56 subtitle:@"This Article can be expanded to display "
63 @"expanded. It can be displayed on " 57 @"additional information or interaction "
64 @"multiple lines."]; 58 @"options"
65 expandableItem.delegate = collectionViewController; 59 image:[UIImage imageNamed:@"distillation_fail"]
66 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier]; 60 detailText:@"Details shown only when the article is "
67 sectionIdentifier++; 61 @"expanded. It can be displayed on "
68 } 62 @"multiple lines."];
63 expandableItem.delegate = _collectionViewController;
64 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier];
65 sectionIdentifier++;
69 } 66 }
70 return self;
71 } 67 }
72 68
73 #pragma mark - Public methods 69 #pragma mark - Public methods
74 70
75 - (void)addTextItem:(NSString*)title 71 - (void)addTextItem:(NSString*)title
76 subtitle:(NSString*)subtitle 72 subtitle:(NSString*)subtitle
77 toSection:(NSInteger)inputSection { 73 toSection:(NSInteger)inputSection {
78 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText 74 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText
lpromero 2017/01/17 13:47:20 DCHECK(_collectionViewController)?
gambard 2017/01/17 14:52:36 Done.
79 title:title 75 title:title
80 subtitle:subtitle]; 76 subtitle:subtitle];
81 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection; 77 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection;
82 NSInteger sectionIndex = inputSection; 78 NSInteger sectionIndex = inputSection;
83 CollectionViewModel* model = _collectionViewController.collectionViewModel; 79 CollectionViewModel* model = _collectionViewController.collectionViewModel;
84 if ([model numberOfSections] <= inputSection) { 80 if ([model numberOfSections] <= inputSection) {
85 sectionIndex = [model numberOfSections]; 81 sectionIndex = [model numberOfSections];
86 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex; 82 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex;
87 [_collectionViewController.collectionView performBatchUpdates:^{ 83 [_collectionViewController.collectionView performBatchUpdates:^{
88 [_collectionViewController.collectionViewModel 84 [_collectionViewController.collectionViewModel
89 addSectionWithIdentifier:sectionIdentifier]; 85 addSectionWithIdentifier:sectionIdentifier];
90 [_collectionViewController.collectionView 86 [_collectionViewController.collectionView
91 insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]]; 87 insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
92 } 88 }
93 completion:nil]; 89 completion:nil];
94 } 90 }
95 NSInteger numberOfItemsInSection = 91 NSInteger numberOfItemsInSection =
96 [model numberOfItemsInSection:sectionIndex]; 92 [model numberOfItemsInSection:sectionIndex];
97 [_collectionViewController.collectionViewModel addItem:item 93 [_collectionViewController.collectionViewModel addItem:item
98 toSectionWithIdentifier:sectionIdentifier]; 94 toSectionWithIdentifier:sectionIdentifier];
99 [_collectionViewController.collectionView performBatchUpdates:^{ 95 [_collectionViewController.collectionView performBatchUpdates:^{
100 [_collectionViewController.collectionView 96 [_collectionViewController.collectionView
101 insertItemsAtIndexPaths:@[ [NSIndexPath 97 insertItemsAtIndexPaths:@[ [NSIndexPath
102 indexPathForRow:numberOfItemsInSection 98 indexPathForRow:numberOfItemsInSection
103 inSection:sectionIndex] ]]; 99 inSection:sectionIndex] ]];
104 } 100 }
105 completion:nil]; 101 completion:nil];
106 } 102 }
107 103
104 - (BOOL)isCustomStyling:(NSInteger)section {
lpromero 2017/01/17 13:47:20 s/isCustomStyling/shouldUseCustomStyleForSection?
gambard 2017/01/17 14:52:36 Done.
105 return section == 0;
106 }
107
108 @end 108 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698