Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..edea4d841e66c2f9d5b371e93bc91f0852dbed53 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPage.java |
| @@ -0,0 +1,126 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.ntp; |
| + |
| +import android.app.Activity; |
| +import android.content.Context; |
| +import android.view.LayoutInflater; |
| +import android.view.View; |
| + |
| +import org.chromium.base.ApiCompatibilityUtils; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.NativePage; |
| +import org.chromium.chrome.browser.UrlConstants; |
| +import org.chromium.chrome.browser.ntp.InterestsService.GetInterestsCallback; |
| +import org.chromium.chrome.browser.ntp.InterestsService.Interest; |
| +import org.chromium.chrome.browser.profiles.Profile; |
| +import org.chromium.chrome.browser.tab.Tab; |
| +import org.chromium.ui.widget.Toast; |
| + |
| +import java.util.Arrays; |
| +import java.util.List; |
| + |
| +/** |
| + * List the interests of the user. When an interest is clicked the user is redirected to a search |
|
newt (away)
2015/12/12 00:30:31
How about: "Displays a list of topics that we thin
PEConn
2015/12/14 17:05:15
Done.
|
| + * for that subject. |
| + */ |
| +public class InterestsPage implements NativePage { |
|
newt (away)
2015/12/12 00:30:31
With the current setup, this doesn't need to be a
PEConn
2015/12/14 17:05:15
Acknowledged.
|
| + |
| + private static final String TAG = "interests_page"; |
| + |
| + private final InterestsView mPageView; |
| + private final String mTitle; |
| + private final int mBackgroundColor; |
| + private final int mThemeColor; |
| + |
| + /** |
| + * Creates a InterestsPage to be shown in document mode. |
|
newt (away)
2015/12/12 00:30:31
only in document mode?? If so, why?
PEConn
2015/12/14 17:05:15
Done.
|
| + * |
| + * @param context The view context for showing the page. |
| + * @param tab The tab from which interests page is loaded. |
| + * @param profile The profile from which to load interests. |
| + * @param activity The activity from which the interests page is loaded. |
|
newt (away)
2015/12/12 00:30:31
You don't need the "activity" param. The context i
PEConn
2015/12/14 17:05:15
Done.
|
| + */ |
| + public InterestsPage(final Context context, Tab tab, Profile profile, Activity activity) { |
| + mTitle = context.getResources().getString(R.string.ntp_interests); |
| + mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources(), R.color.ntp_bg); |
| + mThemeColor = ApiCompatibilityUtils.getColor( |
| + activity.getResources(), R.color.default_primary_color); |
| + |
| + LayoutInflater inflater = LayoutInflater.from(context); |
| + |
| + mPageView = (InterestsView) inflater.inflate(R.layout.interests_page, null); |
|
newt (away)
2015/12/12 00:30:31
You can use the View.inflate() convenience method:
PEConn
2015/12/14 17:05:15
Done.
|
| + |
| + new InterestsService(profile).getInterests( |
| + new GetInterestsCallback() { |
| + @Override |
| + public void onInterestsAvailableCallback(Interest[] interests) { |
|
newt (away)
2015/12/12 00:30:31
style nit: remove "Callback" from this method name
PEConn
2015/12/14 17:05:15
Done.
|
| + if (interests == null) { |
| + Toast toast = Toast.makeText(context, |
| + R.string.ntp_no_interests_toast, Toast.LENGTH_SHORT); |
| + toast.show(); |
| + return; |
| + } |
| + List<Interest> interestList = Arrays.asList(interests); |
| + |
| + mPageView.setInterests(interestList); |
| + } |
| + }); |
| + } |
| + |
| + public void setListener(InterestsClickListener listener) { |
| + mPageView.setListener(listener); |
| + } |
| + |
| + /** |
| + * Interface to be notified when the user clicks on a interest. |
| + **/ |
| + public interface InterestsClickListener { |
| + /** |
| + * Called when a interest is selected. |
|
newt (away)
2015/12/12 00:30:31
s/a interest/an interest/ (and elsewhere too)
PEConn
2015/12/14 17:05:15
Done.
|
| + * |
| + * @param name The name of the selected interest. |
| + */ |
| + void onInterestClicked(String name); |
| + } |
| + |
| + @Override |
| + public String getTitle() { |
| + return mTitle; |
| + } |
| + |
| + @Override |
| + public int getBackgroundColor() { |
| + return mBackgroundColor; |
| + } |
| + |
| + @Override |
| + public int getThemeColor() { |
| + return mThemeColor; |
| + } |
| + @Override |
| + public View getView() { |
| + return mPageView; |
| + } |
| + |
| + |
| + @Override |
| + public void destroy() { |
| + } |
| + |
| + @Override |
| + public String getHost() { |
| + return "interests"; |
|
newt (away)
2015/12/12 00:30:31
If you're going to use a NativePage, this constant
PEConn
2015/12/14 17:05:15
Done.
|
| + } |
| + |
| + @Override |
| + public String getUrl() { |
| + return UrlConstants.INTERESTS_URL; |
| + } |
| + |
| + @Override |
| + public void updateForUrl(String url) { |
| + } |
| +} |