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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java

Issue 2570913003: [Android NTP] Move dismissing items into the TreeNode interface. (Closed)
Patch Set: comments Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java
index 0c57425be4eae349cdee5aaf94c3c5987a1a61da..f54db9da5637255947a33701d2119168626456af 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/InnerNode.java
@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.ntp.cards;
+import org.chromium.base.Callback;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
@@ -17,16 +18,16 @@ public class InnerNode extends ChildNode implements NodeParent {
private final List<TreeNode> mChildren = new ArrayList<>();
private int getChildIndexForPosition(int position) {
- if (position < 0) {
- throw new IndexOutOfBoundsException(Integer.toString(position));
- }
+ checkIndex(position);
int numItems = 0;
int numChildren = mChildren.size();
for (int i = 0; i < numChildren; i++) {
numItems += mChildren.get(i).getItemCount();
if (position < numItems) return i;
}
- throw new IndexOutOfBoundsException(position + "/" + numItems);
+ // checkIndex() will have caught this case already.
+ assert false;
+ return -1;
}
private int getStartingOffsetForChildIndex(int childIndex) {
@@ -84,6 +85,13 @@ public class InnerNode extends ChildNode implements NodeParent {
}
@Override
+ public void dismissItem(int position, Callback<String> itemRemovedCallback) {
+ int index = getChildIndexForPosition(position);
+ getChildren().get(index).dismissItem(
+ position - getStartingOffsetForChildIndex(index), itemRemovedCallback);
+ }
+
+ @Override
public int getDismissSiblingPosDelta(int position) {
int index = getChildIndexForPosition(position);
return mChildren.get(index).getDismissSiblingPosDelta(

Powered by Google App Engine
This is Rietveld 408576698