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

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

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

Powered by Google App Engine
This is Rietveld 408576698