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

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

Issue 2638413006: Add ContentSuggestionsMediator (Closed)
Patch Set: Format Created 3 years, 10 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, weak) id<ContentSuggestionsDataSource> dataSource;
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 // TODO(crbug.com/686728): Load the data with the dataSource instead of hard
54 // coded value.
55
33 NSInteger sectionIdentifier = kSectionIdentifierEnumZero; 56 NSInteger sectionIdentifier = kSectionIdentifierEnumZero;
34 57
35 // Stack Item. 58 // Stack Item.
36 [model addSectionWithIdentifier:sectionIdentifier]; 59 [model addSectionWithIdentifier:sectionIdentifier];
37 [model addItem:[[ContentSuggestionsStackItem alloc] 60 [model addItem:[[ContentSuggestionsStackItem alloc]
38 initWithType:ItemTypeStack 61 initWithType:ItemTypeStack
39 title:@"The title" 62 title:@"The title"
40 subtitle:@"The subtitle"] 63 subtitle:@"The subtitle"]
41 toSectionWithIdentifier:sectionIdentifier++]; 64 toSectionWithIdentifier:sectionIdentifier++];
42 65
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 image:[UIImage imageNamed:@"distillation_fail"] 104 image:[UIImage imageNamed:@"distillation_fail"]
82 detailText:@"Details shown only when the article is " 105 detailText:@"Details shown only when the article is "
83 @"expanded. It can be displayed on " 106 @"expanded. It can be displayed on "
84 @"multiple lines."]; 107 @"multiple lines."];
85 expandableItem.delegate = _collectionViewController; 108 expandableItem.delegate = _collectionViewController;
86 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier]; 109 [model addItem:expandableItem toSectionWithIdentifier:sectionIdentifier];
87 sectionIdentifier++; 110 sectionIdentifier++;
88 } 111 }
89 } 112 }
90 113
114 #pragma mark - ContentSuggestionsDataSink
115
116 - (void)dataAvailable {
117 // TODO(crbug.com/686728): Get the new data from the DataSource.
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