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

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

Issue 2617133002: [Android NTP] Move more of the dismissal logic into the tree. (Closed)
Patch Set: annotation 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 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 9dd7967cfd014b9710b601d19ec961214fdd3ce0..fcb153e1775541d10ef41188d310666923ce0642 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
@@ -9,7 +9,10 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* An inner node in the tree: the root of a subtree, with a list of child nodes.
@@ -85,17 +88,19 @@ public class InnerNode extends ChildNode implements NodeParent {
}
@Override
- public void dismissItem(int position, Callback<String> itemRemovedCallback) {
+ public Set<Integer> getItemDismissalGroup(int position) {
int index = getChildIndexForPosition(position);
- getChildren().get(index).dismissItem(
- position - getStartingOffsetForChildIndex(index), itemRemovedCallback);
+ int offset = getStartingOffsetForChildIndex(index);
+ Set<Integer> itemDismissalGroup =
+ getChildren().get(index).getItemDismissalGroup(position - offset);
+ return offsetBy(itemDismissalGroup, offset);
}
@Override
- public int getDismissSiblingPosDelta(int position) {
+ public void dismissItem(int position, Callback<String> itemRemovedCallback) {
int index = getChildIndexForPosition(position);
- return mChildren.get(index).getDismissSiblingPosDelta(
- position - getStartingOffsetForChildIndex(index));
+ getChildren().get(index).dismissItem(
+ position - getStartingOffsetForChildIndex(index), itemRemovedCallback);
}
@Override
@@ -172,4 +177,24 @@ public class InnerNode extends ChildNode implements NodeParent {
final List<TreeNode> getChildren() {
return mChildren;
}
+
+ /**
+ * Helper method that adds an offset value to a set of integers.
+ * @param set a set of integers
+ * @param offset the offset to add to the set.
+ * @return a set of integers with the {@code offset} value added to the input {@code set}.
+ */
+ private static Set<Integer> offsetBy(Set<Integer> set, int offset) {
+ // Optimizations for empty and singleton sets:
+ if (set.isEmpty()) return Collections.emptySet();
+ if (set.size() == 1) {
+ return Collections.singleton(set.iterator().next() + offset);
+ }
+
+ Set<Integer> offsetSet = new HashSet<>();
+ for (int value : set) {
+ offsetSet.add(value + offset);
+ }
+ return offsetSet;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698