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

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

Issue 2619963004: Suggestions UI - Add Data Source and Item (Closed)
Patch Set: Cleanup 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_data_source.h"
6
7 #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/suggestions/suggestions_item.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 namespace {
16 typedef NS_ENUM(NSInteger, ItemType) {
17 ItemTypeText = kItemTypeEnumZero,
marq (ping after 24h) 2017/01/11 13:43:09 Chromium style is to use all caps ("MACRO_STYLE")
lpromero 2017/01/11 13:46:05 This is outside the scope of this CL, as this is t
gambard 2017/01/11 15:10:38 Acknowledged.
18 ItemTypeArticle,
19 ItemTypeExpand,
20 };
21
22 } // namespace
23
24 @implementation SuggestionsDataSource {
25 NSMutableArray<NSMutableArray<CollectionViewItem*>*>* _items;
lpromero 2017/01/11 09:47:04 No action needed: Hmm, you work around the fact th
gambard 2017/01/11 15:10:38 This was to allow the addition of items before set
26 }
27
28 @synthesize collectionViewController = _collectionViewController;
29
30 - (instancetype)init {
31 self = [super init];
32 if (self) {
33 _items = [NSMutableArray arrayWithCapacity:1];
lpromero 2017/01/11 09:47:04 I usually don't try to give clues like that, espec
gambard 2017/01/11 15:10:38 Done.
34 for (NSInteger i = 0; i < 3; i++) {
35 NSMutableArray<CollectionViewItem*>* arrayToAdd =
36 [NSMutableArray arrayWithCapacity:3];
37 [arrayToAdd
38 addObject:[[SuggestionsItem alloc] initWithType:ItemTypeText
39 title:@"The title"
40 subtitle:@"The subtitle"]];
lpromero 2017/01/11 09:47:04 Maybe remove this bogus data?
gambard 2017/01/11 15:10:37 Why? This is still a demo. It shows what kind of i
41 [_items addObject:arrayToAdd];
42 }
43 }
44 return self;
45 }
46
47 #pragma mark - Properties
48
49 - (void)setCollectionViewController:
50 (CollectionViewController*)collectionViewController {
51 _collectionViewController = collectionViewController;
52 if (!collectionViewController) {
53 return;
54 }
55 [collectionViewController loadModel];
56 CollectionViewModel* model = collectionViewController.collectionViewModel;
57 NSInteger sectionIdentifier = kSectionIdentifierEnumZero;
58 for (NSMutableArray<CollectionViewItem*>* arrayWithItems in _items) {
59 [model addSectionWithIdentifier:sectionIdentifier];
60 for (CollectionViewItem* item in arrayWithItems) {
61 [model addItem:item toSectionWithIdentifier:sectionIdentifier];
62 }
63 sectionIdentifier++;
64 }
65 }
66
67 #pragma mark - Public methods
68
69 - (void)addTextItem:(NSString*)title
70 subtitle:(NSString*)subtitle
71 toSection:(NSUInteger)section {
72 SuggestionsItem* item = [[SuggestionsItem alloc] initWithType:ItemTypeText
73 title:title
74 subtitle:subtitle];
75 NSInteger sectionIdentifier = kSectionIdentifierEnumZero + section;
76 NSInteger sectionIndex = section;
77 if (section >= [_items count]) {
78 sectionIndex = [_items count];
79 sectionIdentifier = kSectionIdentifierEnumZero + section;
80 [_items addObject:[NSMutableArray arrayWithObject:item]];
81 if (_collectionViewController) {
82 [_collectionViewController.collectionView performBatchUpdates:^{
83 [_collectionViewController.collectionViewModel
84 addSectionWithIdentifier:sectionIdentifier];
85 [_collectionViewController.collectionView
86 insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
87 }
88 completion:^(BOOL){
lpromero 2017/01/11 09:47:04 Can't you just pass nil?
gambard 2017/01/11 15:10:38 Done.
89 }];
90 }
91 }
92 [[_items objectAtIndex:section] addObject:item];
lpromero 2017/01/11 09:47:04 Isn't this already done line 80? Plus, if section
gambard 2017/01/11 15:10:37 Acknowledged.
lpromero 2017/01/11 18:54:43 I don't understand how this doesn't crash if you p
gambard 2017/01/12 08:46:16 If you look at line 59 of the patch 5, there is if
lpromero 2017/01/12 11:43:35 Fair enough.
93 if (_collectionViewController) {
94 [_collectionViewController.collectionViewModel addItem:item
95 toSectionWithIdentifier:sectionIdentifier];
96 [_collectionViewController.collectionView performBatchUpdates:^{
97 [_collectionViewController.collectionView insertItemsAtIndexPaths:@[
98 [NSIndexPath indexPathForRow:[[_items objectAtIndex:section] count] - 1
99 inSection:section]
100 ]];
101 }
102 completion:^(BOOL){
lpromero 2017/01/11 09:47:04 Idem, can you pass nil?
gambard 2017/01/11 15:10:37 Done.
103 }];
104 }
105 }
106
107 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698