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); |
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 class SuggestionsList extends ChildNode { |
| 41 public SuggestionsList(NodeParent parent) { |
| 42 super(parent); |
| 43 } |
| 44 |
| 45 @Override |
| 46 public int getItemCount() { |
| 47 return mSuggestions.size(); |
| 48 } |
| 49 |
| 50 @Override |
| 51 @ItemViewType |
| 52 public int getItemViewType(int position) { |
| 53 return ItemViewType.SNIPPET; |
| 54 } |
| 55 |
| 56 @Override |
| 57 public void onBindViewHolder(NewTabPageViewHolder holder, int position)
{ |
| 58 assert holder instanceof SnippetArticleViewHolder; |
| 59 ((SnippetArticleViewHolder) holder).onBindViewHolder(getSuggestionAt
(position)); |
| 60 } |
| 61 |
| 62 @Override |
| 63 public SnippetArticle getSuggestionAt(int position) { |
| 64 return mSuggestions.get(position); |
| 65 } |
| 66 |
| 67 @Override |
| 68 public int getDismissSiblingPosDelta(int position) { |
| 69 return 0; |
| 70 } |
| 71 } |
| 72 |
38 @Override | 73 @Override |
39 protected List<TreeNode> getChildren() { | 74 protected List<TreeNode> getChildren() { |
40 return mChildren; | 75 return mChildren; |
41 } | 76 } |
42 | 77 |
43 private void resetChildren() { | 78 private void resetChildren() { |
44 mChildren.clear(); | 79 mChildren.clear(); |
45 mChildren.add(mHeader); | 80 mChildren.add(mHeader); |
46 mChildren.addAll(mSuggestions); | 81 mChildren.add(mSuggestionsList); |
47 | 82 |
48 if (mSuggestions.isEmpty()) mChildren.add(mStatus); | 83 if (mSuggestions.isEmpty()) mChildren.add(mStatus); |
49 if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) mChildren.a
dd(mMoreButton); | 84 if (mCategoryInfo.hasMoreButton() || mSuggestions.isEmpty()) mChildren.a
dd(mMoreButton); |
50 if (mSuggestions.isEmpty()) mChildren.add(mProgressIndicator); | 85 if (mSuggestions.isEmpty()) mChildren.add(mProgressIndicator); |
51 } | 86 } |
52 | 87 |
53 public void removeSuggestion(SnippetArticle suggestion) { | 88 public void removeSuggestion(SnippetArticle suggestion) { |
54 int removedIndex = mSuggestions.indexOf(suggestion); | 89 int removedIndex = mSuggestions.indexOf(suggestion); |
55 if (removedIndex == -1) return; | 90 if (removedIndex == -1) return; |
56 | 91 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 @VisibleForTesting | 217 @VisibleForTesting |
183 ActionItem getActionItem() { | 218 ActionItem getActionItem() { |
184 return mMoreButton; | 219 return mMoreButton; |
185 } | 220 } |
186 | 221 |
187 @VisibleForTesting | 222 @VisibleForTesting |
188 StatusItem getStatusItem() { | 223 StatusItem getStatusItem() { |
189 return mStatus; | 224 return mStatus; |
190 } | 225 } |
191 } | 226 } |
OLD | NEW |