Commit 14cfdb78 authored by Pete Williamson's avatar Pete Williamson Committed by Commit Bot

Replace the Context with Activity.

Since Context is a base class for Activity, we can replace it with the
activity itself, and pass it as an argument whenever the context is
needed.

We need to do this because we require the activity for some UI operations.
This is in preparation for getting the bottom sheet manager, which is
only available on the ChromeActivity object.

Bug: 1091529
Change-Id: I26791f3a8536eb52fab36c4e01c115fe589e432a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2232822Reviewed-by: default avatarDan H <harringtond@chromium.org>
Commit-Queue: Peter Williamson <petewil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775752}
parent 4944dcd3
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.feed.library.api.client.scope; package org.chromium.chrome.browser.feed.library.api.client.scope;
import android.content.Context; import android.app.Activity;
import org.chromium.chrome.browser.feed.library.api.client.knowncontent.KnownContent; import org.chromium.chrome.browser.feed.library.api.client.knowncontent.KnownContent;
import org.chromium.chrome.browser.feed.library.api.client.lifecycle.AppLifecycleListener; import org.chromium.chrome.browser.feed.library.api.client.lifecycle.AppLifecycleListener;
...@@ -35,7 +35,7 @@ public interface ProcessScope extends Dumpable { ...@@ -35,7 +35,7 @@ public interface ProcessScope extends Dumpable {
KnownContent getKnownContent(); KnownContent getKnownContent();
/** Returns a {@link StreamScopeBuilder.Builder}. */ /** Returns a {@link StreamScopeBuilder.Builder}. */
StreamScopeBuilder createStreamScopeBuilder(Context context, ImageLoaderApi imageLoaderApi, StreamScopeBuilder createStreamScopeBuilder(Activity activity, ImageLoaderApi imageLoaderApi,
ActionApi actionApi, StreamConfiguration streamConfiguration, ActionApi actionApi, StreamConfiguration streamConfiguration,
CardConfiguration cardConfiguration, SnackbarApi snackbarApi, CardConfiguration cardConfiguration, SnackbarApi snackbarApi,
OfflineIndicatorApi offlineIndicatorApi, TooltipApi tooltipApi, OfflineIndicatorApi offlineIndicatorApi, TooltipApi tooltipApi,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.feed.library.api.client.scope; package org.chromium.chrome.browser.feed.library.api.client.scope;
import android.content.Context; import android.app.Activity;
import org.chromium.base.FeatureList; import org.chromium.base.FeatureList;
import org.chromium.chrome.browser.feed.library.api.host.action.ActionApi; import org.chromium.chrome.browser.feed.library.api.host.action.ActionApi;
...@@ -48,7 +48,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager; ...@@ -48,7 +48,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
/** A builder that creates a {@link StreamScope}. */ /** A builder that creates a {@link StreamScope}. */
public final class StreamScopeBuilder { public final class StreamScopeBuilder {
// Required external dependencies. // Required external dependencies.
private final Context mContext; private final Activity mActivity;
private final ActionApi mActionApi; private final ActionApi mActionApi;
private final ImageLoaderApi mImageLoaderApi; private final ImageLoaderApi mImageLoaderApi;
...@@ -84,7 +84,7 @@ public final class StreamScopeBuilder { ...@@ -84,7 +84,7 @@ public final class StreamScopeBuilder {
private HostBindingProvider mHostBindingProvider; private HostBindingProvider mHostBindingProvider;
/** Construct this builder using {@link ProcessScope#createStreamScopeBuilder} */ /** Construct this builder using {@link ProcessScope#createStreamScopeBuilder} */
public StreamScopeBuilder(Context context, ActionApi actionApi, ImageLoaderApi imageLoaderApi, public StreamScopeBuilder(Activity activity, ActionApi actionApi, ImageLoaderApi imageLoaderApi,
ProtocolAdapter protocolAdapter, FeedSessionManager feedSessionManager, ProtocolAdapter protocolAdapter, FeedSessionManager feedSessionManager,
ThreadUtils threadUtils, TimingUtils timingUtils, TaskQueue taskQueue, ThreadUtils threadUtils, TimingUtils timingUtils, TaskQueue taskQueue,
MainThreadRunner mainThreadRunner, Clock clock, DebugBehavior debugBehavior, MainThreadRunner mainThreadRunner, Clock clock, DebugBehavior debugBehavior,
...@@ -94,7 +94,7 @@ public final class StreamScopeBuilder { ...@@ -94,7 +94,7 @@ public final class StreamScopeBuilder {
FeedKnownContent feedKnownContent, TooltipApi tooltipApi, FeedKnownContent feedKnownContent, TooltipApi tooltipApi,
TooltipSupportedApi tooltipSupportedApi, ApplicationInfo applicationInfo, TooltipSupportedApi tooltipSupportedApi, ApplicationInfo applicationInfo,
FeedExtensionRegistry feedExtensionRegistry, SnackbarManager snackbarManager) { FeedExtensionRegistry feedExtensionRegistry, SnackbarManager snackbarManager) {
this.mContext = context; this.mActivity = activity;
this.mActionApi = actionApi; this.mActionApi = actionApi;
this.mImageLoaderApi = imageLoaderApi; this.mImageLoaderApi = imageLoaderApi;
this.mProtocolAdapter = protocolAdapter; this.mProtocolAdapter = protocolAdapter;
...@@ -166,12 +166,12 @@ public final class StreamScopeBuilder { ...@@ -166,12 +166,12 @@ public final class StreamScopeBuilder {
} }
if (FeatureList.isInitialized() if (FeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2)) { && ChromeFeatureList.isEnabled(ChromeFeatureList.INTEREST_FEED_V2)) {
mStream = new FeedStream(mContext, mIsBackgroundDark, mSnackbarManager); mStream = new FeedStream(mActivity, mIsBackgroundDark, mSnackbarManager);
} else { } else {
if (mStreamFactory == null) { if (mStreamFactory == null) {
mStreamFactory = new BasicStreamFactory(); mStreamFactory = new BasicStreamFactory();
} }
mStream = mStreamFactory.build(Validators.checkNotNull(mActionParserFactory), mContext, mStream = mStreamFactory.build(Validators.checkNotNull(mActionParserFactory), mActivity,
mApplicationInfo.getBuildType(), mCardConfiguration, mImageLoaderApi, mApplicationInfo.getBuildType(), mCardConfiguration, mImageLoaderApi,
Validators.checkNotNull(mCustomElementProvider), mDebugBehavior, mClock, Validators.checkNotNull(mCustomElementProvider), mDebugBehavior, mClock,
Validators.checkNotNull(mModelProviderFactory), Validators.checkNotNull(mModelProviderFactory),
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.feed.library.api.internal.scope; package org.chromium.chrome.browser.feed.library.api.internal.scope;
import android.content.Context; import android.app.Activity;
import org.chromium.chrome.browser.feed.library.api.client.knowncontent.KnownContent; import org.chromium.chrome.browser.feed.library.api.client.knowncontent.KnownContent;
import org.chromium.chrome.browser.feed.library.api.client.lifecycle.AppLifecycleListener; import org.chromium.chrome.browser.feed.library.api.client.lifecycle.AppLifecycleListener;
...@@ -175,12 +175,12 @@ public final class FeedProcessScope implements ProcessScope { ...@@ -175,12 +175,12 @@ public final class FeedProcessScope implements ProcessScope {
* <p>This is called by hosts so it must be public * <p>This is called by hosts so it must be public
*/ */
@Override @Override
public StreamScopeBuilder createStreamScopeBuilder(Context context, public StreamScopeBuilder createStreamScopeBuilder(Activity activity,
ImageLoaderApi imageLoaderApi, ActionApi actionApi, ImageLoaderApi imageLoaderApi, ActionApi actionApi,
StreamConfiguration streamConfiguration, CardConfiguration cardConfiguration, StreamConfiguration streamConfiguration, CardConfiguration cardConfiguration,
SnackbarApi snackbarApi, OfflineIndicatorApi offlineIndicatorApi, TooltipApi tooltipApi, SnackbarApi snackbarApi, OfflineIndicatorApi offlineIndicatorApi, TooltipApi tooltipApi,
SnackbarManager snackbarManager) { SnackbarManager snackbarManager) {
return new StreamScopeBuilder(context, actionApi, imageLoaderApi, mProtocolAdapter, return new StreamScopeBuilder(activity, actionApi, imageLoaderApi, mProtocolAdapter,
mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue, mMainThreadRunner, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue, mMainThreadRunner,
mClock, mDebugBehavior, streamConfiguration, cardConfiguration, mActionManager, mClock, mDebugBehavior, streamConfiguration, cardConfiguration, mActionManager,
mConfiguration, snackbarApi, mBasicLoggingApi, offlineIndicatorApi, mConfiguration, snackbarApi, mBasicLoggingApi, offlineIndicatorApi,
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
package org.chromium.chrome.browser.feed.v2; package org.chromium.chrome.browser.feed.v2;
import android.content.Context; import android.app.Activity;
import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -28,7 +27,7 @@ import java.util.List; ...@@ -28,7 +27,7 @@ import java.util.List;
public class FeedStream implements Stream { public class FeedStream implements Stream {
private static final String TAG = "FeedStream"; private static final String TAG = "FeedStream";
private final Context mContext; private final Activity mActivity;
private final FeedStreamSurface mFeedStreamSurface; private final FeedStreamSurface mFeedStreamSurface;
private final ObserverList<ScrollListener> mScrollListeners; private final ObserverList<ScrollListener> mScrollListeners;
...@@ -36,10 +35,12 @@ public class FeedStream implements Stream { ...@@ -36,10 +35,12 @@ public class FeedStream implements Stream {
// TODO(jianli): To be used. // TODO(jianli): To be used.
private boolean mIsStreamContentVisible = true; private boolean mIsStreamContentVisible = true;
public FeedStream(Context context, boolean isBackgroundDark, SnackbarManager snackbarManager) { public FeedStream(
this.mFeedStreamSurface = new FeedStreamSurface(null, () -> null, context, snackbarManager); Activity activity, boolean isBackgroundDark, SnackbarManager snackbarManager) {
this.mContext = // TODO(petewil): Use isBackgroundDark to turn on dark theme.
new ContextThemeWrapper(context, (isBackgroundDark ? R.style.Dark : R.style.Light)); this.mActivity = activity;
this.mFeedStreamSurface =
new FeedStreamSurface(null, () -> null, activity, snackbarManager);
this.mScrollListeners = new ObserverList<ScrollListener>(); this.mScrollListeners = new ObserverList<ScrollListener>();
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.feed.v2; package org.chromium.chrome.browser.feed.v2;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
...@@ -61,6 +62,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -61,6 +62,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
private final View mRootView; private final View mRootView;
private final HybridListRenderer mHybridListRenderer; private final HybridListRenderer mHybridListRenderer;
private final SnackbarManager mSnackbarManager; private final SnackbarManager mSnackbarManager;
private final Activity mActivity;
private int mHeaderCount; private int mHeaderCount;
...@@ -120,17 +122,18 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -120,17 +122,18 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
* client implementation. * client implementation.
*/ */
public FeedStreamSurface(TabModelSelector tabModelSelector, Supplier<Tab> tabProvider, public FeedStreamSurface(TabModelSelector tabModelSelector, Supplier<Tab> tabProvider,
Context activityContext, SnackbarManager snackbarManager) { Activity activity, SnackbarManager snackbarManager) {
mNativeFeedStreamSurface = FeedStreamSurfaceJni.get().init(FeedStreamSurface.this); mNativeFeedStreamSurface = FeedStreamSurfaceJni.get().init(FeedStreamSurface.this);
mTabModelSelector = tabModelSelector; mTabModelSelector = tabModelSelector;
mTabProvider = tabProvider; mTabProvider = tabProvider;
mSnackbarManager = snackbarManager; mSnackbarManager = snackbarManager;
mActivity = activity;
mContentManager = new FeedListContentManager(this, this); mContentManager = new FeedListContentManager(this, this);
ProcessScope processScope = xSurfaceProcessScope(); ProcessScope processScope = xSurfaceProcessScope();
if (processScope != null) { if (processScope != null) {
mSurfaceScope = xSurfaceProcessScope().obtainSurfaceScope(activityContext); mSurfaceScope = xSurfaceProcessScope().obtainSurfaceScope(mActivity);
} else { } else {
mSurfaceScope = null; mSurfaceScope = null;
} }
...@@ -138,7 +141,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand ...@@ -138,7 +141,7 @@ public class FeedStreamSurface implements SurfaceActionsHandler, FeedActionsHand
if (mSurfaceScope != null) { if (mSurfaceScope != null) {
mHybridListRenderer = mSurfaceScope.provideListRenderer(); mHybridListRenderer = mSurfaceScope.provideListRenderer();
} else { } else {
mHybridListRenderer = new NativeViewListRenderer(activityContext); mHybridListRenderer = new NativeViewListRenderer(mActivity);
} }
if (mHybridListRenderer != null) { if (mHybridListRenderer != null) {
......
...@@ -12,7 +12,6 @@ import static org.mockito.Mockito.when; ...@@ -12,7 +12,6 @@ import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; import static org.mockito.MockitoAnnotations.initMocks;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -108,7 +107,7 @@ public class StreamScopeBuilderTest { ...@@ -108,7 +107,7 @@ public class StreamScopeBuilderTest {
@Mock @Mock
private SnackbarManager mSnackbarManager; private SnackbarManager mSnackbarManager;
private Context mContext; private Activity mActivity;
private MainThreadRunner mMainThreadRunner; private MainThreadRunner mMainThreadRunner;
private ThreadUtils mThreadUtils; private ThreadUtils mThreadUtils;
private TimingUtils mTimingUtils; private TimingUtils mTimingUtils;
...@@ -119,12 +118,12 @@ public class StreamScopeBuilderTest { ...@@ -119,12 +118,12 @@ public class StreamScopeBuilderTest {
@Before @Before
public void setUp() { public void setUp() {
initMocks(this); initMocks(this);
mContext = Robolectric.buildActivity(Activity.class).get(); mActivity = Robolectric.buildActivity(Activity.class).get();
mMainThreadRunner = new MainThreadRunner(); mMainThreadRunner = new MainThreadRunner();
mThreadUtils = new ThreadUtils(); mThreadUtils = new ThreadUtils();
mTimingUtils = new TimingUtils(); mTimingUtils = new TimingUtils();
mClock = new FakeClock(); mClock = new FakeClock();
mApplicationInfo = new ApplicationInfo.Builder(mContext).setBuildType(BUILD_TYPE).build(); mApplicationInfo = new ApplicationInfo.Builder(mActivity).setBuildType(BUILD_TYPE).build();
when(mConfig.getValueOrDefault( when(mConfig.getValueOrDefault(
eq(ConfigKey.LOGGING_IMMEDIATE_CONTENT_THRESHOLD_MS), anyLong())) eq(ConfigKey.LOGGING_IMMEDIATE_CONTENT_THRESHOLD_MS), anyLong()))
.thenReturn(1000L); .thenReturn(1000L);
...@@ -134,7 +133,7 @@ public class StreamScopeBuilderTest { ...@@ -134,7 +133,7 @@ public class StreamScopeBuilderTest {
@Test @Test
public void testBasicBuild() { public void testBasicBuild() {
StreamScope streamScope = new StreamScopeBuilder(mContext, mActionApi, mImageLoaderApi, StreamScope streamScope = new StreamScopeBuilder(mActivity, mActionApi, mImageLoaderApi,
mProtocolAdapter, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue, mProtocolAdapter, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue,
mMainThreadRunner, mClock, DEBUG_BEHAVIOR, mStreamConfiguration, mCardConfiguration, mMainThreadRunner, mClock, DEBUG_BEHAVIOR, mStreamConfiguration, mCardConfiguration,
mActionManager, mConfig, mSnackbarApi, mBasicLoggingApi, mOfflineIndicatorApi, mActionManager, mConfig, mSnackbarApi, mBasicLoggingApi, mOfflineIndicatorApi,
...@@ -147,7 +146,7 @@ public class StreamScopeBuilderTest { ...@@ -147,7 +146,7 @@ public class StreamScopeBuilderTest {
@Test @Test
public void testComplexBuild() { public void testComplexBuild() {
StreamScope streamScope = new StreamScopeBuilder(mContext, mActionApi, mImageLoaderApi, StreamScope streamScope = new StreamScopeBuilder(mActivity, mActionApi, mImageLoaderApi,
mProtocolAdapter, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue, mProtocolAdapter, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue,
mMainThreadRunner, mClock, DEBUG_BEHAVIOR, mStreamConfiguration, mCardConfiguration, mMainThreadRunner, mClock, DEBUG_BEHAVIOR, mStreamConfiguration, mCardConfiguration,
mActionManager, mConfig, mSnackbarApi, mBasicLoggingApi, mOfflineIndicatorApi, mActionManager, mConfig, mSnackbarApi, mBasicLoggingApi, mOfflineIndicatorApi,
...@@ -165,7 +164,7 @@ public class StreamScopeBuilderTest { ...@@ -165,7 +164,7 @@ public class StreamScopeBuilderTest {
public void testStreamFactoryBuild() { public void testStreamFactoryBuild() {
setupStreamFactory(mStream); setupStreamFactory(mStream);
StreamScope streamScope = new StreamScopeBuilder(mContext, mActionApi, mImageLoaderApi, StreamScope streamScope = new StreamScopeBuilder(mActivity, mActionApi, mImageLoaderApi,
mProtocolAdapter, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue, mProtocolAdapter, mFeedSessionManager, mThreadUtils, mTimingUtils, mTaskQueue,
mMainThreadRunner, mClock, DEBUG_BEHAVIOR, mStreamConfiguration, mCardConfiguration, mMainThreadRunner, mClock, DEBUG_BEHAVIOR, mStreamConfiguration, mCardConfiguration,
mActionManager, mConfig, mSnackbarApi, mBasicLoggingApi, mOfflineIndicatorApi, mActionManager, mConfig, mSnackbarApi, mBasicLoggingApi, mOfflineIndicatorApi,
......
...@@ -9,7 +9,6 @@ import static org.mockito.Mockito.any; ...@@ -9,7 +9,6 @@ import static org.mockito.Mockito.any;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.view.View; import android.view.View;
...@@ -41,7 +40,7 @@ import java.util.Arrays; ...@@ -41,7 +40,7 @@ import java.util.Arrays;
public class FeedStreamSurfaceTest { public class FeedStreamSurfaceTest {
private static final String TEST_DATA = "test"; private static final String TEST_DATA = "test";
private FeedStreamSurface mFeedStreamSurface; private FeedStreamSurface mFeedStreamSurface;
private Context mContext; private Activity mActivity;
@Mock @Mock
private SnackbarManager mSnackbarManager; private SnackbarManager mSnackbarManager;
...@@ -57,9 +56,9 @@ public class FeedStreamSurfaceTest { ...@@ -57,9 +56,9 @@ public class FeedStreamSurfaceTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = Robolectric.buildActivity(Activity.class).get(); mActivity = Robolectric.buildActivity(Activity.class).get();
mocker.mock(FeedStreamSurfaceJni.TEST_HOOKS, mFeedStreamSurfaceJniMock); mocker.mock(FeedStreamSurfaceJni.TEST_HOOKS, mFeedStreamSurfaceJniMock);
mFeedStreamSurface = new FeedStreamSurface(null, () -> null, mContext, mSnackbarManager); mFeedStreamSurface = new FeedStreamSurface(null, () -> null, mActivity, mSnackbarManager);
} }
@Test @Test
...@@ -250,9 +249,9 @@ public class FeedStreamSurfaceTest { ...@@ -250,9 +249,9 @@ public class FeedStreamSurfaceTest {
FeedListContentManager contentManager = FeedListContentManager contentManager =
mFeedStreamSurface.getFeedListContentManagerForTesting(); mFeedStreamSurface.getFeedListContentManagerForTesting();
View v0 = new View(mContext); View v0 = new View(mActivity);
View v1 = new View(mContext); View v1 = new View(mActivity);
View v2 = new View(mContext); View v2 = new View(mActivity);
mFeedStreamSurface.setHeaderViews(Arrays.asList(v0, v1)); mFeedStreamSurface.setHeaderViews(Arrays.asList(v0, v1));
assertEquals(2, contentManager.getItemCount()); assertEquals(2, contentManager.getItemCount());
...@@ -280,8 +279,8 @@ public class FeedStreamSurfaceTest { ...@@ -280,8 +279,8 @@ public class FeedStreamSurfaceTest {
mFeedStreamSurface.getFeedListContentManagerForTesting(); mFeedStreamSurface.getFeedListContentManagerForTesting();
// Set 2 header views first. These should always be there throughout stream update. // Set 2 header views first. These should always be there throughout stream update.
View v0 = new View(mContext); View v0 = new View(mActivity);
View v1 = new View(mContext); View v1 = new View(mActivity);
mFeedStreamSurface.setHeaderViews(Arrays.asList(v0, v1)); mFeedStreamSurface.setHeaderViews(Arrays.asList(v0, v1));
assertEquals(2, contentManager.getItemCount()); assertEquals(2, contentManager.getItemCount());
assertEquals(v0, assertEquals(v0,
......
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