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 package org.chromium.chrome.browser.ntp.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
6 | 6 |
7 import org.chromium.base.VisibleForTesting; | 7 import org.chromium.base.VisibleForTesting; |
8 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; | 8 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; |
9 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu m; | 9 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu m; |
10 import org.chromium.chrome.browser.ntp.snippets.SectionHeader; | 10 import org.chromium.chrome.browser.ntp.snippets.SectionHeader; |
11 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | 11 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; |
12 import org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder; | |
12 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 13 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
13 | 14 |
14 import java.util.ArrayList; | 15 import java.util.ArrayList; |
15 import java.util.List; | 16 import java.util.List; |
16 | 17 |
17 /** | 18 /** |
18 * A group of suggestions, with a header, a status card, and a progress indicato r. | 19 * A group of suggestions, with a header, a status card, and a progress indicato r. |
19 */ | 20 */ |
20 public class SuggestionsSection extends InnerNode { | 21 public class SuggestionsSection extends InnerNode { |
21 private final List<TreeNode> mChildren = new ArrayList<>(); | 22 private final List<TreeNode> mChildren = new ArrayList<>(); |
22 private final List<SnippetArticle> mSuggestions = new ArrayList<>(); | 23 private final List<SnippetArticle> mSuggestions = new ArrayList<>(); |
23 private final SectionHeader mHeader; | 24 private final SectionHeader mHeader; |
25 private final TreeNode mSuggestionsList = new SuggestionsList(this, mSuggest ions); | |
24 private final StatusItem mStatus; | 26 private final StatusItem mStatus; |
25 private final ProgressItem mProgressIndicator = new ProgressItem(); | 27 private final ProgressItem mProgressIndicator = new ProgressItem(); |
26 private final ActionItem mMoreButton; | 28 private final ActionItem mMoreButton; |
27 private final SuggestionsCategoryInfo mCategoryInfo; | 29 private final SuggestionsCategoryInfo mCategoryInfo; |
28 | 30 |
29 public SuggestionsSection(NodeParent parent, SuggestionsCategoryInfo info) { | 31 public SuggestionsSection(NodeParent parent, SuggestionsCategoryInfo info) { |
30 super(parent); | 32 super(parent); |
31 mHeader = new SectionHeader(info.getTitle()); | 33 mHeader = new SectionHeader(info.getTitle()); |
32 mCategoryInfo = info; | 34 mCategoryInfo = info; |
33 mMoreButton = new ActionItem(info); | 35 mMoreButton = new ActionItem(info); |
34 mStatus = StatusItem.createNoSuggestionsItem(info); | 36 mStatus = StatusItem.createNoSuggestionsItem(info); |
35 resetChildren(); | 37 resetChildren(); |
36 } | 38 } |
37 | 39 |
40 private static class SuggestionsList extends ChildNode { | |
41 private final List<SnippetArticle> mSuggestions; | |
dgn
2016/10/21 17:13:30
I find it a bit weird that we have another referen
Bernhard Bauer
2016/10/22 16:43:47
Yeah, I considered that as well. I'm not sure what
| |
42 | |
43 public SuggestionsList(NodeParent parent, List<SnippetArticle> suggestio ns) { | |
44 super(parent); | |
45 mSuggestions = suggestions; | |
46 } | |
47 | |
48 @Override | |
49 public int getItemCount() { | |
50 return mSuggestions.size(); | |
51 } | |
52 | |
53 @Override | |
54 @ItemViewType | |
55 public int getItemViewType(int position) { | |
56 return ItemViewType.SNIPPET; | |
57 } | |
58 | |
59 @Override | |
60 public void onBindViewHolder(NewTabPageViewHolder holder, int position) { | |
61 assert holder instanceof SnippetArticleViewHolder; | |
62 ((SnippetArticleViewHolder) holder).onBindViewHolder(getSuggestionAt (position)); | |
63 } | |
64 | |
65 @Override | |
66 public SnippetArticle getSuggestionAt(int position) { | |
67 return mSuggestions.get(position); | |
68 } | |
69 | |
70 @Override | |
71 public int getDismissSiblingPosDelta(int position) { | |
72 return 0; | |
73 } | |
74 } | |
75 | |
38 @Override | 76 @Override |
39 protected List<TreeNode> getChildren() { | 77 protected List<TreeNode> getChildren() { |
40 return mChildren; | 78 return mChildren; |
41 } | 79 } |
42 | 80 |
43 private void resetChildren() { | 81 private void resetChildren() { |
44 mChildren.clear(); | 82 mChildren.clear(); |
45 mChildren.add(mHeader); | 83 mChildren.add(mHeader); |
46 mChildren.addAll(mSuggestions); | 84 mChildren.add(mSuggestionsList); |
47 | 85 |
48 if (mSuggestions.isEmpty()) mChildren.add(mStatus); | 86 if (mSuggestions.isEmpty()) mChildren.add(mStatus); |
49 if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) mChildren.a dd(mMoreButton); | 87 if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) mChildren.a dd(mMoreButton); |
50 if (mSuggestions.isEmpty()) mChildren.add(mProgressIndicator); | 88 if (mSuggestions.isEmpty()) mChildren.add(mProgressIndicator); |
51 } | 89 } |
52 | 90 |
53 public void removeSuggestion(SnippetArticle suggestion) { | 91 public void removeSuggestion(SnippetArticle suggestion) { |
54 int removedIndex = mSuggestions.indexOf(suggestion); | 92 int removedIndex = mSuggestions.indexOf(suggestion); |
55 if (removedIndex == -1) return; | 93 if (removedIndex == -1) return; |
56 | 94 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 @VisibleForTesting | 220 @VisibleForTesting |
183 ActionItem getActionItem() { | 221 ActionItem getActionItem() { |
184 return mMoreButton; | 222 return mMoreButton; |
185 } | 223 } |
186 | 224 |
187 @VisibleForTesting | 225 @VisibleForTesting |
188 StatusItem getStatusItem() { | 226 StatusItem getStatusItem() { |
189 return mStatus; | 227 return mStatus; |
190 } | 228 } |
191 } | 229 } |
OLD | NEW |