Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
index 3eb3a43cedbed68f480e5edf0336ebb4b41d407f..d313592dc429164d252dfad42e58a95b4cfc2695 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticleViewHolder.java |
@@ -185,39 +185,43 @@ public class SnippetArticleViewHolder |
mPublisherBar.setLayoutParams(params); |
} |
- public void onBindViewHolder(SnippetArticle article, SuggestionsCategoryInfo categoryInfo) { |
- super.onBindViewHolder(); |
- |
- // No longer listen for offline status changes to the old article. |
- if (mArticle != null) mArticle.setOfflineStatusChangeRunnable(null); |
- |
- mArticle = article; |
- mCategoryInfo = categoryInfo; |
- updateLayout(); |
- |
- mHeadlineTextView.setText(mArticle.mTitle); |
+ private static String getAttributionString(SnippetArticle article) { |
+ if (article.mPublishTimestampMilliseconds == 0) return article.mPublisher; |
// DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.getDefault(). If this |
// has never been called before it loads the current time zone from disk. In most likelihood |
// this will have been called previously and the current time zone will have been cached, |
// but in some cases (eg instrumentation tests) it will cause a strict mode violation. |
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
+ CharSequence relativeTimeSpan; |
try { |
long time = SystemClock.elapsedRealtime(); |
- CharSequence relativeTimeSpan = DateUtils.getRelativeTimeSpanString( |
- mArticle.mPublishTimestampMilliseconds, System.currentTimeMillis(), |
- DateUtils.MINUTE_IN_MILLIS); |
+ relativeTimeSpan = |
+ DateUtils.getRelativeTimeSpanString(article.mPublishTimestampMilliseconds, |
+ System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS); |
RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBuildTime", |
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); |
- |
- // We format the publisher here so that having a publisher name in an RTL language |
- // doesn't mess up the formatting on an LTR device and vice versa. |
- String publisherAttribution = String.format(PUBLISHER_FORMAT_STRING, |
- BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher), relativeTimeSpan); |
- mPublisherTextView.setText(publisherAttribution); |
} finally { |
StrictMode.setThreadPolicy(oldPolicy); |
} |
+ // We format the publisher here so that having a publisher name in an RTL language |
+ // doesn't mess up the formatting on an LTR device and vice versa. |
+ return String.format(PUBLISHER_FORMAT_STRING, |
+ BidiFormatter.getInstance().unicodeWrap(article.mPublisher), relativeTimeSpan); |
+ } |
+ |
+ public void onBindViewHolder(SnippetArticle article, SuggestionsCategoryInfo categoryInfo) { |
+ super.onBindViewHolder(); |
+ |
+ // No longer listen for offline status changes to the old article. |
+ if (mArticle != null) mArticle.setOfflineStatusChangeRunnable(null); |
+ |
+ mArticle = article; |
+ mCategoryInfo = categoryInfo; |
+ updateLayout(); |
+ |
+ mHeadlineTextView.setText(mArticle.mTitle); |
+ mPublisherTextView.setText(getAttributionString(mArticle)); |
// The favicon of the publisher should match the TextView height. |
int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); |