| 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.test.util.browser.suggestions; | 5 package org.chromium.chrome.test.util.browser.suggestions; |
| 6 | 6 |
| 7 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
| 8 | 8 |
| 9 import org.chromium.base.Callback; | 9 import org.chromium.base.Callback; |
| 10 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; | 11 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; |
| 12 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; | 12 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; |
| 13 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; | 13 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; |
| 14 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu
m; | |
| 15 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | 14 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; |
| 16 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 15 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
| 17 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 16 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
| 18 | 17 |
| 19 import java.util.ArrayList; | 18 import java.util.ArrayList; |
| 20 import java.util.Collections; | 19 import java.util.Collections; |
| 21 import java.util.HashMap; | 20 import java.util.HashMap; |
| 22 import java.util.LinkedHashMap; | 21 import java.util.LinkedHashMap; |
| 23 import java.util.List; | 22 import java.util.List; |
| 24 import java.util.Map; | 23 import java.util.Map; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 39 | 38 |
| 40 private final List<Integer> mDismissedCategories = new ArrayList<>(); | 39 private final List<Integer> mDismissedCategories = new ArrayList<>(); |
| 41 private final Map<Integer, List<SnippetArticle>> mDismissedCategorySuggestio
ns = | 40 private final Map<Integer, List<SnippetArticle>> mDismissedCategorySuggestio
ns = |
| 42 new HashMap<>(); | 41 new HashMap<>(); |
| 43 private final Map<Integer, Integer> mDismissedCategoryStatus = new LinkedHas
hMap<>(); | 42 private final Map<Integer, Integer> mDismissedCategoryStatus = new LinkedHas
hMap<>(); |
| 44 private final Map<Integer, SuggestionsCategoryInfo> mDismissedCategoryInfo =
new HashMap<>(); | 43 private final Map<Integer, SuggestionsCategoryInfo> mDismissedCategoryInfo =
new HashMap<>(); |
| 45 | 44 |
| 46 /** | 45 /** |
| 47 * Sets the status to be returned for a given category. | 46 * Sets the status to be returned for a given category. |
| 48 */ | 47 */ |
| 49 public void setStatusForCategory(@CategoryInt int category, @CategoryStatusE
num int status) { | 48 public void setStatusForCategory(@CategoryInt int category, @CategoryStatus
int status) { |
| 50 mCategoryStatus.put(category, status); | 49 mCategoryStatus.put(category, status); |
| 51 if (status == CategoryStatus.NOT_PROVIDED) { | 50 if (status == CategoryStatus.NOT_PROVIDED) { |
| 52 mCategories.remove(Integer.valueOf(category)); | 51 mCategories.remove(Integer.valueOf(category)); |
| 53 } else if (!mCategories.contains(category)) { | 52 } else if (!mCategories.contains(category)) { |
| 54 mCategories.add(category); | 53 mCategories.add(category); |
| 55 } | 54 } |
| 56 if (mObserver != null) mObserver.onCategoryStatusChanged(category, statu
s); | 55 if (mObserver != null) mObserver.onCategoryStatusChanged(category, statu
s); |
| 57 } | 56 } |
| 58 | 57 |
| 59 /** | 58 /** |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 186 } |
| 188 | 187 |
| 189 @Override | 188 @Override |
| 190 public int[] getCategories() { | 189 public int[] getCategories() { |
| 191 int[] result = new int[mCategories.size()]; | 190 int[] result = new int[mCategories.size()]; |
| 192 int index = 0; | 191 int index = 0; |
| 193 for (int id : mCategories) result[index++] = id; | 192 for (int id : mCategories) result[index++] = id; |
| 194 return result; | 193 return result; |
| 195 } | 194 } |
| 196 | 195 |
| 197 @CategoryStatusEnum | 196 @CategoryStatus |
| 198 @Override | 197 @Override |
| 199 public int getCategoryStatus(@CategoryInt int category) { | 198 public int getCategoryStatus(@CategoryInt int category) { |
| 200 return mCategoryStatus.get(category); | 199 return mCategoryStatus.get(category); |
| 201 } | 200 } |
| 202 | 201 |
| 203 @Override | 202 @Override |
| 204 public SuggestionsCategoryInfo getCategoryInfo(int category) { | 203 public SuggestionsCategoryInfo getCategoryInfo(int category) { |
| 205 return mCategoryInfo.get(category); | 204 return mCategoryInfo.get(category); |
| 206 } | 205 } |
| 207 | 206 |
| 208 @Override | 207 @Override |
| 209 public List<SnippetArticle> getSuggestionsForCategory(int category) { | 208 public List<SnippetArticle> getSuggestionsForCategory(int category) { |
| 210 if (!SnippetsBridge.isCategoryStatusAvailable(mCategoryStatus.get(catego
ry))) { | 209 if (!SnippetsBridge.isCategoryStatusAvailable(mCategoryStatus.get(catego
ry))) { |
| 211 return Collections.emptyList(); | 210 return Collections.emptyList(); |
| 212 } | 211 } |
| 213 List<SnippetArticle> result = mSuggestions.get(category); | 212 List<SnippetArticle> result = mSuggestions.get(category); |
| 214 return result == null ? Collections.<SnippetArticle>emptyList() : new Ar
rayList<>(result); | 213 return result == null ? Collections.<SnippetArticle>emptyList() : new Ar
rayList<>(result); |
| 215 } | 214 } |
| 216 } | 215 } |
| OLD | NEW |