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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticle.java

Issue 2439683003: [Android NTP] Move suggestions in SuggestionSection into a separate TreeNode. (Closed)
Patch Set: review Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.ItemViewType;
9 import org.chromium.chrome.browser.ntp.cards.Leaf;
10 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder;
11 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout.Con tentSuggestionsCardLayoutEnum; 8 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout.Con tentSuggestionsCardLayoutEnum;
12 9
13 /** 10 /**
14 * Represents the data for an article card on the NTP. 11 * Represents the data for an article card on the NTP.
15 */ 12 */
16 public class SnippetArticle extends Leaf { 13 public class SnippetArticle {
17 /** The category of this article. */ 14 /** The category of this article. */
18 public final int mCategory; 15 public final int mCategory;
19 16
20 /** The identifier for this article within the category - not necessarily un ique globally. */ 17 /** The identifier for this article within the category - not necessarily un ique globally. */
21 public final String mIdWithinCategory; 18 public final String mIdWithinCategory;
22 19
23 /** The title of this article. */ 20 /** The title of this article. */
24 public final String mTitle; 21 public final String mTitle;
25 22
26 /** The canonical publisher name (e.g., New York Times). */ 23 /** The canonical publisher name (e.g., New York Times). */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (!(other instanceof SnippetArticle)) return false; 78 if (!(other instanceof SnippetArticle)) return false;
82 SnippetArticle rhs = (SnippetArticle) other; 79 SnippetArticle rhs = (SnippetArticle) other;
83 return mCategory == rhs.mCategory && mIdWithinCategory.equals(rhs.mIdWit hinCategory); 80 return mCategory == rhs.mCategory && mIdWithinCategory.equals(rhs.mIdWit hinCategory);
84 } 81 }
85 82
86 @Override 83 @Override
87 public int hashCode() { 84 public int hashCode() {
88 return mCategory ^ mIdWithinCategory.hashCode(); 85 return mCategory ^ mIdWithinCategory.hashCode();
89 } 86 }
90 87
91 @Override
92 @ItemViewType
93 public int getItemViewType() {
94 return ItemViewType.SNIPPET;
95 }
96
97 @Override
98 protected void onBindViewHolder(NewTabPageViewHolder holder) {
99 assert holder instanceof SnippetArticleViewHolder;
100 ((SnippetArticleViewHolder) holder).onBindViewHolder(this);
101 }
102
103 @Override
104 public SnippetArticle getSuggestionAt(int position) {
105 if (position != 0) throw new IndexOutOfBoundsException();
106
107 return this;
108 }
109
110 /** 88 /**
111 * Returns this article's thumbnail as a {@link Bitmap}. Can return {@code n ull} as it is 89 * Returns this article's thumbnail as a {@link Bitmap}. Can return {@code n ull} as it is
112 * initially unset. 90 * initially unset.
113 */ 91 */
114 public Bitmap getThumbnailBitmap() { 92 public Bitmap getThumbnailBitmap() {
115 return mThumbnailBitmap; 93 return mThumbnailBitmap;
116 } 94 }
117 95
118 /** Sets the thumbnail bitmap for this article. */ 96 /** Sets the thumbnail bitmap for this article. */
119 public void setThumbnailBitmap(Bitmap bitmap) { 97 public void setThumbnailBitmap(Bitmap bitmap) {
120 mThumbnailBitmap = bitmap; 98 mThumbnailBitmap = bitmap;
121 } 99 }
122 100
123 /** Returns whether to track an impression for this article. */ 101 /** Returns whether to track an impression for this article. */
124 public boolean trackImpression() { 102 public boolean trackImpression() {
125 // Track UMA only upon the first impression per life-time of this object . 103 // Track UMA only upon the first impression per life-time of this object .
126 if (mImpressionTracked) return false; 104 if (mImpressionTracked) return false;
127 mImpressionTracked = true; 105 mImpressionTracked = true;
128 return true; 106 return true;
129 } 107 }
130 108
131 @Override 109 @Override
132 public String toString() { 110 public String toString() {
133 // For debugging purposes. Displays the first 42 characters of the title . 111 // For debugging purposes. Displays the first 42 characters of the title .
134 return String.format("{%s, %1.42s}", getClass().getSimpleName(), mTitle) ; 112 return String.format("{%s, %1.42s}", getClass().getSimpleName(), mTitle) ;
135 } 113 }
136 } 114 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SuggestionsSection.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698