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

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

Issue 2630313004: Suggestions UI - stack item (Closed)
Patch Set: Cleanup 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 namespace {
20 typedef NS_ENUM(NSInteger, ItemType) { 21 typedef NS_ENUM(NSInteger, ItemType) {
21 ItemTypeText = kItemTypeEnumZero, 22 ItemTypeText = kItemTypeEnumZero,
22 ItemTypeArticle, 23 ItemTypeArticle,
23 ItemTypeExpand, 24 ItemTypeExpand,
25 ItemTypeStack,
24 }; 26 };
25 27
26 } // namespace 28 } // namespace
27 29
28 @implementation SuggestionsCollectionUpdater { 30 @implementation SuggestionsCollectionUpdater
29 SuggestionsViewController* _collectionViewController;
30 }
31 31
32 - (instancetype)initWithCollectionViewController: 32 @synthesize collectionViewController = _collectionViewController;
33
34 #pragma mark - Properties
35
36 - (void)setCollectionViewController:
33 (SuggestionsViewController*)collectionViewController { 37 (SuggestionsViewController*)collectionViewController {
34 self = [super init]; 38 _collectionViewController = collectionViewController;
35 if (self) { 39 [collectionViewController loadModel];
36 _collectionViewController = collectionViewController; 40 CollectionViewModel* model = collectionViewController.collectionViewModel;
37 [collectionViewController loadModel]; 41 NSInteger sectionIdentifier = kSectionIdentifierEnumZero;
38 CollectionViewModel* model = collectionViewController.collectionViewModel; 42 [model addSectionWithIdentifier:sectionIdentifier];
39 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; 43 [model addItem:[[SuggestionsStackItem alloc] initWithType:ItemTypeStack
40 for (NSInteger i = 0; i < 3; i++) { 44 title:@"The title"
41 [model addSectionWithIdentifier:sectionIdentifier]; 45 subtitle:@"The subtitle"]
42 [model addItem:[[SuggestionsItem alloc] initWithType:ItemTypeText 46 toSectionWithIdentifier:sectionIdentifier++];
43 title:@"The title" 47
44 subtitle:@"The subtitle"] 48 for (NSInteger i = 0; i < 3; i++) {
45 toSectionWithIdentifier:sectionIdentifier]; 49 [model addSectionWithIdentifier:sectionIdentifier];
46 [model addItem: 50 [model addItem:[[SuggestionsItem alloc] initWithType:ItemTypeText
47 [[SuggestionsArticleItem alloc] 51 title:@"The title"
48 initWithType:ItemTypeArticle 52 subtitle:@"The subtitle"]
49 title:@"Title of an Article" 53 toSectionWithIdentifier:sectionIdentifier];
50 subtitle:@"This is the subtitle of an article, can " 54 [model addItem:[[SuggestionsArticleItem alloc]
51 @"spawn on multiple lines" 55 initWithType:ItemTypeArticle
52 image:[UIImage imageNamed:@"distillation_success"]] 56 title:@"Title of an Article"
53 toSectionWithIdentifier:sectionIdentifier]; 57 subtitle:@"This is the subtitle of an article, can "
54 SuggestionsExpandableItem* expandableItem = 58 @"spawn on multiple lines"
55 [[SuggestionsExpandableItem alloc] 59 image:[UIImage
56 initWithType:ItemTypeExpand 60 imageNamed:@"distillation_success"]]
57 title:@"Title of an Expandable Article" 61 toSectionWithIdentifier:sectionIdentifier];
58 subtitle:@"This Article can be expanded to display " 62 SuggestionsExpandableItem* expandableItem =
59 @"addition information or interaction " 63 [[SuggestionsExpandableItem alloc]
60 @"options" 64 initWithType:ItemTypeExpand
61 image:[UIImage imageNamed:@"distillation_fail"] 65 title:@"Title of an Expandable Article"
62 detailText:@"Details shown only when the article is " 66 subtitle:@"This Article can be expanded to display "
63 @"expanded. It can be displayed on " 67 @"addition information or interaction "
64 @"multiple lines."]; 68 @"options"
65 expandableItem.delegate = collectionViewController; 69 image:[UIImage imageNamed:@"distillation_fail"]
66 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier]; 70 detailText:@"Details shown only when the article is "
67 sectionIdentifier++; 71 @"expanded. It can be displayed on "
68 } 72 @"multiple lines."];
73 expandableItem.delegate = _collectionViewController;
74 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier];
75 sectionIdentifier++;
69 } 76 }
70 return self;
71 } 77 }
72 78
73 #pragma mark - Public methods 79 #pragma mark - Public methods
74 80
75 - (void)addTextItem:(NSString*)title 81 - (void)addTextItem:(NSString*)title
76 subtitle:(NSString*)subtitle 82 subtitle:(NSString*)subtitle
77 toSection:(NSInteger)inputSection { 83 toSection:(NSInteger)inputSection {
78 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText 84 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText
79 title:title 85 title:title
80 subtitle:subtitle]; 86 subtitle:subtitle];
(...skipping 17 matching lines...) Expand all
98 toSectionWithIdentifier:sectionIdentifier]; 104 toSectionWithIdentifier:sectionIdentifier];
99 [_collectionViewController.collectionView performBatchUpdates:^{ 105 [_collectionViewController.collectionView performBatchUpdates:^{
100 [_collectionViewController.collectionView 106 [_collectionViewController.collectionView
101 insertItemsAtIndexPaths:@[ [NSIndexPath 107 insertItemsAtIndexPaths:@[ [NSIndexPath
102 indexPathForRow:numberOfItemsInSection 108 indexPathForRow:numberOfItemsInSection
103 inSection:sectionIndex] ]]; 109 inSection:sectionIndex] ]];
104 } 110 }
105 completion:nil]; 111 completion:nil];
106 } 112 }
107 113
114 - (BOOL)isCustomStyling:(NSInteger)section {
115 return section == 0;
116 }
117
108 @end 118 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698