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

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

Powered by Google App Engine
This is Rietveld 408576698