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