Commit 1811f49c authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Feed] Hook up MarginResizer for FeedNTP

Bug: 860051
Change-Id: I08b602d2f02f8e61f1539a81483d4af9ad2e0493
Reviewed-on: https://chromium-review.googlesource.com/1180505Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584546}
parent 6a178bd0
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.feed;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
......@@ -44,6 +45,8 @@ import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegateImpl
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.displaystyle.HorizontalDisplayStyle;
import org.chromium.chrome.browser.widget.displaystyle.MarginResizer;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import java.util.Arrays;
......@@ -58,6 +61,7 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
private final StreamLifecycleManager mStreamLifecycleManager;
private final Stream mStream;
private UiConfig mUiConfig;
private FrameLayout mRootView;
private SectionHeaderView mSectionHeaderView;
private FeedImageLoader mImageLoader;
......@@ -72,22 +76,15 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
}
private static class BasicStreamConfiguration implements StreamConfiguration {
private final Resources mResources;
private final int mPadding;
public BasicStreamConfiguration(Resources resources) {
mResources = resources;
mPadding = mResources.getDimensionPixelSize(
R.dimen.content_suggestions_card_modern_margin);
}
public BasicStreamConfiguration() {}
@Override
public int getPaddingStart() {
return mPadding;
return 0;
}
@Override
public int getPaddingEnd() {
return mPadding;
return 0;
}
@Override
public int getPaddingTop() {
......@@ -101,18 +98,23 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
private static class BasicCardConfiguration implements CardConfiguration {
private final Resources mResources;
private final UiConfig mUiConfig;
private final int mCornerRadius;
private final Drawable mCardBackground;
private final int mCardMarginBottom;
private final int mCardMargin;
private final int mCardWideMargin;
public BasicCardConfiguration(Resources resources) {
public BasicCardConfiguration(Resources resources, UiConfig uiConfig) {
mResources = resources;
mUiConfig = uiConfig;
mCornerRadius = mResources.getDimensionPixelSize(
R.dimen.content_suggestions_card_modern_corner_radius);
mCardBackground = ApiCompatibilityUtils.getDrawable(
mResources, R.drawable.content_card_modern_background);
mCardMarginBottom = mResources.getDimensionPixelSize(
mCardMargin = mResources.getDimensionPixelSize(
R.dimen.content_suggestions_card_modern_margin);
mCardWideMargin =
mResources.getDimensionPixelSize(R.dimen.ntp_wide_card_lateral_margins);
}
@Override
......@@ -127,19 +129,21 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
@Override
public int getCardBottomMargin() {
return mCardMarginBottom;
return mCardMargin;
}
@Override
public int getCardStartMargin() {
// TODO(twellington): implement this method.
return 0;
return mUiConfig.getCurrentDisplayStyle().horizontal == HorizontalDisplayStyle.WIDE
? mCardWideMargin
: mCardMargin;
}
@Override
public int getCardEndMargin() {
// TODO(twellington): implement this method.
return 0;
return mUiConfig.getCurrentDisplayStyle().horizontal == HorizontalDisplayStyle.WIDE
? mCardWideMargin
: mCardMargin;
}
}
......@@ -157,6 +161,21 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
public void removeOfflineStatusListener(OfflineStatusListener offlineStatusListener) {}
}
/**
* Provides the additional capabilities needed for the {@link FeedNewTabPage} container view.
*/
private class RootView extends FrameLayout {
public RootView(Context context) {
super(context);
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUiConfig.updateDisplayStyle();
}
}
/**
* Constructs a new FeedNewTabPage.
*
......@@ -180,8 +199,8 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
FeedStreamScope streamScope =
feedProcessScope
.createFeedStreamScopeBuilder(activity, mImageLoader, actionApi,
new BasicStreamConfiguration(activity.getResources()),
new BasicCardConfiguration(activity.getResources()),
new BasicStreamConfiguration(),
new BasicCardConfiguration(activity.getResources(), mUiConfig),
new BasicSnackbarApi(), new FeedBasicLogging(),
new StubOfflineIndicatorApi())
.build();
......@@ -194,6 +213,12 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
mSectionHeaderView = (SectionHeaderView) inflater.inflate(
R.layout.new_tab_page_snippets_expandable_header, null);
// TODO(huayinz): Add MarginResizer for sign-in promo under issue 860051 or 860043,
// depending on which one lands first.
int wideMargin = mSectionHeaderView.getResources().getDimensionPixelSize(
R.dimen.ntp_wide_card_lateral_margins);
MarginResizer.createAndAttach(mSectionHeaderView, mUiConfig, 0, wideMargin);
mMediator = new FeedNewTabPageMediator(this,
new SnapScrollHelper(mNewTabPageManager, mNewTabPageLayout, mStream.getView()));
......@@ -209,7 +234,7 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
mNewTabPageLayout.initialize(mNewTabPageManager, mTab, mTileGroupDelegate,
mSearchProviderHasLogo,
TemplateUrlService.getInstance().isDefaultSearchEngineGoogle(), mMediator,
contextMenuManager, new UiConfig(mRootView));
contextMenuManager, mUiConfig);
mStream.getView().setBackgroundColor(Color.WHITE);
mRootView.addView(mStream.getView());
......@@ -221,10 +246,11 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
@Override
protected void initializeMainView(Context context) {
int topPadding = context.getResources().getDimensionPixelOffset(R.dimen.tab_strip_height);
mRootView = new FrameLayout(context);
mRootView = new RootView(context);
mRootView.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
mRootView.setPadding(0, topPadding, 0, 0);
mUiConfig = new UiConfig(mRootView);
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment