Commit c7d05f45 authored by Jian Li's avatar Jian Li Committed by Commit Bot

Show load spinner for Feed v2

Bug: none
Change-Id: Iad6d5575615324bf5748b48db547104008e976f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253146
Commit-Queue: Jian Li <jianli@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781594}
parent 104ea49e
......@@ -19,6 +19,7 @@ if (enable_feed_in_chrome) {
"core/java/res/drawable/hairline_border_card_background_with_inset.xml",
"core/java/res/layout/feed_more_button.xml",
"core/java/res/layout/feed_simple_list_item.xml",
"core/java/res/layout/feed_spinner.xml",
"core/java/res/layout/feed_spinner_gone.xml",
"core/java/res/layout/no_content.xml",
"core/java/res/layout/zero_state.xml",
......
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<org.chromium.chrome.browser.feed.shared.ui.MaterialSpinnerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading_spinner"
android:layout_width="match_parent"
android:layout_height="@dimen/feed_suggestion_card_action_min_height"
android:layout_gravity="center" />
......@@ -4,7 +4,7 @@ Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<org.chromium.chrome.browser.feed.library.sharedstream.ui.MaterialSpinnerView
<org.chromium.chrome.browser.feed.shared.ui.MaterialSpinnerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading_spinner"
android:layout_width="match_parent"
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.feed.library.sharedstream.ui;
package org.chromium.chrome.browser.feed.shared.ui;
import android.content.Context;
import android.content.res.Resources.Theme;
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.feed.v2;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -76,17 +77,30 @@ public class FeedListContentManager implements ListContentManager {
* For the content that is supported by the native view.
*/
public static class NativeViewContent extends FeedContent {
private final View mNativeView;
private View mNativeView;
private int mResId;
/** Holds an inflated native view. */
public NativeViewContent(String key, View nativeView) {
super(key);
assert nativeView != null;
mNativeView = nativeView;
}
/** Holds a resource ID used to inflate a native view. */
public NativeViewContent(String key, int resId) {
super(key);
mResId = resId;
}
/**
* Returns the native view if the content is supported by it. Null otherwise.
*/
public View getNativeView() {
public View getNativeView(ViewGroup parent) {
if (mNativeView == null) {
mNativeView =
LayoutInflater.from(parent.getContext()).inflate(mResId, parent, false);
}
return mNativeView;
}
......@@ -231,12 +245,12 @@ public class FeedListContentManager implements ListContentManager {
public View getNativeView(int index, ViewGroup parent) {
assert mFeedContentList.get(index).isNativeView();
NativeViewContent nativeViewContent = (NativeViewContent) mFeedContentList.get(index);
return nativeViewContent.getNativeView();
return nativeViewContent.getNativeView(parent);
}
@Override
public void bindNativeView(int index, View v) {
// TODO(jianli): to be implemented.
// Nothing to do.
}
@Override
......
......@@ -50,8 +50,8 @@ public class FeedStream implements Stream {
BottomSheetController bottomSheetController) {
// TODO(petewil): Use isBackgroundDark to turn on dark theme.
this.mActivity = activity;
this.mFeedStreamSurface = new FeedStreamSurface(
activity, snackbarManager, nativePageNavigationDelegate, bottomSheetController);
this.mFeedStreamSurface = new FeedStreamSurface(activity, isBackgroundDark, snackbarManager,
nativePageNavigationDelegate, bottomSheetController);
this.mScrollListeners = new ObserverList<ScrollListener>();
}
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.feed.v2;
import android.app.Activity;
import android.content.Context;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.TextView;
......@@ -34,6 +35,7 @@ import org.chromium.chrome.browser.xsurface.ProcessScope;
import org.chromium.chrome.browser.xsurface.SurfaceActionsHandler;
import org.chromium.chrome.browser.xsurface.SurfaceDependencyProvider;
import org.chromium.chrome.browser.xsurface.SurfaceScope;
import org.chromium.chrome.feed.R;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
import org.chromium.components.feed.proto.FeedUiProto.SharedState;
......@@ -161,20 +163,24 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
* Creates a {@link FeedStreamSurface} for creating native side bridge to access native feed
* client implementation.
*/
public FeedStreamSurface(Activity activity, SnackbarManager snackbarManager,
NativePageNavigationDelegate pageNavigationDelegate,
public FeedStreamSurface(Activity activity, boolean isBackgroundDark,
SnackbarManager snackbarManager, NativePageNavigationDelegate pageNavigationDelegate,
BottomSheetController bottomSheetController) {
mNativeFeedStreamSurface = FeedStreamSurfaceJni.get().init(FeedStreamSurface.this);
mSnackbarManager = snackbarManager;
mActivity = activity;
mPageNavigationDelegate = pageNavigationDelegate;
mBottomSheetController = bottomSheetController;
mContentManager = new FeedListContentManager(this, this);
Context context = new ContextThemeWrapper(
activity, (isBackgroundDark ? R.style.Dark : R.style.Light));
ProcessScope processScope = xSurfaceProcessScope();
if (processScope != null) {
mSurfaceScope = processScope.obtainSurfaceScope(mActivity);
mSurfaceScope = processScope.obtainSurfaceScope(context);
} else {
mSurfaceScope = null;
}
......@@ -182,7 +188,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
if (mSurfaceScope != null) {
mHybridListRenderer = mSurfaceScope.provideListRenderer();
} else {
mHybridListRenderer = new NativeViewListRenderer(mActivity);
mHybridListRenderer = new NativeViewListRenderer(context);
}
if (mHybridListRenderer != null) {
......@@ -345,9 +351,11 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
if (slice.getSliceDataCase() == SliceDataCase.XSURFACE_SLICE) {
return new FeedListContentManager.ExternalViewContent(
sliceId, slice.getXsurfaceSlice().getXsurfaceFrame().toByteArray());
} else if (slice.getSliceDataCase() == SliceDataCase.LOADING_SPINNER_SLICE) {
return new FeedListContentManager.NativeViewContent(sliceId, R.layout.feed_spinner);
} else {
// TODO(jianli): Create native view for ZeroStateSlice.
TextView view = new TextView(ContextUtils.getApplicationContext());
TextView view = new TextView(mActivity);
view.setText(sliceId);
return new FeedListContentManager.NativeViewContent(sliceId, view);
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.feed.library.sharedstream.ui;
package org.chromium.chrome.browser.feed.shared.ui;
import static com.google.common.truth.Truth.assertThat;
......
......@@ -374,12 +374,12 @@ if (enable_feed_in_chrome) {
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library/sharedstream/scroll/ScrollLogger.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library/sharedstream/scroll/ScrollRestoreHelper.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library/sharedstream/scroll/ScrollTracker.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library/sharedstream/ui/MaterialSpinnerView.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/shared/FeedSurfaceDelegate.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/shared/FeedSurfaceProvider.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/shared/stream/Header.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/shared/stream/NonDismissibleHeader.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/shared/stream/Stream.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/shared/ui/MaterialSpinnerView.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/tooltip/BasicTooltipApi.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/tooltip/BasicTooltipSupportedApi.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/tooltip/FeedTooltipUtils.java",
......@@ -638,7 +638,7 @@ if (enable_feed_in_chrome) {
"//chrome/android/feed/core/javatests/src/org/chromium/chrome/browser/feed/library/sharedstream/scroll/ScrollLoggerTest.java",
"//chrome/android/feed/core/javatests/src/org/chromium/chrome/browser/feed/library/sharedstream/scroll/ScrollRestoreHelperTest.java",
"//chrome/android/feed/core/javatests/src/org/chromium/chrome/browser/feed/library/sharedstream/scroll/ScrollTrackerTest.java",
"//chrome/android/feed/core/javatests/src/org/chromium/chrome/browser/feed/library/sharedstream/ui/MaterialSpinnerViewTest.java",
"//chrome/android/feed/core/javatests/src/org/chromium/chrome/browser/feed/shared/ui/MaterialSpinnerViewTest.java",
"junit/src/org/chromium/chrome/browser/feed/FeedApplicationInfoTest.java",
"junit/src/org/chromium/chrome/browser/feed/FeedContentStorageTest.java",
"junit/src/org/chromium/chrome/browser/feed/FeedImageLoaderTest.java",
......
......@@ -63,8 +63,8 @@ public class FeedStreamSurfaceTest {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.buildActivity(Activity.class).get();
mocker.mock(FeedStreamSurfaceJni.TEST_HOOKS, mFeedStreamSurfaceJniMock);
mFeedStreamSurface =
new FeedStreamSurface(mActivity, mSnackbarManager, null, mBottomSheetController);
mFeedStreamSurface = new FeedStreamSurface(
mActivity, false, mSnackbarManager, null, mBottomSheetController);
}
@Test
......@@ -262,10 +262,10 @@ public class FeedStreamSurfaceTest {
assertEquals(2, contentManager.getItemCount());
assertEquals(v0,
((FeedListContentManager.NativeViewContent) contentManager.getContent(0))
.getNativeView());
.getNativeView(null));
assertEquals(v1,
((FeedListContentManager.NativeViewContent) contentManager.getContent(1))
.getNativeView());
.getNativeView(null));
}
@Test
......@@ -281,10 +281,10 @@ public class FeedStreamSurfaceTest {
assertEquals(2, contentManager.getItemCount());
assertEquals(v0,
((FeedListContentManager.NativeViewContent) contentManager.getContent(0))
.getNativeView());
.getNativeView(null));
assertEquals(v1,
((FeedListContentManager.NativeViewContent) contentManager.getContent(1))
.getNativeView());
.getNativeView(null));
View v2 = new View(mActivity);
View v3 = new View(mActivity);
......@@ -293,13 +293,13 @@ public class FeedStreamSurfaceTest {
assertEquals(3, contentManager.getItemCount());
assertEquals(v2,
((FeedListContentManager.NativeViewContent) contentManager.getContent(0))
.getNativeView());
.getNativeView(null));
assertEquals(v0,
((FeedListContentManager.NativeViewContent) contentManager.getContent(1))
.getNativeView());
.getNativeView(null));
assertEquals(v3,
((FeedListContentManager.NativeViewContent) contentManager.getContent(2))
.getNativeView());
.getNativeView(null));
}
@Test
......@@ -315,10 +315,10 @@ public class FeedStreamSurfaceTest {
assertEquals(2, contentManager.getItemCount());
assertEquals(v0,
((FeedListContentManager.NativeViewContent) contentManager.getContent(0))
.getNativeView());
.getNativeView(null));
assertEquals(v1,
((FeedListContentManager.NativeViewContent) contentManager.getContent(1))
.getNativeView());
.getNativeView(null));
final int headers = 2;
// Add 3 new slices at first.
......@@ -394,10 +394,10 @@ public class FeedStreamSurfaceTest {
assertEquals(2, contentManager.getItemCount());
assertEquals(v0,
((FeedListContentManager.NativeViewContent) contentManager.getContent(0))
.getNativeView());
.getNativeView(null));
assertEquals(v1,
((FeedListContentManager.NativeViewContent) contentManager.getContent(1))
.getNativeView());
.getNativeView(null));
final int headers = 2;
// Add 3 new slices.
......@@ -414,10 +414,10 @@ public class FeedStreamSurfaceTest {
assertEquals(headers, contentManager.getItemCount());
assertEquals(v0,
((FeedListContentManager.NativeViewContent) contentManager.getContent(0))
.getNativeView());
.getNativeView(null));
assertEquals(v1,
((FeedListContentManager.NativeViewContent) contentManager.getContent(1))
.getNativeView());
.getNativeView(null));
}
private SliceUpdate createSliceUpdateForExistingSlice(String sliceId) {
......
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