| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 | 4 |
| 5 package org.chromium.chrome.browser.ntp.snippets; | 5 package org.chromium.chrome.browser.ntp.snippets; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.drawable.BitmapDrawable; | 10 import android.graphics.drawable.BitmapDrawable; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 private final TextView mHeadlineTextView; | 63 private final TextView mHeadlineTextView; |
| 64 private final TextView mPublisherTextView; | 64 private final TextView mPublisherTextView; |
| 65 private final TextView mArticleSnippetTextView; | 65 private final TextView mArticleSnippetTextView; |
| 66 private final ImageView mThumbnailView; | 66 private final ImageView mThumbnailView; |
| 67 private final ImageView mOfflineBadge; | 67 private final ImageView mOfflineBadge; |
| 68 private final View mPublisherBar; | 68 private final View mPublisherBar; |
| 69 | 69 |
| 70 private FetchImageCallback mImageCallback; | 70 private FetchImageCallback mImageCallback; |
| 71 private SnippetArticle mArticle; | 71 private SnippetArticle mArticle; |
| 72 private SuggestionsCategoryInfo mCategoryInfo; | 72 private SuggestionsCategoryInfo mCategoryInfo; |
| 73 private int mCategoryIndex; | |
| 74 private int mPublisherFaviconSizePx; | 73 private int mPublisherFaviconSizePx; |
| 75 | 74 |
| 76 private final boolean mUseFaviconService; | 75 private final boolean mUseFaviconService; |
| 77 private final UiConfig mUiConfig; | 76 private final UiConfig mUiConfig; |
| 78 | 77 |
| 79 /** | 78 /** |
| 80 * Constructs a {@link SnippetArticleViewHolder} item used to display snippe
ts. | 79 * Constructs a {@link SnippetArticleViewHolder} item used to display snippe
ts. |
| 81 * | 80 * |
| 82 * @param parent The NewTabPageRecyclerView that is going to contain the new
ly created view. | 81 * @param parent The NewTabPageRecyclerView that is going to contain the new
ly created view. |
| 83 * @param manager The NewTabPageManager object used to open an article. | 82 * @param manager The NewTabPageManager object used to open an article. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 104 updateLayout(); | 103 updateLayout(); |
| 105 } | 104 } |
| 106 }); | 105 }); |
| 107 | 106 |
| 108 mUseFaviconService = CardsVariationParameters.isFaviconServiceEnabled(); | 107 mUseFaviconService = CardsVariationParameters.isFaviconServiceEnabled(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 @Override | 110 @Override |
| 112 public void onImpression() { | 111 public void onImpression() { |
| 113 if (mArticle != null && mArticle.trackImpression()) { | 112 if (mArticle != null && mArticle.trackImpression()) { |
| 114 mNewTabPageManager.trackSnippetImpression(mArticle); | 113 mNewTabPageManager.getSuggestionsMetricsReporter().onSuggestionShown
(mArticle); |
| 115 mRecyclerView.onSnippetImpression(); | 114 mRecyclerView.onSnippetImpression(); |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 | 117 |
| 119 @Override | 118 @Override |
| 120 public void onCardTapped() { | 119 public void onCardTapped() { |
| 121 mNewTabPageManager.openSnippet(WindowOpenDisposition.CURRENT_TAB, mArtic
le, mCategoryIndex); | 120 mNewTabPageManager.openSnippet(WindowOpenDisposition.CURRENT_TAB, mArtic
le); |
| 122 } | 121 } |
| 123 | 122 |
| 124 @Override | 123 @Override |
| 125 public void openItem(int windowDisposition) { | 124 public void openItem(int windowDisposition) { |
| 126 mNewTabPageManager.openSnippet(windowDisposition, mArticle, mCategoryInd
ex); | 125 mNewTabPageManager.openSnippet(windowDisposition, mArticle); |
| 127 } | 126 } |
| 128 | 127 |
| 129 @Override | 128 @Override |
| 130 public void removeItem() { | 129 public void removeItem() { |
| 131 getRecyclerView().dismissItemWithAnimation(this); | 130 getRecyclerView().dismissItemWithAnimation(this); |
| 132 } | 131 } |
| 133 | 132 |
| 134 @Override | 133 @Override |
| 135 public String getUrl() { | 134 public String getUrl() { |
| 136 return mArticle.mUrl; | 135 return mArticle.mUrl; |
| 137 } | 136 } |
| 138 | 137 |
| 139 @Override | 138 @Override |
| 140 public boolean isItemSupported(@ContextMenuItemId int menuItemId) { | 139 public boolean isItemSupported(@ContextMenuItemId int menuItemId) { |
| 141 if (mArticle.isDownload()) { | 140 if (mArticle.isDownload()) { |
| 142 if (menuItemId == ContextMenuManager.ID_OPEN_IN_INCOGNITO_TAB) retur
n false; | 141 if (menuItemId == ContextMenuManager.ID_OPEN_IN_INCOGNITO_TAB) retur
n false; |
| 143 if (menuItemId == ContextMenuManager.ID_SAVE_FOR_OFFLINE) return fal
se; | 142 if (menuItemId == ContextMenuManager.ID_SAVE_FOR_OFFLINE) return fal
se; |
| 144 return true; | 143 return true; |
| 145 } | 144 } |
| 146 if (mArticle.isRecentTab()) { | 145 if (mArticle.isRecentTab()) { |
| 147 if (menuItemId == ContextMenuManager.ID_REMOVE) return true; | 146 if (menuItemId == ContextMenuManager.ID_REMOVE) return true; |
| 148 return false; | 147 return false; |
| 149 } | 148 } |
| 150 return true; | 149 return true; |
| 151 } | 150 } |
| 152 | 151 |
| 153 @Override | 152 @Override |
| 154 public void onContextMenuCreated() { | 153 public void onContextMenuCreated() { |
| 155 mNewTabPageManager.trackSnippetMenuOpened(mArticle); | 154 mNewTabPageManager.getSuggestionsMetricsReporter().onSuggestionMenuOpene
d(mArticle); |
| 156 } | 155 } |
| 157 | 156 |
| 158 @Override | 157 @Override |
| 159 protected Delegate getContextMenuDelegate() { | 158 protected Delegate getContextMenuDelegate() { |
| 160 return this; | 159 return this; |
| 161 } | 160 } |
| 162 | 161 |
| 163 /** | 162 /** |
| 164 * Updates the layout taking into account screen dimensions and the type of
snippet displayed. | 163 * Updates the layout taking into account screen dimensions and the type of
snippet displayed. |
| 165 */ | 164 */ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS)
; | 216 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS)
; |
| 218 } finally { | 217 } finally { |
| 219 StrictMode.setThreadPolicy(oldPolicy); | 218 StrictMode.setThreadPolicy(oldPolicy); |
| 220 } | 219 } |
| 221 // We format the publisher here so that having a publisher name in an RT
L language | 220 // We format the publisher here so that having a publisher name in an RT
L language |
| 222 // doesn't mess up the formatting on an LTR device and vice versa. | 221 // doesn't mess up the formatting on an LTR device and vice versa. |
| 223 return String.format(PUBLISHER_FORMAT_STRING, | 222 return String.format(PUBLISHER_FORMAT_STRING, |
| 224 BidiFormatter.getInstance().unicodeWrap(article.mPublisher), rel
ativeTimeSpan); | 223 BidiFormatter.getInstance().unicodeWrap(article.mPublisher), rel
ativeTimeSpan); |
| 225 } | 224 } |
| 226 | 225 |
| 227 public void onBindViewHolder(SnippetArticle article, SuggestionsCategoryInfo
categoryInfo, | 226 public void onBindViewHolder( |
| 228 List<Object> payloads, int categoryIndex) { | 227 SnippetArticle article, SuggestionsCategoryInfo categoryInfo, List<O
bject> payloads) { |
| 229 if (!payloads.isEmpty() && article.equals(mArticle)) { | 228 if (!payloads.isEmpty() && article.equals(mArticle)) { |
| 230 performPartialBind(payloads); | 229 performPartialBind(payloads); |
| 231 return; | 230 return; |
| 232 } | 231 } |
| 233 | 232 |
| 234 super.onBindViewHolder(); | 233 super.onBindViewHolder(); |
| 235 | 234 |
| 236 mArticle = article; | 235 mArticle = article; |
| 237 mCategoryInfo = categoryInfo; | 236 mCategoryInfo = categoryInfo; |
| 238 mCategoryIndex = categoryIndex; | |
| 239 updateLayout(); | 237 updateLayout(); |
| 240 | 238 |
| 241 mHeadlineTextView.setText(mArticle.mTitle); | 239 mHeadlineTextView.setText(mArticle.mTitle); |
| 242 mPublisherTextView.setText(getAttributionString(mArticle)); | 240 mPublisherTextView.setText(getAttributionString(mArticle)); |
| 243 | 241 |
| 244 // The favicon of the publisher should match the TextView height. | 242 // The favicon of the publisher should match the TextView height. |
| 245 int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); | 243 int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); |
| 246 int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
; | 244 int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
; |
| 247 mPublisherTextView.measure(widthSpec, heightSpec); | 245 mPublisherTextView.measure(widthSpec, heightSpec); |
| 248 mPublisherFaviconSizePx = mPublisherTextView.getMeasuredHeight(); | 246 mPublisherFaviconSizePx = mPublisherTextView.getMeasuredHeight(); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 ApiCompatibilityUtils.setCompoundDrawablesRelative( | 411 ApiCompatibilityUtils.setCompoundDrawablesRelative( |
| 414 mPublisherTextView, drawable, null, null, null); | 412 mPublisherTextView, drawable, null, null, null); |
| 415 mPublisherTextView.setVisibility(View.VISIBLE); | 413 mPublisherTextView.setVisibility(View.VISIBLE); |
| 416 } | 414 } |
| 417 | 415 |
| 418 @Override | 416 @Override |
| 419 public boolean isDismissable() { | 417 public boolean isDismissable() { |
| 420 return !isPeeking(); | 418 return !isPeeking(); |
| 421 } | 419 } |
| 422 } | 420 } |
| OLD | NEW |