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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/OptionalLeaf.java

Issue 2860463002: [Suggestions] Remove TreeNode.getSuggestionAt() in favor of a visitor. (Closed)
Patch Set: review Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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.CallSuper; 7 import android.support.annotation.CallSuper;
8 8
9 import org.chromium.base.Callback; 9 import org.chromium.base.Callback;
10 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
11 10
12 import java.util.Collections; 11 import java.util.Collections;
13 import java.util.Set; 12 import java.util.Set;
14 13
15 /** 14 /**
16 * An optional leaf (i.e. single item) in the tree. Depending on its internal st ate (see 15 * An optional leaf (i.e. single item) in the tree. Depending on its internal st ate (see
17 * {@link #isVisible()}), the item will be present or absent from the tree, by m anipulating the 16 * {@link #isVisible()}), the item will be present or absent from the tree, by m anipulating the
18 * values returned from {@link ChildNode} methods. This allows the parent node t o not have to add or 17 * values returned from {@link ChildNode} methods. This allows the parent node t o not have to add or
19 * remove the optional leaf from its children manually. 18 * remove the optional leaf from its children manually.
20 * 19 *
(...skipping 13 matching lines...) Expand all
34 return getItemViewType(); 33 return getItemViewType();
35 } 34 }
36 35
37 @Override 36 @Override
38 public void onBindViewHolder(NewTabPageViewHolder holder, int position) { 37 public void onBindViewHolder(NewTabPageViewHolder holder, int position) {
39 checkIndex(position); 38 checkIndex(position);
40 onBindViewHolder(holder); 39 onBindViewHolder(holder);
41 } 40 }
42 41
43 @Override 42 @Override
44 public SnippetArticle getSuggestionAt(int position) {
45 checkIndex(position);
46 return null;
47 }
48
49 @Override
50 public Set<Integer> getItemDismissalGroup(int position) { 43 public Set<Integer> getItemDismissalGroup(int position) {
51 checkIndex(position); 44 checkIndex(position);
52 return canBeDismissed() ? Collections.singleton(0) : Collections.<Intege r>emptySet(); 45 return canBeDismissed() ? Collections.singleton(0) : Collections.<Intege r>emptySet();
53 } 46 }
54 47
55 @Override 48 @Override
56 public void dismissItem(int position, Callback<String> itemRemovedCallback) { 49 public void dismissItem(int position, Callback<String> itemRemovedCallback) {
57 checkIndex(position); 50 checkIndex(position);
58 dismiss(itemRemovedCallback); 51 dismiss(itemRemovedCallback);
59 } 52 }
60 53
54 @Override
55 public final void visitItems(NodeVisitor visitor) {
56 if (mVisible) visitOptionalItem(visitor);
57 }
58
61 /** @return Whether the optional item is currently visible. */ 59 /** @return Whether the optional item is currently visible. */
62 public final boolean isVisible() { 60 public final boolean isVisible() {
63 return mVisible; 61 return mVisible;
64 } 62 }
65 63
66 /** 64 /**
67 * Notifies the parents in the tree about whether the visibility of this lea f changed. Call this 65 * Notifies the parents in the tree about whether the visibility of this lea f changed. Call this
68 * after a data change that could affect the return value of {@link #isVisib le()}. The leaf is 66 * after a data change that could affect the return value of {@link #isVisib le()}. The leaf is
69 * initially considered hidden. 67 * initially considered hidden.
70 */ 68 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 /** 103 /**
106 * Dismiss this item. The default implementation asserts, as by default item s can't be 104 * Dismiss this item. The default implementation asserts, as by default item s can't be
107 * dismissed. 105 * dismissed.
108 * @param itemRemovedCallback Should be called with the title of the dismiss ed item, to announce 106 * @param itemRemovedCallback Should be called with the title of the dismiss ed item, to announce
109 * it for accessibility purposes. 107 * it for accessibility purposes.
110 * @see TreeNode#dismissItem 108 * @see TreeNode#dismissItem
111 */ 109 */
112 protected void dismiss(Callback<String> itemRemovedCallback) { 110 protected void dismiss(Callback<String> itemRemovedCallback) {
113 assert false; 111 assert false;
114 } 112 }
113
114 /**
115 * Visits this item. This method is called iff the optional item is currentl y visible.
116 * @param visitor The visitor with which to visit this item.
117 */
118 protected abstract void visitOptionalItem(NodeVisitor visitor);
115 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698