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
private boolean mExcludeMVTiles;
private boolean mShowStackTabSwitcher;
/**
* 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
* Pref.ARTICLES_LIST_VISIBLE}.
* 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
* Pref#ARTICLES_LIST_VISIBLE}.
*/
private Boolean mFeedVisibilityPrefOnStartUp;
/**
* The value of {@link ChromePreferenceKeys.FEED_ARTICLES_LIST_VISIBLE} on Startup. Getting this
* value for recording the consistency with {@link Pref.ARTICLES_LIST_VISIBLE}.
* The value of {@link ChromePreferenceKeys#FEED_ARTICLES_LIST_VISIBLE} on Startup. Getting this
* value for recording the consistency with {@link Pref#ARTICLES_LIST_VISIBLE}.
*/
@Nullable
private Boolean mFeedVisibilityInSharedPreferenceOnStartUp;
......
......@@ -74,6 +74,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
private final View mNtpHeader;
private final boolean mShowDarkBackground;
private final boolean mIsPlaceholderShown;
private final boolean mIsPlaceholderShownInV1;
private final boolean mV2Enabled;
private final FeedSurfaceDelegate mDelegate;
private final int mDefaultMargin;
......@@ -221,6 +222,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mIsPlaceholderShown = isPlaceholderShown;
mV2Enabled = FeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2);
mIsPlaceholderShownInV1 = mIsPlaceholderShown && !mV2Enabled;
mDelegate = delegate;
mPageNavigationDelegate = pageNavigationDelegate;
mBottomSheetController = bottomSheetController;
......@@ -305,6 +307,11 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
return mStream;
}
/** @return Whether the placeholder shows in V1. */
public boolean isPlaceholderShownInV1() {
return mIsPlaceholderShownInV1;
}
/**
* Create a {@link Stream} for this class.
*/
......@@ -316,9 +323,7 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mScrollViewResizer = null;
}
boolean isPlaceholderShownInV1 = mIsPlaceholderShown && !mV2Enabled;
mStreamCreatedTimeMs = SystemClock.elapsedRealtime();
if (mV2Enabled) {
mStream = new FeedStream(mActivity, mShowDarkBackground, mSnackbarManager,
mPageNavigationDelegate, mBottomSheetController);
......@@ -333,14 +338,14 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
FeedProcessScopeFactory.getFeedConsumptionObserver(),
FeedProcessScopeFactory.getFeedLoggingBridge(), mActivity, mProfile);
mStream = FeedV1StreamCreator.createStream(mActivity, mImageLoader, actionApi,
mUiConfig, mSnackbarManager, mShowDarkBackground, isPlaceholderShownInV1);
mUiConfig, mSnackbarManager, mShowDarkBackground, mIsPlaceholderShownInV1);
}
mStreamLifecycleManager = mDelegate.createStreamLifecycleManager(mStream, mActivity);
View view = mStream.getView();
view.setBackgroundResource(R.color.default_bg_color);
if (isPlaceholderShownInV1) {
if (mIsPlaceholderShownInV1) {
// Set recyclerView as transparent until first patch of articles are loaded. Before
// that, the placeholder is shown.
view.getBackground().setAlpha(0);
......@@ -448,6 +453,11 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mSigninPromoView = (PersonalizedSigninPromoView) inflater.inflate(
R.layout.personalized_signin_promo_view_modern_content_suggestions, mRootView,
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;
}
......
......@@ -14,6 +14,7 @@ import android.widget.ScrollView;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.RecyclerView;
import org.chromium.base.MemoryPressureListener;
import org.chromium.base.memory.MemoryPressureCallback;
......@@ -205,6 +206,9 @@ public class FeedSurfaceMediator
@Override
public void onAddFinished() {
// After first batch of articles are loaded, set recyclerView back to
// non-transparent.
stream.getView().getBackground().setAlpha(255);
if (mContentFirstAvailableTimeMs == 0) {
mContentFirstAvailableTimeMs = SystemClock.elapsedRealtime();
if (mHasPendingUmaRecording) {
......@@ -214,6 +218,24 @@ public class FeedSurfaceMediator
}
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);
......
......@@ -31,11 +31,15 @@ public class StreamItemAnimator extends DefaultItemAnimator {
@Override
public void onAddFinished(RecyclerView.ViewHolder item) {
super.onAddFinished(item);
// After first patch of articles are loaded, set recyclerView back to non-transparent.
mParent.getBackground().setAlpha(255);
mContentChangedListener.onAddFinished();
}
@Override
public void onAddStarting(RecyclerView.ViewHolder item) {
super.onAddStarting(item);
mContentChangedListener.onAddStarting();
}
@Override
public void onAnimationFinished(RecyclerView.ViewHolder viewHolder) {
super.onAnimationFinished(viewHolder);
......
......@@ -35,4 +35,11 @@ public class StreamContentChangedListener implements ContentChangedListener {
listener.onAddFinished();
}
}
@Override
public void onAddStarting() {
for (ContentChangedListener listener : mListeners) {
listener.onAddStarting();
}
}
}
......@@ -153,6 +153,12 @@ public interface Stream {
* {@link androidx.recyclerview.widget.SimpleItemAnimator#onAddFinished} event is received.
*/
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. */
......
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