Chromium Code Reviews| 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.content.Context; | |
| 8 import android.graphics.drawable.Drawable; | |
| 9 import android.util.AttributeSet; | |
| 10 import android.util.LruCache; | |
| 11 import android.view.View; | |
| 12 import android.view.ViewGroup; | |
| 13 import android.widget.BaseAdapter; | |
| 14 import android.widget.GridView; | |
| 15 import android.widget.LinearLayout; | |
| 16 | |
| 17 import org.chromium.chrome.R; | |
| 18 import org.chromium.chrome.browser.ntp.InterestsItemView.DrawingData; | |
| 19 import org.chromium.chrome.browser.ntp.InterestsPage.InterestsListener; | |
| 20 import org.chromium.chrome.browser.ntp.InterestsService.Interest; | |
| 21 | |
| 22 import java.util.Collections; | |
| 23 import java.util.List; | |
| 24 | |
| 25 /** | |
| 26 * 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.
| |
| 27 */ | |
| 28 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.
| |
| 29 | |
| 30 private InterestsListener mListener; | |
| 31 private GridView mInterestsGrid; | |
| 32 private InterestsListAdapter mAdapter; | |
|
Bernhard Bauer
2015/09/29 14:33:28
Make this final as well?
PEConn
2015/11/18 15:26:57
Done.
| |
| 33 private final LruCache<String, Drawable> mImageCache; | |
| 34 private DrawingData mDrawingData; | |
| 35 | |
| 36 public InterestsPageView(Context context, AttributeSet attrs) { | |
| 37 super(context, attrs); | |
| 38 mAdapter = new InterestsListAdapter(context); | |
| 39 mImageCache = new LruCache<>(30); | |
| 40 } | |
| 41 | |
| 42 public void setListener(InterestsListener listener) { | |
| 43 mListener = listener; | |
| 44 } | |
| 45 | |
| 46 public void setInterests(List<Interest> interests) { | |
| 47 mAdapter.setInterests(interests); | |
| 48 mAdapter.notifyDataSetChanged(); | |
| 49 } | |
| 50 | |
| 51 @Override | |
| 52 protected void onFinishInflate() { | |
| 53 super.onFinishInflate(); | |
| 54 | |
| 55 mInterestsGrid = (GridView) findViewById(R.id.interests_list_view); | |
| 56 mInterestsGrid.setAdapter(mAdapter); | |
| 57 } | |
| 58 | |
| 59 private class InterestsListAdapter extends BaseAdapter { | |
|
newt (away)
2015/09/29 17:33:22
Extend ArrayAdapter instead of BaseAdapter. ArrayA
| |
| 60 | |
| 61 private List<Interest> mInterests = Collections.emptyList(); | |
| 62 private Context mContext = null; | |
| 63 | |
| 64 public InterestsListAdapter(Context context) { | |
| 65 mContext = context; | |
| 66 } | |
| 67 | |
| 68 public void setInterests(List<Interest> interests) { | |
| 69 mInterests = interests; | |
| 70 } | |
| 71 | |
| 72 @Override | |
| 73 public int getCount() { | |
| 74 return mInterests.size(); | |
| 75 } | |
| 76 | |
| 77 @Override | |
| 78 public Object getItem(int position) { | |
| 79 return mInterests.get(position); | |
| 80 } | |
| 81 | |
| 82 @Override | |
| 83 public long getItemId(int position) { | |
| 84 return position; | |
| 85 } | |
| 86 | |
| 87 @Override | |
| 88 public View getView(int position, View convertView, ViewGroup parent) { | |
| 89 if (mDrawingData == null) { | |
| 90 mDrawingData = new InterestsItemView.DrawingData(getContext()); | |
| 91 } | |
| 92 Interest interest = mInterests.get(position); | |
| 93 | |
| 94 if (convertView instanceof InterestsItemView) { | |
| 95 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.
| |
| 96 view.reset(interest.getName(), interest.getImageUrl()); | |
| 97 return view; | |
| 98 } else { | |
| 99 InterestsItemView itemView = new InterestsItemView(mContext, int erest.getName(), | |
| 100 interest.getImageUrl(), mListener, mImageCache, mDrawing Data); | |
| 101 return itemView; | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 @Override | |
| 106 public boolean hasStableIds() { | |
| 107 return false; | |
| 108 } | |
| 109 } | |
| 110 } | |
| OLD | NEW |