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 android.support.annotation.Nullable; | 7 import android.support.annotation.Nullable; |
8 | 8 |
9 import org.chromium.base.Callback; | 9 import org.chromium.base.Callback; |
10 import org.chromium.base.VisibleForTesting; | 10 import org.chromium.base.VisibleForTesting; |
11 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder.PartialBindCal
lback; | 11 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder.PartialBindCal
lback; |
12 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | |
13 | 12 |
14 import java.util.ArrayList; | 13 import java.util.ArrayList; |
15 import java.util.Collections; | 14 import java.util.Collections; |
16 import java.util.HashSet; | 15 import java.util.HashSet; |
17 import java.util.List; | 16 import java.util.List; |
18 import java.util.Set; | 17 import java.util.Set; |
19 | 18 |
20 /** | 19 /** |
21 * An inner node in the tree: the root of a subtree, with a list of child nodes. | 20 * An inner node in the tree: the root of a subtree, with a list of child nodes. |
22 */ | 21 */ |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 76 } |
78 | 77 |
79 @Override | 78 @Override |
80 public void onBindViewHolder(NewTabPageViewHolder holder, int position) { | 79 public void onBindViewHolder(NewTabPageViewHolder holder, int position) { |
81 int index = getChildIndexForPosition(position); | 80 int index = getChildIndexForPosition(position); |
82 mChildren.get(index).onBindViewHolder( | 81 mChildren.get(index).onBindViewHolder( |
83 holder, position - getStartingOffsetForChildIndex(index)); | 82 holder, position - getStartingOffsetForChildIndex(index)); |
84 } | 83 } |
85 | 84 |
86 @Override | 85 @Override |
87 public SnippetArticle getSuggestionAt(int position) { | |
88 int index = getChildIndexForPosition(position); | |
89 return mChildren.get(index).getSuggestionAt( | |
90 position - getStartingOffsetForChildIndex(index)); | |
91 } | |
92 | |
93 @Override | |
94 public Set<Integer> getItemDismissalGroup(int position) { | 86 public Set<Integer> getItemDismissalGroup(int position) { |
95 int index = getChildIndexForPosition(position); | 87 int index = getChildIndexForPosition(position); |
96 int offset = getStartingOffsetForChildIndex(index); | 88 int offset = getStartingOffsetForChildIndex(index); |
97 Set<Integer> itemDismissalGroup = | 89 Set<Integer> itemDismissalGroup = |
98 getChildren().get(index).getItemDismissalGroup(position - offset
); | 90 getChildren().get(index).getItemDismissalGroup(position - offset
); |
99 return offsetBy(itemDismissalGroup, offset); | 91 return offsetBy(itemDismissalGroup, offset); |
100 } | 92 } |
101 | 93 |
102 @Override | 94 @Override |
103 public void dismissItem(int position, Callback<String> itemRemovedCallback)
{ | 95 public void dismissItem(int position, Callback<String> itemRemovedCallback)
{ |
104 int index = getChildIndexForPosition(position); | 96 int index = getChildIndexForPosition(position); |
105 getChildren().get(index).dismissItem( | 97 getChildren().get(index).dismissItem( |
106 position - getStartingOffsetForChildIndex(index), itemRemovedCal
lback); | 98 position - getStartingOffsetForChildIndex(index), itemRemovedCal
lback); |
107 } | 99 } |
108 | 100 |
109 @Override | 101 @Override |
| 102 public void visitItems(NodeVisitor visitor) { |
| 103 for (TreeNode child : getChildren()) { |
| 104 child.visitItems(visitor); |
| 105 } |
| 106 } |
| 107 |
| 108 @Override |
110 public void onItemRangeChanged( | 109 public void onItemRangeChanged( |
111 TreeNode child, int index, int count, @Nullable PartialBindCallback
callback) { | 110 TreeNode child, int index, int count, @Nullable PartialBindCallback
callback) { |
112 notifyItemRangeChanged(getStartingOffsetForChild(child) + index, count,
callback); | 111 notifyItemRangeChanged(getStartingOffsetForChild(child) + index, count,
callback); |
113 } | 112 } |
114 | 113 |
115 @Override | 114 @Override |
116 public void onItemRangeInserted(TreeNode child, int index, int count) { | 115 public void onItemRangeInserted(TreeNode child, int index, int count) { |
117 notifyItemRangeInserted(getStartingOffsetForChild(child) + index, count)
; | 116 notifyItemRangeInserted(getStartingOffsetForChild(child) + index, count)
; |
118 } | 117 } |
119 | 118 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return Collections.singleton(set.iterator().next() + offset); | 197 return Collections.singleton(set.iterator().next() + offset); |
199 } | 198 } |
200 | 199 |
201 Set<Integer> offsetSet = new HashSet<>(); | 200 Set<Integer> offsetSet = new HashSet<>(); |
202 for (int value : set) { | 201 for (int value : set) { |
203 offsetSet.add(value + offset); | 202 offsetSet.add(value + offset); |
204 } | 203 } |
205 return offsetSet; | 204 return offsetSet; |
206 } | 205 } |
207 } | 206 } |
OLD | NEW |