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.InterestsPage.InterestsListener; | |
| 19 import org.chromium.chrome.browser.ntp.InterestsService.Interest; | |
| 20 | |
| 21 import java.util.Collections; | |
| 22 import java.util.List; | |
| 23 | |
| 24 /** | |
| 25 * The user's interests, displayed with a two collumn grid view. | |
| 26 */ | |
| 27 public class InterestsPageView extends LinearLayout { | |
| 28 | |
| 29 /** | |
| 30 * @param context | |
| 31 * @param attrs | |
| 32 */ | |
|
Marc Treib
2015/09/18 13:26:03
Either remove, or fill and move down to the method
tache
2015/09/21 15:35:55
Done.
| |
| 33 private InterestsListener mListener; | |
| 34 | |
| 35 private final LruCache<String, Drawable> mImageCache; | |
| 36 | |
| 37 public InterestsPageView(Context context, AttributeSet attrs) { | |
| 38 super(context, attrs); | |
| 39 mAdapter = new InterestsListAdapter(context); | |
| 40 mImageCache = new LruCache<>(30); | |
| 41 } | |
| 42 | |
| 43 public void setListener(InterestsListener listener) { | |
| 44 mListener = listener; | |
| 45 } | |
| 46 | |
| 47 public void setInterests(List<Interest> interests) { | |
| 48 mAdapter.setInterests(interests); | |
| 49 mAdapter.notifyDataSetChanged(); | |
| 50 } | |
| 51 | |
| 52 private GridView mInterestsList; | |
|
Marc Treib
2015/09/18 13:26:03
List or Grid?
tache
2015/09/21 15:35:55
Done.
| |
| 53 private InterestsListAdapter mAdapter; | |
|
Marc Treib
2015/09/18 13:26:04
Move these up to the other member fields?
tache
2015/09/21 15:35:55
Done.
| |
| 54 | |
| 55 @Override | |
| 56 protected void onFinishInflate() { | |
| 57 super.onFinishInflate(); | |
| 58 | |
| 59 mInterestsList = (GridView) findViewById(R.id.interests_list_view); | |
| 60 mInterestsList.setAdapter(mAdapter); | |
| 61 } | |
| 62 | |
| 63 private class InterestsListAdapter extends BaseAdapter { | |
| 64 | |
| 65 private List<Interest> mInterests = Collections.emptyList(); | |
| 66 private Context mContext = null; | |
| 67 | |
| 68 public InterestsListAdapter(Context context) { | |
| 69 mContext = context; | |
| 70 } | |
| 71 | |
| 72 public void setInterests(List<Interest> interests) { | |
| 73 mInterests = interests; | |
| 74 } | |
| 75 | |
| 76 @Override | |
| 77 public int getCount() { | |
| 78 return mInterests.size(); | |
| 79 } | |
| 80 | |
| 81 @Override | |
| 82 public Object getItem(int position) { | |
| 83 return mInterests.get(position); | |
| 84 } | |
| 85 | |
| 86 @Override | |
| 87 public long getItemId(int position) { | |
| 88 return position; | |
| 89 } | |
| 90 | |
| 91 @Override | |
| 92 public View getView(int position, View convertView, ViewGroup parent) { | |
| 93 Interest interest = mInterests.get(position); | |
| 94 | |
| 95 if (convertView instanceof InterestsItemView) { | |
| 96 InterestsItemView view = (InterestsItemView) convertView; | |
| 97 view.reset(interest.getName(), interest.getImageUrl()); | |
| 98 return view; | |
| 99 } else { | |
| 100 InterestsItemView itemView = new InterestsItemView(mContext, int erest.getName(), | |
| 101 interest.getImageUrl(), | |
| 102 mListener, | |
| 103 mImageCache); | |
|
Marc Treib
2015/09/18 13:26:04
nit: line breaks are weird?
tache
2015/09/21 15:35:55
Done.
| |
| 104 return itemView; | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 @Override | |
| 109 public boolean hasStableIds() { | |
| 110 return false; | |
| 111 } | |
| 112 } | |
| 113 } | |
| OLD | NEW |