Chromium Code Reviews| 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 aeb54cc9520624a47da71ff387df5f4d48746d72..df9aa33df89b2df0ad8c529d0e0fbf5e3dd78577 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 |
| @@ -65,6 +65,8 @@ |
| "https://s2.googleusercontent.com/s2/favicons?domain=%s&src=chrome_newtab_mobile&sz=%d&alt=404"; |
| private final SuggestionsUiDelegate mUiDelegate; |
| + private final UiConfig mUiConfig; |
| + |
| private final TextView mHeadlineTextView; |
| private final TextView mPublisherTextView; |
| private final TextView mArticleSnippetTextView; |
| @@ -72,14 +74,15 @@ |
| private final ImageView mOfflineBadge; |
| private final View mPublisherBar; |
| + /** Total horizontal space occupied by the thumbnail, sum of its size and padding. */ |
|
Michael van Ouwerkerk
2017/02/15 17:59:33
"size and margin"?
dgn
2017/02/15 18:15:56
Done.
|
| + private final int mThumbnailFootprintPx; |
| + private final boolean mUseFaviconService; |
| + |
| private FetchImageCallback mImageCallback; |
| private SnippetArticle mArticle; |
| private SuggestionsCategoryInfo mCategoryInfo; |
| private int mPublisherFaviconSizePx; |
| - private final boolean mUseFaviconService; |
|
dgn
2017/02/15 16:53:32
moved the final members together
|
| - private final UiConfig mUiConfig; |
| - |
| /** |
| * Constructs a {@link SnippetArticleViewHolder} item used to display snippets. |
| * @param parent The NewTabPageRecyclerView that is going to contain the newly created view. |
| @@ -93,6 +96,8 @@ public SnippetArticleViewHolder(NewTabPageRecyclerView parent, |
| super(R.layout.new_tab_page_snippets_card, parent, uiConfig, contextMenuManager); |
| mUiDelegate = uiDelegate; |
| + mUiConfig = uiConfig; |
| + |
| mThumbnailView = (ImageView) itemView.findViewById(R.id.article_thumbnail); |
| mHeadlineTextView = (TextView) itemView.findViewById(R.id.article_headline); |
| mPublisherTextView = (TextView) itemView.findViewById(R.id.article_publisher); |
| @@ -100,17 +105,18 @@ public SnippetArticleViewHolder(NewTabPageRecyclerView parent, |
| mPublisherBar = itemView.findViewById(R.id.publisher_bar); |
| mOfflineBadge = (ImageView) itemView.findViewById(R.id.offline_icon); |
| - new ImpressionTracker(itemView, this); |
| + mThumbnailFootprintPx = |
| + itemView.getResources().getDimensionPixelSize(R.dimen.snippets_thumbnail_size) |
| + + itemView.getResources().getDimensionPixelSize(R.dimen.snippets_thumbnail_padding); |
| + mUseFaviconService = CardsVariationParameters.isFaviconServiceEnabled(); |
| - mUiConfig = uiConfig; |
| + new ImpressionTracker(itemView, this); |
| new DisplayStyleObserverAdapter(itemView, uiConfig, new DisplayStyleObserver() { |
| @Override |
| public void onDisplayStyleChanged(UiConfig.DisplayStyle newDisplayStyle) { |
| updateLayout(); |
| } |
| }); |
| - |
| - mUseFaviconService = CardsVariationParameters.isFaviconServiceEnabled(); |
| } |
| @Override |
| @@ -165,16 +171,15 @@ private void updateLayout() { |
| mArticleSnippetTextView.setVisibility(showDescription ? View.VISIBLE : View.GONE); |
| mThumbnailView.setVisibility(showThumbnail ? View.VISIBLE : View.GONE); |
| - mHeadlineTextView.setMaxLines(getHeaderMaxLines(horizontalStyle, verticalStyle, layout)); |
| - mHeadlineTextView.setMinLines(getHeaderMinLines(showDescription, showThumbnail)); |
| // If we aren't showing the article snippet, reduce the top margin for publisher text. |
| ViewGroup.MarginLayoutParams params = |
| (ViewGroup.MarginLayoutParams) mPublisherBar.getLayoutParams(); |
| - params.topMargin = mPublisherBar.getResources().getDimensionPixelSize(showThumbnail |
| + params.topMargin = mPublisherBar.getResources().getDimensionPixelSize(showDescription |
| ? R.dimen.snippets_publisher_margin_top_with_article_snippet |
| : R.dimen.snippets_publisher_margin_top_without_article_snippet); |
| + ApiCompatibilityUtils.setMarginEnd(params, showThumbnail ? mThumbnailFootprintPx : 0); |
| mPublisherBar.setLayoutParams(params); |
| } |
| @@ -197,21 +202,6 @@ private boolean shouldShowThumbnail(int horizontalStyle, int verticalStyle, int |
| return true; |
| } |
| - private int getHeaderMaxLines(int horizontalStyle, int verticalStyle, int layout) { |
| - // When the screen is too small (narrow or flat) we don't show the description so we have |
| - // more space for the header. |
| - if (verticalStyle == VerticalDisplayStyle.FLAT) return 3; |
| - if (horizontalStyle == HorizontalDisplayStyle.NARROW) return 4; |
| - return 2; |
| - } |
| - |
| - private int getHeaderMinLines(boolean showDescription, boolean showThumbnail) { |
| - // When we have a thumbnail, we try to ensure we have enough content to push the |
| - // attribution line below it. So when the description is hidden, we have to force the |
| - // header to reserve that space. |
| - return showThumbnail && !showDescription ? 3 : 1; |
| - } |
| - |
| private static String getAttributionString(SnippetArticle article) { |
| if (article.mPublishTimestampMilliseconds == 0) return article.mPublisher; |