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.CallSuper; | 7 import android.support.annotation.CallSuper; |
8 import android.support.annotation.Nullable; | 8 import android.support.annotation.Nullable; |
9 | 9 |
10 import org.chromium.base.Callback; | 10 import org.chromium.base.Callback; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 @Override | 131 @Override |
132 public void onBindViewHolder(NewTabPageViewHolder holder, int position)
{ | 132 public void onBindViewHolder(NewTabPageViewHolder holder, int position)
{ |
133 checkIndex(position); | 133 checkIndex(position); |
134 assert holder instanceof SnippetArticleViewHolder; | 134 assert holder instanceof SnippetArticleViewHolder; |
135 SnippetArticle suggestion = getSuggestionAt(position); | 135 SnippetArticle suggestion = getSuggestionAt(position); |
136 mSuggestionsRanker.rankSuggestion(suggestion); | 136 mSuggestionsRanker.rankSuggestion(suggestion); |
137 ((SnippetArticleViewHolder) holder).onBindViewHolder(suggestion, mCa
tegoryInfo); | 137 ((SnippetArticleViewHolder) holder).onBindViewHolder(suggestion, mCa
tegoryInfo); |
138 } | 138 } |
139 | 139 |
140 @Override | |
141 public SnippetArticle getSuggestionAt(int position) { | 140 public SnippetArticle getSuggestionAt(int position) { |
142 return mSuggestions.get(position); | 141 return mSuggestions.get(position); |
143 } | 142 } |
144 | 143 |
145 public void clear() { | 144 public void clear() { |
146 int itemCount = mSuggestions.size(); | 145 int itemCount = mSuggestions.size(); |
147 if (itemCount == 0) return; | 146 if (itemCount == 0) return; |
148 | 147 |
149 mSuggestions.clear(); | 148 mSuggestions.clear(); |
150 notifyItemRangeRemoved(0, itemCount); | 149 notifyItemRangeRemoved(0, itemCount); |
(...skipping 23 matching lines...) Expand all Loading... |
174 notifyItemRemoved(position); | 173 notifyItemRemoved(position); |
175 return suggestion; | 174 return suggestion; |
176 } | 175 } |
177 | 176 |
178 @Override | 177 @Override |
179 public Iterator<SnippetArticle> iterator() { | 178 public Iterator<SnippetArticle> iterator() { |
180 return mSuggestions.iterator(); | 179 return mSuggestions.iterator(); |
181 } | 180 } |
182 | 181 |
183 @Override | 182 @Override |
| 183 public void visitItems(NodeVisitor visitor) { |
| 184 for (SnippetArticle suggestion : mSuggestions) { |
| 185 visitor.visitSuggestion(suggestion); |
| 186 } |
| 187 } |
| 188 |
| 189 @Override |
184 public Set<Integer> getItemDismissalGroup(int position) { | 190 public Set<Integer> getItemDismissalGroup(int position) { |
185 return Collections.singleton(position); | 191 return Collections.singleton(position); |
186 } | 192 } |
187 | 193 |
188 @Override | 194 @Override |
189 public void dismissItem(int position, Callback<String> itemRemovedCallba
ck) { | 195 public void dismissItem(int position, Callback<String> itemRemovedCallba
ck) { |
190 checkIndex(position); | 196 checkIndex(position); |
191 SuggestionsSource suggestionsSource = mUiDelegate.getSuggestionsSour
ce(); | 197 SuggestionsSource suggestionsSource = mUiDelegate.getSuggestionsSour
ce(); |
192 if (suggestionsSource == null) { | 198 if (suggestionsSource == null) { |
193 // It is possible for this method to be called after the NewTabP
age has had | 199 // It is possible for this method to be called after the NewTabP
age has had |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 int i = 0; | 322 int i = 0; |
317 for (SnippetArticle suggestion : mSuggestionsList) { | 323 for (SnippetArticle suggestion : mSuggestionsList) { |
318 if (suggestion.mIdWithinCategory.equals(idWithinCategory)) { | 324 if (suggestion.mIdWithinCategory.equals(idWithinCategory)) { |
319 mSuggestionsList.remove(i); | 325 mSuggestionsList.remove(i); |
320 return; | 326 return; |
321 } | 327 } |
322 i++; | 328 i++; |
323 } | 329 } |
324 } | 330 } |
325 | 331 |
326 public boolean hasSuggestions() { | 332 private boolean hasSuggestions() { |
327 return mSuggestionsList.getItemCount() != 0; | 333 return mSuggestionsList.getItemCount() != 0; |
328 } | 334 } |
329 | 335 |
330 public int getSuggestionsCount() { | 336 public int getSuggestionsCount() { |
331 return mSuggestionsList.getItemCount(); | 337 return mSuggestionsList.getItemCount(); |
332 } | 338 } |
333 | 339 |
334 public boolean isDataStale() { | 340 public boolean isDataStale() { |
335 return mIsDataStale; | 341 return mIsDataStale; |
336 } | 342 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 public void onSuggestionOfflineIdChanged(SnippetArticle suggestion, @Nul
lable Long id) { | 540 public void onSuggestionOfflineIdChanged(SnippetArticle suggestion, @Nul
lable Long id) { |
535 mSuggestionsList.updateSuggestionOfflineId(suggestion, id); | 541 mSuggestionsList.updateSuggestionOfflineId(suggestion, id); |
536 } | 542 } |
537 | 543 |
538 @Override | 544 @Override |
539 public Iterable<SnippetArticle> getOfflinableSuggestions() { | 545 public Iterable<SnippetArticle> getOfflinableSuggestions() { |
540 return mSuggestionsList; | 546 return mSuggestionsList; |
541 } | 547 } |
542 } | 548 } |
543 } | 549 } |
OLD | NEW |