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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPageView.java

Issue 1351303003: Add the UI for the Interests Prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ntp-interests-jni
Patch Set: Fetch the oauth token from the native code. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPageView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPageView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPageView.java
new file mode 100644
index 0000000000000000000000000000000000000000..8b3a405b9ee14e2788d51fea0eed5f1d1ae58aa8
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/InterestsPageView.java
@@ -0,0 +1,110 @@
+// 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.content.Context;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.util.LruCache;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.GridView;
+import android.widget.LinearLayout;
+
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ntp.InterestsItemView.DrawingData;
+import org.chromium.chrome.browser.ntp.InterestsPage.InterestsListener;
+import org.chromium.chrome.browser.ntp.InterestsService.Interest;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * The user's interests, displayed with a two collumn grid view.
Bernhard Bauer 2015/09/29 14:33:28 Nit: "column".
PEConn 2015/11/18 15:26:57 Done.
+ */
+public class InterestsPageView extends LinearLayout {
Bernhard Bauer 2015/09/29 14:33:28 Just InterestsView? InterestsPageView implies some
PEConn 2015/11/18 15:26:57 Done.
+
+ private InterestsListener mListener;
+ private GridView mInterestsGrid;
+ private InterestsListAdapter mAdapter;
Bernhard Bauer 2015/09/29 14:33:28 Make this final as well?
PEConn 2015/11/18 15:26:57 Done.
+ private final LruCache<String, Drawable> mImageCache;
+ private DrawingData mDrawingData;
+
+ public InterestsPageView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mAdapter = new InterestsListAdapter(context);
+ mImageCache = new LruCache<>(30);
+ }
+
+ public void setListener(InterestsListener listener) {
+ mListener = listener;
+ }
+
+ public void setInterests(List<Interest> interests) {
+ mAdapter.setInterests(interests);
+ mAdapter.notifyDataSetChanged();
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mInterestsGrid = (GridView) findViewById(R.id.interests_list_view);
+ mInterestsGrid.setAdapter(mAdapter);
+ }
+
+ private class InterestsListAdapter extends BaseAdapter {
newt (away) 2015/09/29 17:33:22 Extend ArrayAdapter instead of BaseAdapter. ArrayA
+
+ private List<Interest> mInterests = Collections.emptyList();
+ private Context mContext = null;
+
+ public InterestsListAdapter(Context context) {
+ mContext = context;
+ }
+
+ public void setInterests(List<Interest> interests) {
+ mInterests = interests;
+ }
+
+ @Override
+ public int getCount() {
+ return mInterests.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mInterests.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (mDrawingData == null) {
+ mDrawingData = new InterestsItemView.DrawingData(getContext());
+ }
+ Interest interest = mInterests.get(position);
+
+ if (convertView instanceof InterestsItemView) {
+ InterestsItemView view = (InterestsItemView) convertView;
Bernhard Bauer 2015/09/29 14:33:28 You could extract this variable and the return sta
PEConn 2015/11/18 15:26:57 Done.
+ view.reset(interest.getName(), interest.getImageUrl());
+ return view;
+ } else {
+ InterestsItemView itemView = new InterestsItemView(mContext, interest.getName(),
+ interest.getImageUrl(), mListener, mImageCache, mDrawingData);
+ return itemView;
+ }
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698