OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.ntp; | |
6 | |
7 import android.app.Activity; | |
8 import android.content.Context; | |
9 import android.view.LayoutInflater; | |
10 import android.view.View; | |
11 | |
12 import org.chromium.base.ApiCompatibilityUtils; | |
13 import org.chromium.chrome.R; | |
14 import org.chromium.chrome.browser.NativePage; | |
15 import org.chromium.chrome.browser.UrlConstants; | |
16 import org.chromium.chrome.browser.ntp.InterestsService.GetInterestsCallback; | |
17 import org.chromium.chrome.browser.ntp.InterestsService.Interest; | |
18 import org.chromium.chrome.browser.profiles.Profile; | |
19 import org.chromium.chrome.browser.tab.Tab; | |
20 import org.chromium.ui.widget.Toast; | |
21 | |
22 import java.util.Arrays; | |
23 import java.util.List; | |
24 | |
25 /** | |
26 * List the interests of the user. When an interest is clicked the user is redir ected 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.
| |
27 * for that subject. | |
28 */ | |
29 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.
| |
30 | |
31 private static final String TAG = "interests_page"; | |
32 | |
33 private final InterestsView mPageView; | |
34 private final String mTitle; | |
35 private final int mBackgroundColor; | |
36 private final int mThemeColor; | |
37 | |
38 /** | |
39 * 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.
| |
40 * | |
41 * @param context The view context for showing the page. | |
42 * @param tab The tab from which interests page is loaded. | |
43 * @param profile The profile from which to load interests. | |
44 * @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.
| |
45 */ | |
46 public InterestsPage(final Context context, Tab tab, Profile profile, Activi ty activity) { | |
47 mTitle = context.getResources().getString(R.string.ntp_interests); | |
48 mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources( ), R.color.ntp_bg); | |
49 mThemeColor = ApiCompatibilityUtils.getColor( | |
50 activity.getResources(), R.color.default_primary_color); | |
51 | |
52 LayoutInflater inflater = LayoutInflater.from(context); | |
53 | |
54 mPageView = (InterestsView) inflater.inflate(R.layout.interests_page, nu ll); | |
newt (away)
2015/12/12 00:30:31
You can use the View.inflate() convenience method:
PEConn
2015/12/14 17:05:15
Done.
| |
55 | |
56 new InterestsService(profile).getInterests( | |
57 new GetInterestsCallback() { | |
58 @Override | |
59 public void onInterestsAvailableCallback(Interest[] interest s) { | |
newt (away)
2015/12/12 00:30:31
style nit: remove "Callback" from this method name
PEConn
2015/12/14 17:05:15
Done.
| |
60 if (interests == null) { | |
61 Toast toast = Toast.makeText(context, | |
62 R.string.ntp_no_interests_toast, Toast.LENGT H_SHORT); | |
63 toast.show(); | |
64 return; | |
65 } | |
66 List<Interest> interestList = Arrays.asList(interests); | |
67 | |
68 mPageView.setInterests(interestList); | |
69 } | |
70 }); | |
71 } | |
72 | |
73 public void setListener(InterestsClickListener listener) { | |
74 mPageView.setListener(listener); | |
75 } | |
76 | |
77 /** | |
78 * Interface to be notified when the user clicks on a interest. | |
79 **/ | |
80 public interface InterestsClickListener { | |
81 /** | |
82 * 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.
| |
83 * | |
84 * @param name The name of the selected interest. | |
85 */ | |
86 void onInterestClicked(String name); | |
87 } | |
88 | |
89 @Override | |
90 public String getTitle() { | |
91 return mTitle; | |
92 } | |
93 | |
94 @Override | |
95 public int getBackgroundColor() { | |
96 return mBackgroundColor; | |
97 } | |
98 | |
99 @Override | |
100 public int getThemeColor() { | |
101 return mThemeColor; | |
102 } | |
103 @Override | |
104 public View getView() { | |
105 return mPageView; | |
106 } | |
107 | |
108 | |
109 @Override | |
110 public void destroy() { | |
111 } | |
112 | |
113 @Override | |
114 public String getHost() { | |
115 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.
| |
116 } | |
117 | |
118 @Override | |
119 public String getUrl() { | |
120 return UrlConstants.INTERESTS_URL; | |
121 } | |
122 | |
123 @Override | |
124 public void updateForUrl(String url) { | |
125 } | |
126 } | |
OLD | NEW |