Commit d4aaf40e authored by spdonghao's avatar spdonghao Committed by Commit Bot

[Instant Start] Delay sign-in box to fade in together with Feed.

The sign-in box shows earlier than the Feed articles, and the Feed
placeholder looks strange during this period of time. This CL delays
the sign-in box and makes it fade in together with the Feed articles.

Bug: 1114190
Change-Id: Ifd353fe5bf318baaf61b7419e561b673a5852b87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314267
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796129}
parent f8c2fe64
...@@ -150,14 +150,14 @@ class StartSurfaceMediator ...@@ -150,14 +150,14 @@ class StartSurfaceMediator
private boolean mExcludeMVTiles; private boolean mExcludeMVTiles;
private boolean mShowStackTabSwitcher; private boolean mShowStackTabSwitcher;
/** /**
* The value of {@link Pref.ARTICLES_LIST_VISIBLE} on Startup. Getting this value for recording * The value of {@link Pref#ARTICLES_LIST_VISIBLE} on Startup. Getting this value for recording
* the consistency of {@link ChromePreferenceKeys.FEED_ARTICLES_LIST_VISIBLE} with {@link * the consistency of {@link ChromePreferenceKeys#FEED_ARTICLES_LIST_VISIBLE} with {@link
* Pref.ARTICLES_LIST_VISIBLE}. * Pref#ARTICLES_LIST_VISIBLE}.
*/ */
private Boolean mFeedVisibilityPrefOnStartUp; private Boolean mFeedVisibilityPrefOnStartUp;
/** /**
* The value of {@link ChromePreferenceKeys.FEED_ARTICLES_LIST_VISIBLE} on Startup. Getting this * The value of {@link ChromePreferenceKeys#FEED_ARTICLES_LIST_VISIBLE} on Startup. Getting this
* value for recording the consistency with {@link Pref.ARTICLES_LIST_VISIBLE}. * value for recording the consistency with {@link Pref#ARTICLES_LIST_VISIBLE}.
*/ */
@Nullable @Nullable
private Boolean mFeedVisibilityInSharedPreferenceOnStartUp; private Boolean mFeedVisibilityInSharedPreferenceOnStartUp;
......
...@@ -74,6 +74,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -74,6 +74,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
private final View mNtpHeader; private final View mNtpHeader;
private final boolean mShowDarkBackground; private final boolean mShowDarkBackground;
private final boolean mIsPlaceholderShown; private final boolean mIsPlaceholderShown;
private final boolean mIsPlaceholderShownInV1;
private final boolean mV2Enabled; private final boolean mV2Enabled;
private final FeedSurfaceDelegate mDelegate; private final FeedSurfaceDelegate mDelegate;
private final int mDefaultMargin; private final int mDefaultMargin;
...@@ -221,6 +222,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -221,6 +222,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mIsPlaceholderShown = isPlaceholderShown; mIsPlaceholderShown = isPlaceholderShown;
mV2Enabled = FeatureList.isInitialized() mV2Enabled = FeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2); && ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2);
mIsPlaceholderShownInV1 = mIsPlaceholderShown && !mV2Enabled;
mDelegate = delegate; mDelegate = delegate;
mPageNavigationDelegate = pageNavigationDelegate; mPageNavigationDelegate = pageNavigationDelegate;
mBottomSheetController = bottomSheetController; mBottomSheetController = bottomSheetController;
...@@ -305,6 +307,11 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -305,6 +307,11 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
return mStream; return mStream;
} }
/** @return Whether the placeholder shows in V1. */
public boolean isPlaceholderShownInV1() {
return mIsPlaceholderShownInV1;
}
/** /**
* Create a {@link Stream} for this class. * Create a {@link Stream} for this class.
*/ */
...@@ -316,9 +323,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -316,9 +323,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mScrollViewResizer = null; mScrollViewResizer = null;
} }
boolean isPlaceholderShownInV1 = mIsPlaceholderShown && !mV2Enabled;
mStreamCreatedTimeMs = SystemClock.elapsedRealtime(); mStreamCreatedTimeMs = SystemClock.elapsedRealtime();
if (mV2Enabled) { if (mV2Enabled) {
mStream = new FeedStream(mActivity, mShowDarkBackground, mSnackbarManager, mStream = new FeedStream(mActivity, mShowDarkBackground, mSnackbarManager,
mPageNavigationDelegate, mBottomSheetController); mPageNavigationDelegate, mBottomSheetController);
...@@ -333,14 +338,14 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -333,14 +338,14 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
FeedProcessScopeFactory.getFeedConsumptionObserver(), FeedProcessScopeFactory.getFeedConsumptionObserver(),
FeedProcessScopeFactory.getFeedLoggingBridge(), mActivity, mProfile); FeedProcessScopeFactory.getFeedLoggingBridge(), mActivity, mProfile);
mStream = FeedV1StreamCreator.createStream(mActivity, mImageLoader, actionApi, mStream = FeedV1StreamCreator.createStream(mActivity, mImageLoader, actionApi,
mUiConfig, mSnackbarManager, mShowDarkBackground, isPlaceholderShownInV1); mUiConfig, mSnackbarManager, mShowDarkBackground, mIsPlaceholderShownInV1);
} }
mStreamLifecycleManager = mDelegate.createStreamLifecycleManager(mStream, mActivity); mStreamLifecycleManager = mDelegate.createStreamLifecycleManager(mStream, mActivity);
View view = mStream.getView(); View view = mStream.getView();
view.setBackgroundResource(R.color.default_bg_color); view.setBackgroundResource(R.color.default_bg_color);
if (isPlaceholderShownInV1) { if (mIsPlaceholderShownInV1) {
// Set recyclerView as transparent until first patch of articles are loaded. Before // Set recyclerView as transparent until first patch of articles are loaded. Before
// that, the placeholder is shown. // that, the placeholder is shown.
view.getBackground().setAlpha(0); view.getBackground().setAlpha(0);
...@@ -448,6 +453,11 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -448,6 +453,11 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mSigninPromoView = (PersonalizedSigninPromoView) inflater.inflate( mSigninPromoView = (PersonalizedSigninPromoView) inflater.inflate(
R.layout.personalized_signin_promo_view_modern_content_suggestions, mRootView, R.layout.personalized_signin_promo_view_modern_content_suggestions, mRootView,
false); false);
// If the placeholder is shown in V1, delay to show the sign-in view until the articles
// are shown.
if (mIsPlaceholderShownInV1) {
mSigninPromoView.setVisibility(View.INVISIBLE);
}
} }
return mSigninPromoView; return mSigninPromoView;
} }
......
...@@ -14,6 +14,7 @@ import android.widget.ScrollView; ...@@ -14,6 +14,7 @@ import android.widget.ScrollView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.RecyclerView;
import org.chromium.base.MemoryPressureListener; import org.chromium.base.MemoryPressureListener;
import org.chromium.base.memory.MemoryPressureCallback; import org.chromium.base.memory.MemoryPressureCallback;
...@@ -205,6 +206,9 @@ public class FeedSurfaceMediator ...@@ -205,6 +206,9 @@ public class FeedSurfaceMediator
@Override @Override
public void onAddFinished() { public void onAddFinished() {
// After first batch of articles are loaded, set recyclerView back to
// non-transparent.
stream.getView().getBackground().setAlpha(255);
if (mContentFirstAvailableTimeMs == 0) { if (mContentFirstAvailableTimeMs == 0) {
mContentFirstAvailableTimeMs = SystemClock.elapsedRealtime(); mContentFirstAvailableTimeMs = SystemClock.elapsedRealtime();
if (mHasPendingUmaRecording) { if (mHasPendingUmaRecording) {
...@@ -214,6 +218,24 @@ public class FeedSurfaceMediator ...@@ -214,6 +218,24 @@ public class FeedSurfaceMediator
} }
mIsLoadingFeed = false; mIsLoadingFeed = false;
} }
@Override
public void onAddStarting() {
if (!mCoordinator.isPlaceholderShownInV1()) {
return;
}
// If the placeholder is shown, set sign-in box visible back.
RecyclerView recyclerView = (RecyclerView) stream.getView();
if (recyclerView != null) {
View signInView = recyclerView.findViewById(R.id.signin_promo_view_container);
if (signInView != null) {
signInView.setAlpha(0f);
signInView.setVisibility(View.VISIBLE);
signInView.animate().alpha(1f).setDuration(
recyclerView.getItemAnimator().getAddDuration());
}
}
}
}; };
stream.addOnContentChangedListener(mStreamContentChangedListener); stream.addOnContentChangedListener(mStreamContentChangedListener);
......
...@@ -31,11 +31,15 @@ public class StreamItemAnimator extends DefaultItemAnimator { ...@@ -31,11 +31,15 @@ public class StreamItemAnimator extends DefaultItemAnimator {
@Override @Override
public void onAddFinished(RecyclerView.ViewHolder item) { public void onAddFinished(RecyclerView.ViewHolder item) {
super.onAddFinished(item); super.onAddFinished(item);
// After first patch of articles are loaded, set recyclerView back to non-transparent.
mParent.getBackground().setAlpha(255);
mContentChangedListener.onAddFinished(); mContentChangedListener.onAddFinished();
} }
@Override
public void onAddStarting(RecyclerView.ViewHolder item) {
super.onAddStarting(item);
mContentChangedListener.onAddStarting();
}
@Override @Override
public void onAnimationFinished(RecyclerView.ViewHolder viewHolder) { public void onAnimationFinished(RecyclerView.ViewHolder viewHolder) {
super.onAnimationFinished(viewHolder); super.onAnimationFinished(viewHolder);
......
...@@ -35,4 +35,11 @@ public class StreamContentChangedListener implements ContentChangedListener { ...@@ -35,4 +35,11 @@ public class StreamContentChangedListener implements ContentChangedListener {
listener.onAddFinished(); listener.onAddFinished();
} }
} }
@Override
public void onAddStarting() {
for (ContentChangedListener listener : mListeners) {
listener.onAddStarting();
}
}
} }
...@@ -153,6 +153,12 @@ public interface Stream { ...@@ -153,6 +153,12 @@ public interface Stream {
* {@link androidx.recyclerview.widget.SimpleItemAnimator#onAddFinished} event is received. * {@link androidx.recyclerview.widget.SimpleItemAnimator#onAddFinished} event is received.
*/ */
default void onAddFinished(){}; default void onAddFinished(){};
/**
* Called by Stream when an
* {@link androidx.recyclerview.widget.SimpleItemAnimator#onAddStarting} event is received.
*/
default void onAddStarting(){};
} }
/** Interface users can implement to be told about changes to scrolling in the Stream. */ /** Interface users can implement to be told about changes to scrolling in the Stream. */
......
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