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

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

Issue 2274293002: 📰 Keep Suggestion sections in declaration order (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix render test Created 4 years, 3 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 org.chromium.chrome.browser.ChromeFeatureList;
8 import org.chromium.chrome.browser.ntp.cards.StatusItem.ActionDelegate; 7 import org.chromium.chrome.browser.ntp.cards.StatusItem.ActionDelegate;
9 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; 8 import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
10 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu m; 9 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu m;
11 import org.chromium.chrome.browser.ntp.snippets.KnownCategories;
12 import org.chromium.chrome.browser.ntp.snippets.SectionHeader; 10 import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
13 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; 11 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
14 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; 12 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
15 13
16 import java.util.ArrayList; 14 import java.util.ArrayList;
17 import java.util.Collections; 15 import java.util.Collections;
18 import java.util.List; 16 import java.util.List;
19 17
20 /** 18 /**
21 * A group of suggestions, with a header, a status card, and a progress indicato r. 19 * A group of suggestions, with a header, a status card, and a progress indicato r.
22 */ 20 */
23 public class SuggestionsSection implements ItemGroup { 21 public class SuggestionsSection implements ItemGroup {
24 private final List<SnippetArticle> mSuggestions = new ArrayList<>(); 22 private final List<SnippetArticle> mSuggestions = new ArrayList<>();
25 private final SectionHeader mHeader; 23 private final SectionHeader mHeader;
26 private StatusItem mStatus; 24 private StatusItem mStatus;
27 private final ProgressItem mProgressIndicator = new ProgressItem(); 25 private final ProgressItem mProgressIndicator = new ProgressItem();
28 private final ActionDelegate mActionDelegate; 26 private final ActionDelegate mActionDelegate;
29 private final ActionItem mMoreButton; 27 private final ActionItem mMoreButton;
28 @CategoryInt
29 private final int mCategory;
30 30
31 public SuggestionsSection(@CategoryInt int category, SuggestionsCategoryInfo info, 31 public SuggestionsSection(@CategoryInt int category, SuggestionsCategoryInfo info,
32 final NewTabPageAdapter adapter) { 32 final NewTabPageAdapter adapter) {
33 mHeader = new SectionHeader(info.getTitle()); 33 mHeader = new SectionHeader(info.getTitle());
34 // TODO(pke): Replace the condition with "info.hasMoreButton()" once all other categories 34 mCategory = category;
35 // are supported by the C++ backend, too.
36 // Right now, we hard-code all the sections that are handled in ActionLi stItem.
37 boolean showMoreButton = false;
38 if (category == KnownCategories.BOOKMARKS) {
39 showMoreButton = true;
40 } else if (category == KnownCategories.DOWNLOADS) {
41 showMoreButton = ChromeFeatureList.isEnabled("DownloadsUi");
42 }
43 mMoreButton = showMoreButton ? new ActionItem(category) : null;
44 35
45 // TODO(dgn): Properly define strings, actions, etc. for each section an d category type. 36 // TODO(dgn): Properly define strings, actions, etc. for each section an d category type.
46 if (showMoreButton) { 37 if (info.hasMoreButton()) {
38 mMoreButton = new ActionItem(category);
47 mActionDelegate = null; 39 mActionDelegate = null;
48 } else { 40 } else {
41 mMoreButton = null;
49 mActionDelegate = new ActionDelegate() { 42 mActionDelegate = new ActionDelegate() {
50 @Override 43 @Override
51 public void onButtonTapped() { 44 public void onButtonTapped() {
52 adapter.reloadSnippets(); 45 adapter.reloadSnippets();
53 } 46 }
54 }; 47 };
55 } 48 }
56 } 49 }
57 50
58 @Override 51 @Override
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 93
101 /** Sets the status for the section. Some statuses can cause the suggestions to be cleared. */ 94 /** Sets the status for the section. Some statuses can cause the suggestions to be cleared. */
102 public void setStatus(@CategoryStatusEnum int status) { 95 public void setStatus(@CategoryStatusEnum int status) {
103 mStatus = StatusItem.create(status, mActionDelegate); 96 mStatus = StatusItem.create(status, mActionDelegate);
104 97
105 if (!SnippetsBridge.isCategoryStatusAvailable(status)) mSuggestions.clea r(); 98 if (!SnippetsBridge.isCategoryStatusAvailable(status)) mSuggestions.clea r();
106 99
107 mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status)); 100 mProgressIndicator.setVisible(SnippetsBridge.isCategoryLoading(status));
108 } 101 }
109 102
103 public int getCategory() {
104 return mCategory;
105 }
106
110 private void copyThumbnails(List<SnippetArticle> suggestions) { 107 private void copyThumbnails(List<SnippetArticle> suggestions) {
111 for (SnippetArticle suggestion : suggestions) { 108 for (SnippetArticle suggestion : suggestions) {
112 int index = mSuggestions.indexOf(suggestion); 109 int index = mSuggestions.indexOf(suggestion);
113 if (index == -1) continue; 110 if (index == -1) continue;
114 111
115 suggestion.setThumbnailBitmap(mSuggestions.get(index).getThumbnailBi tmap()); 112 suggestion.setThumbnailBitmap(mSuggestions.get(index).getThumbnailBi tmap());
116 } 113 }
117 } 114 }
118 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698