| 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/content_suggestions/content_suggestions_collectio
n_updater.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.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" | 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 11 #import "ios/chrome/browser/ui/suggestions/suggestions_article_item.h" | 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i
tem.h" |
| 12 #import "ios/chrome/browser/ui/suggestions/suggestions_expandable_item.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl
e_item.h" |
| 13 #import "ios/chrome/browser/ui/suggestions/suggestions_item.h" | 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h" |
| 14 #import "ios/chrome/browser/ui/suggestions/suggestions_stack_item.h" | 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite
m.h" |
| 15 #import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h" | 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
| 16 | 16 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 @implementation SuggestionsCollectionUpdater | 21 @implementation ContentSuggestionsCollectionUpdater |
| 22 | 22 |
| 23 @synthesize collectionViewController = _collectionViewController; | 23 @synthesize collectionViewController = _collectionViewController; |
| 24 | 24 |
| 25 #pragma mark - Properties | 25 #pragma mark - Properties |
| 26 | 26 |
| 27 - (void)setCollectionViewController: | 27 - (void)setCollectionViewController: |
| 28 (SuggestionsViewController*)collectionViewController { | 28 (ContentSuggestionsViewController*)collectionViewController { |
| 29 _collectionViewController = collectionViewController; | 29 _collectionViewController = collectionViewController; |
| 30 [collectionViewController loadModel]; | 30 [collectionViewController loadModel]; |
| 31 CollectionViewModel* model = collectionViewController.collectionViewModel; | 31 CollectionViewModel* model = collectionViewController.collectionViewModel; |
| 32 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; | 32 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; |
| 33 [model addSectionWithIdentifier:sectionIdentifier]; | 33 [model addSectionWithIdentifier:sectionIdentifier]; |
| 34 [model addItem:[[SuggestionsStackItem alloc] initWithType:ItemTypeStack | 34 [model addItem:[[ContentSuggestionsStackItem alloc] |
| 35 title:@"The title" | 35 initWithType:ItemTypeStack |
| 36 subtitle:@"The subtitle"] | 36 title:@"The title" |
| 37 subtitle:@"The subtitle"] |
| 37 toSectionWithIdentifier:sectionIdentifier++]; | 38 toSectionWithIdentifier:sectionIdentifier++]; |
| 38 | 39 |
| 39 for (NSInteger i = 0; i < 3; i++) { | 40 for (NSInteger i = 0; i < 3; i++) { |
| 40 [model addSectionWithIdentifier:sectionIdentifier]; | 41 [model addSectionWithIdentifier:sectionIdentifier]; |
| 41 [model addItem:[[SuggestionsItem alloc] initWithType:ItemTypeText | 42 [model addItem:[[ContentSuggestionsItem alloc] initWithType:ItemTypeText |
| 42 title:@"The title" | 43 title:@"The title" |
| 43 subtitle:@"The subtitle"] | 44 subtitle:@"The subtitle"] |
| 44 toSectionWithIdentifier:sectionIdentifier]; | 45 toSectionWithIdentifier:sectionIdentifier]; |
| 45 [model addItem:[[SuggestionsArticleItem alloc] | 46 [model addItem:[[ContentSuggestionsArticleItem alloc] |
| 46 initWithType:ItemTypeArticle | 47 initWithType:ItemTypeArticle |
| 47 title:@"Title of an Article" | 48 title:@"Title of an Article" |
| 48 subtitle:@"This is the subtitle of an article, can " | 49 subtitle:@"This is the subtitle of an article, can " |
| 49 @"spawn on multiple lines" | 50 @"spawn on multiple lines" |
| 50 image:[UIImage | 51 image:[UIImage |
| 51 imageNamed:@"distillation_success"]] | 52 imageNamed:@"distillation_success"]] |
| 52 toSectionWithIdentifier:sectionIdentifier]; | 53 toSectionWithIdentifier:sectionIdentifier]; |
| 53 SuggestionsExpandableItem* expandableItem = | 54 SuggestionsExpandableItem* expandableItem = |
| 54 [[SuggestionsExpandableItem alloc] | 55 [[SuggestionsExpandableItem alloc] |
| 55 initWithType:ItemTypeExpand | 56 initWithType:ItemTypeExpand |
| (...skipping 10 matching lines...) Expand all Loading... |
| 66 sectionIdentifier++; | 67 sectionIdentifier++; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 #pragma mark - Public methods | 71 #pragma mark - Public methods |
| 71 | 72 |
| 72 - (void)addTextItem:(NSString*)title | 73 - (void)addTextItem:(NSString*)title |
| 73 subtitle:(NSString*)subtitle | 74 subtitle:(NSString*)subtitle |
| 74 toSection:(NSInteger)inputSection { | 75 toSection:(NSInteger)inputSection { |
| 75 DCHECK(_collectionViewController); | 76 DCHECK(_collectionViewController); |
| 76 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText | 77 ContentSuggestionsItem* item = |
| 77 title:title | 78 [[ContentSuggestionsItem alloc] initWithType:ItemTypeText |
| 78 subtitle:subtitle]; | 79 title:title |
| 80 subtitle:subtitle]; |
| 79 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection; | 81 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + inputSection; |
| 80 NSInteger sectionIndex = inputSection; | 82 NSInteger sectionIndex = inputSection; |
| 81 CollectionViewModel* model = _collectionViewController.collectionViewModel; | 83 CollectionViewModel* model = _collectionViewController.collectionViewModel; |
| 82 if ([model numberOfSections] <= inputSection) { | 84 if ([model numberOfSections] <= inputSection) { |
| 83 sectionIndex = [model numberOfSections]; | 85 sectionIndex = [model numberOfSections]; |
| 84 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex; | 86 sectionIdentifier = kSectionIdentifierEnumZero + sectionIndex; |
| 85 [_collectionViewController.collectionView performBatchUpdates:^{ | 87 [_collectionViewController.collectionView performBatchUpdates:^{ |
| 86 [_collectionViewController.collectionViewModel | 88 [_collectionViewController.collectionViewModel |
| 87 addSectionWithIdentifier:sectionIdentifier]; | 89 addSectionWithIdentifier:sectionIdentifier]; |
| 88 [_collectionViewController.collectionView | 90 [_collectionViewController.collectionView |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 inSection:sectionIndex] ]]; | 103 inSection:sectionIndex] ]]; |
| 102 } | 104 } |
| 103 completion:nil]; | 105 completion:nil]; |
| 104 } | 106 } |
| 105 | 107 |
| 106 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { | 108 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { |
| 107 return section == 0; | 109 return section == 0; |
| 108 } | 110 } |
| 109 | 111 |
| 110 @end | 112 @end |
| OLD | NEW |