OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 package org.chromium.chrome.browser.ntp.snippets; | 4 package org.chromium.chrome.browser.ntp.snippets; |
5 | 5 |
6 import android.graphics.Bitmap; | 6 import android.graphics.Bitmap; |
7 | 7 |
8 import org.chromium.chrome.browser.ntp.cards.NewTabPageItem; | 8 import org.chromium.chrome.browser.ntp.cards.ItemViewType; |
| 9 import org.chromium.chrome.browser.ntp.cards.Leaf; |
9 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; | 10 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; |
10 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout.Con
tentSuggestionsCardLayoutEnum; | 11 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout.Con
tentSuggestionsCardLayoutEnum; |
11 | 12 |
12 /** | 13 /** |
13 * Represents the data for an article card on the NTP. | 14 * Represents the data for an article card on the NTP. |
14 */ | 15 */ |
15 public class SnippetArticle implements NewTabPageItem { | 16 public class SnippetArticle extends Leaf { |
16 /** The category of this article. */ | 17 /** The category of this article. */ |
17 public final int mCategory; | 18 public final int mCategory; |
18 | 19 |
19 /** The identifier for this article within the category - not necessarily un
ique globally. */ | 20 /** The identifier for this article within the category - not necessarily un
ique globally. */ |
20 public final String mIdWithinCategory; | 21 public final String mIdWithinCategory; |
21 | 22 |
22 /** The title of this article. */ | 23 /** The title of this article. */ |
23 public final String mTitle; | 24 public final String mTitle; |
24 | 25 |
25 /** The canonical publisher name (e.g., New York Times). */ | 26 /** The canonical publisher name (e.g., New York Times). */ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 SnippetArticle rhs = (SnippetArticle) other; | 82 SnippetArticle rhs = (SnippetArticle) other; |
82 return mCategory == rhs.mCategory && mIdWithinCategory.equals(rhs.mIdWit
hinCategory); | 83 return mCategory == rhs.mCategory && mIdWithinCategory.equals(rhs.mIdWit
hinCategory); |
83 } | 84 } |
84 | 85 |
85 @Override | 86 @Override |
86 public int hashCode() { | 87 public int hashCode() { |
87 return mCategory ^ mIdWithinCategory.hashCode(); | 88 return mCategory ^ mIdWithinCategory.hashCode(); |
88 } | 89 } |
89 | 90 |
90 @Override | 91 @Override |
91 public int getType() { | 92 @ItemViewType |
92 return NewTabPageItem.VIEW_TYPE_SNIPPET; | 93 public int getItemViewType() { |
| 94 return ItemViewType.SNIPPET; |
93 } | 95 } |
94 | 96 |
95 @Override | 97 @Override |
96 public void onBindViewHolder(NewTabPageViewHolder holder) { | 98 protected void onBindViewHolder(NewTabPageViewHolder holder) { |
97 assert holder instanceof SnippetArticleViewHolder; | 99 assert holder instanceof SnippetArticleViewHolder; |
98 ((SnippetArticleViewHolder) holder).onBindViewHolder(this); | 100 ((SnippetArticleViewHolder) holder).onBindViewHolder(this); |
99 } | 101 } |
100 | 102 |
| 103 @Override |
| 104 public SnippetArticle getSuggestionAt(int position) { |
| 105 if (position != 0) throw new IndexOutOfBoundsException(); |
| 106 |
| 107 return this; |
| 108 } |
| 109 |
101 /** | 110 /** |
102 * Returns this article's thumbnail as a {@link Bitmap}. Can return {@code n
ull} as it is | 111 * Returns this article's thumbnail as a {@link Bitmap}. Can return {@code n
ull} as it is |
103 * initially unset. | 112 * initially unset. |
104 */ | 113 */ |
105 public Bitmap getThumbnailBitmap() { | 114 public Bitmap getThumbnailBitmap() { |
106 return mThumbnailBitmap; | 115 return mThumbnailBitmap; |
107 } | 116 } |
108 | 117 |
109 /** Sets the thumbnail bitmap for this article. */ | 118 /** Sets the thumbnail bitmap for this article. */ |
110 public void setThumbnailBitmap(Bitmap bitmap) { | 119 public void setThumbnailBitmap(Bitmap bitmap) { |
111 mThumbnailBitmap = bitmap; | 120 mThumbnailBitmap = bitmap; |
112 } | 121 } |
113 | 122 |
114 /** Returns whether to track an impression for this article. */ | 123 /** Returns whether to track an impression for this article. */ |
115 public boolean trackImpression() { | 124 public boolean trackImpression() { |
116 // Track UMA only upon the first impression per life-time of this object
. | 125 // Track UMA only upon the first impression per life-time of this object
. |
117 if (mImpressionTracked) return false; | 126 if (mImpressionTracked) return false; |
118 mImpressionTracked = true; | 127 mImpressionTracked = true; |
119 return true; | 128 return true; |
120 } | 129 } |
121 | 130 |
122 @Override | 131 @Override |
123 public String toString() { | 132 public String toString() { |
124 // For debugging purposes. Displays the first 42 characters of the title
. | 133 // For debugging purposes. Displays the first 42 characters of the title
. |
125 return String.format("{%s, %1.42s}", getClass().getSimpleName(), mTitle)
; | 134 return String.format("{%s, %1.42s}", getClass().getSimpleName(), mTitle)
; |
126 } | 135 } |
127 } | 136 } |
OLD | NEW |