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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater.mm

Issue 2638413006: Add ContentSuggestionsMediator (Closed)
Patch Set: Fix 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/content_suggestions/content_suggestions_collectio n_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/content_suggestions/content_suggestions_article_i tem.h" 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i tem.h"
12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink .h"
13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sour ce.h"
12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl e_item.h" 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_expandabl e_item.h"
13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i tem.h" 15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_favicon_i tem.h"
14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h" 16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_item.h"
15 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite m.h" 17 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_stack_ite m.h"
16 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h" 18 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
17 19
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 20 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support." 21 #error "This file requires ARC support."
20 #endif 22 #endif
21 23
24 @interface ContentSuggestionsCollectionUpdater ()<ContentSuggestionsDataSink>
25
26 @property(nonatomic, strong) id<ContentSuggestionsDataSource> dataSource;
lpromero 2017/01/26 10:10:20 Can we risk creating a cycle if the one creating a
marq (ping after 24h) 2017/01/27 12:44:55 Does this need to be strong? Delegates usually are
gambard 2017/01/30 15:19:17 Yes, the data source should be kept alive by the c
27
28 @end
29
22 @implementation ContentSuggestionsCollectionUpdater 30 @implementation ContentSuggestionsCollectionUpdater
23 31
24 @synthesize collectionViewController = _collectionViewController; 32 @synthesize collectionViewController = _collectionViewController;
33 @synthesize dataSource = _dataSource;
34
35 - (instancetype)initWithDataSource:
36 (id<ContentSuggestionsDataSource>)dataSource {
37 self = [super init];
38 if (self) {
39 _dataSource = dataSource;
40 _dataSource.dataSink = self;
41 }
42 return self;
43 }
25 44
26 #pragma mark - Properties 45 #pragma mark - Properties
27 46
28 - (void)setCollectionViewController: 47 - (void)setCollectionViewController:
29 (ContentSuggestionsViewController*)collectionViewController { 48 (ContentSuggestionsViewController*)collectionViewController {
30 _collectionViewController = collectionViewController; 49 _collectionViewController = collectionViewController;
31 [collectionViewController loadModel]; 50 [collectionViewController loadModel];
32 CollectionViewModel* model = collectionViewController.collectionViewModel; 51 CollectionViewModel* model = collectionViewController.collectionViewModel;
52
53 // Loads the data with the dataSource instead of hard coded value.
lpromero 2017/01/26 10:10:20 Mark this with // PLACEHOLDER
marq (ping after 24h) 2017/01/27 12:44:55 Also, clarify that this is a change that needs to
gambard 2017/01/30 15:19:17 Done.
54
33 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; 55 NSInteger sectionIdentifier = kSectionIdentifierEnumZero;
34 56
35 // Stack Item. 57 // Stack Item.
36 [model addSectionWithIdentifier:sectionIdentifier]; 58 [model addSectionWithIdentifier:sectionIdentifier];
37 [model addItem:[[ContentSuggestionsStackItem alloc] 59 [model addItem:[[ContentSuggestionsStackItem alloc]
38 initWithType:ItemTypeStack 60 initWithType:ItemTypeStack
39 title:@"The title" 61 title:@"The title"
40 subtitle:@"The subtitle"] 62 subtitle:@"The subtitle"]
41 toSectionWithIdentifier:sectionIdentifier++]; 63 toSectionWithIdentifier:sectionIdentifier++];
42 64
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 image:[UIImage imageNamed:@"distillation_fail"] 103 image:[UIImage imageNamed:@"distillation_fail"]
82 detailText:@"Details shown only when the article is " 104 detailText:@"Details shown only when the article is "
83 @"expanded. It can be displayed on " 105 @"expanded. It can be displayed on "
84 @"multiple lines."]; 106 @"multiple lines."];
85 expandableItem.delegate = _collectionViewController; 107 expandableItem.delegate = _collectionViewController;
86 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier]; 108 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier];
87 sectionIdentifier++; 109 sectionIdentifier++;
88 } 110 }
89 } 111 }
90 112
113 #pragma mark - ContentSuggestionsDataSink
114
115 - (void)dataAvailable {
116 [self.dataSource getMoreData];
marq (ping after 24h) 2017/01/27 12:44:55 Either delete the dataSource call or assign the re
gambard 2017/01/30 15:19:17 Done.
117 // Do something.
118 }
119
91 #pragma mark - Public methods 120 #pragma mark - Public methods
92 121
93 - (void)addTextItem:(NSString*)title 122 - (void)addTextItem:(NSString*)title
94 subtitle:(NSString*)subtitle 123 subtitle:(NSString*)subtitle
95 toSection:(NSInteger)inputSection { 124 toSection:(NSInteger)inputSection {
96 DCHECK(_collectionViewController); 125 DCHECK(_collectionViewController);
97 ContentSuggestionsItem* item = 126 ContentSuggestionsItem* item =
98 [[ContentSuggestionsItem alloc] initWithType:ItemTypeText 127 [[ContentSuggestionsItem alloc] initWithType:ItemTypeText
99 title:title 128 title:title
100 subtitle:subtitle]; 129 subtitle:subtitle];
(...skipping 22 matching lines...) Expand all
123 inSection:sectionIndex] ]]; 152 inSection:sectionIndex] ]];
124 } 153 }
125 completion:nil]; 154 completion:nil];
126 } 155 }
127 156
128 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section { 157 - (BOOL)shouldUseCustomStyleForSection:(NSInteger)section {
129 return section == 0 || section == 1; 158 return section == 0 || section == 1;
130 } 159 }
131 160
132 @end 161 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698