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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/OptionalLeaf.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/OptionalLeaf.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/OptionalLeaf.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/OptionalLeaf.java
index 1a3b7ffa84d402635f3e701a50c10a6bc6b335ff..fe95e48e7e90c380b6cdbf1ddee706011752f1a6 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/OptionalLeaf.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/OptionalLeaf.java
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.ntp.cards;
import android.support.annotation.CallSuper;
+import org.chromium.base.Callback;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
/**
@@ -43,12 +44,17 @@ public abstract class OptionalLeaf extends ChildNode {
}
@Override
+ public void dismissItem(int position, Callback<String> itemRemovedCallback) {
+ checkIndex(position);
+ dismiss(itemRemovedCallback);
+ }
+
+ @Override
public int getDismissSiblingPosDelta(int position) {
checkIndex(position);
return 0;
}
-
/** @return Whether the optional item is currently visible. */
public final boolean isVisible() {
return mVisible;
@@ -86,9 +92,14 @@ public abstract class OptionalLeaf extends ChildNode {
@ItemViewType
protected abstract int getItemViewType();
- protected void checkIndex(int position) {
- if (position < 0 || position >= getItemCount()) {
- throw new IndexOutOfBoundsException(position + "/" + getItemCount());
- }
+ /**
+ * Dismiss this item. The default implementation asserts, as by default items can't be
+ * dismissed.
+ * @param itemRemovedCallback Should be called with the title of the dismissed item, to announce
+ * it for accessibility purposes.
+ * @see TreeNode#dismissItem
+ */
+ protected void dismiss(Callback<String> itemRemovedCallback) {
+ assert false;
}
}

Powered by Google App Engine
This is Rietveld 408576698