Commit d96bf1d7 authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

Hook up a long-press context menu for contextual suggestions

Bug: 822952
Change-Id: I23a567488375f4308cbbef8de63c2ae60c1bcfac
Reviewed-on: https://chromium-review.googlesource.com/979259Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545959}
parent 3112ed9e
......@@ -12,11 +12,13 @@ import android.view.ViewGroup;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsModel.ClusterListObservable;
import org.chromium.chrome.browser.modelutil.RecyclerViewModelChangeProcessor;
import org.chromium.chrome.browser.ntp.ContextMenuManager;
import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.suggestions.SuggestionsRecyclerView;
import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import org.chromium.ui.base.WindowAndroid;
/**
* Coordinator for the content sub-component. Responsible for communication with the parent
......@@ -24,6 +26,8 @@ import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
*/
class ContentCoordinator {
private final ContextualSuggestionsModel mModel;
private final WindowAndroid mWindowAndroid;
private final ContextMenuManager mContextMenuManager;
private SuggestionsRecyclerView mRecyclerView;
private RecyclerViewModelChangeProcessor<ClusterListObservable, NewTabPageViewHolder>
......@@ -37,16 +41,24 @@ class ContentCoordinator {
* @param uiDelegate The {@link SuggestionsUiDelegate} used to help construct items in the
* content view.
* @param model The {@link ContextualSuggestionsModel} for the component.
* @param windowAndroid The {@link WindowAndroid} for attaching a context menu listener.
* @param closeContextMenuCallback The callback when a context menu is closed.
*/
ContentCoordinator(Context context, ViewGroup parentView, Profile profile,
SuggestionsUiDelegate uiDelegate, ContextualSuggestionsModel model) {
SuggestionsUiDelegate uiDelegate, ContextualSuggestionsModel model,
WindowAndroid windowAndroid, Runnable closeContextMenuCallback) {
mModel = model;
mWindowAndroid = windowAndroid;
mRecyclerView = (SuggestionsRecyclerView) LayoutInflater.from(context).inflate(
R.layout.contextual_suggestions_layout, parentView, false);
ContextualSuggestionsAdapter adapter = new ContextualSuggestionsAdapter(
context, profile, new UiConfig(mRecyclerView), uiDelegate, mModel);
mContextMenuManager = new ContextMenuManager(uiDelegate.getNavigationDelegate(),
mRecyclerView::setTouchEnabled, closeContextMenuCallback);
mWindowAndroid.addContextMenuCloseListener(mContextMenuManager);
ContextualSuggestionsAdapter adapter = new ContextualSuggestionsAdapter(context, profile,
new UiConfig(mRecyclerView), uiDelegate, mModel, mContextMenuManager);
mRecyclerView.setAdapter(adapter);
mModelChangeProcessor = new RecyclerViewModelChangeProcessor<>(adapter);
......@@ -68,5 +80,6 @@ class ContentCoordinator {
// The model outlives the content sub-component. Remove the observer so that this object
// can be garbage collected.
mModel.mClusterListObservable.removeObserver(mModelChangeProcessor);
mWindowAndroid.removeContextMenuCloseListener(mContextMenuManager);
}
}
......@@ -19,6 +19,11 @@ public class ContextualSuggestionCardViewHolder extends SnippetArticleViewHolder
super(parent, contextMenuManager, uiDelegate, uiConfig, offlinePageBridge);
}
@Override
public boolean isItemSupported(@ContextMenuManager.ContextMenuItemId int menuItemId) {
return menuItemId != ContextMenuManager.ID_LEARN_MORE && super.isItemSupported(menuItemId);
}
@Override
public boolean isDismissable() {
return false;
......
......@@ -10,6 +10,7 @@ import android.view.ViewGroup;
import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsModel.ClusterListObservable;
import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter;
import org.chromium.chrome.browser.ntp.ContextMenuManager;
import org.chromium.chrome.browser.ntp.cards.ItemViewType;
import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder;
import org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder;
......@@ -33,9 +34,9 @@ class ContextualSuggestionsAdapter
return new SectionHeaderViewHolder(mRecyclerView, mUiConfig);
case ItemViewType.SNIPPET:
// TODO(twellington): Hook up ContextMenuManager.
return new ContextualSuggestionCardViewHolder(mRecyclerView, null, mUiDelegate,
mUiConfig, OfflinePageBridge.getForProfile(mProfile));
return new ContextualSuggestionCardViewHolder(mRecyclerView,
mContextMenuManager, mUiDelegate, mUiConfig,
OfflinePageBridge.getForProfile(mProfile));
default:
assert false;
......@@ -54,6 +55,7 @@ class ContextualSuggestionsAdapter
private final UiConfig mUiConfig;
private final SuggestionsUiDelegate mUiDelegate;
private final ContextualSuggestionsModel mModel;
private final ContextMenuManager mContextMenuManager;
private SuggestionsRecyclerView mRecyclerView;
......@@ -65,9 +67,11 @@ class ContextualSuggestionsAdapter
* @param uiDelegate The {@link SuggestionsUiDelegate} used to help construct items in the
* content view.
* @param model The {@link ContextualSuggestionsModel} for the component.
* @param contextMenuManager The {@link ContextMenuManager} used to display a context menu.
*/
ContextualSuggestionsAdapter(Context context, Profile profile, UiConfig uiConfig,
SuggestionsUiDelegate uiDelegate, ContextualSuggestionsModel model) {
SuggestionsUiDelegate uiDelegate, ContextualSuggestionsModel model,
ContextMenuManager contextMenuManager) {
super(model.mClusterListObservable);
setViewBinder(new ContextualSuggestionsViewBinder());
......@@ -76,6 +80,7 @@ class ContextualSuggestionsAdapter
mUiConfig = uiConfig;
mUiDelegate = uiDelegate;
mModel = model;
mContextMenuManager = contextMenuManager;
}
@Override
......
......@@ -77,8 +77,8 @@ public class ContextualSuggestionsCoordinator {
// a toolbar view when suggestions are fist available, and use this method to construct the
// content view when the sheet is opened.
mToolbarCoordinator = new ToolbarCoordinator(mActivity, mBottomSheet, mModel);
mContentCoordinator =
new ContentCoordinator(mActivity, mBottomSheet, mProfile, mUiDelegate, mModel);
mContentCoordinator = new ContentCoordinator(mActivity, mBottomSheet, mProfile, mUiDelegate,
mModel, mActivity.getWindowAndroid(), mActivity::closeContextMenu);
mBottomSheetContent = new ContextualSuggestionsBottomSheetContent(
mContentCoordinator, mToolbarCoordinator);
mBottomSheet.showContent(mBottomSheetContent);
......
......@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.TabLoadStatus;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.ActionModeController.ActionBarDelegate;
import org.chromium.chrome.browser.toolbar.ViewShiftingActionBarDelegate;
......@@ -672,13 +673,14 @@ public class BottomSheet
assert mTabModelSelector != null;
int tabLoadStatus;
int tabLoadStatus = TabLoadStatus.DEFAULT_PAGE_LOAD;
if (getActiveTab() != null && getActiveTab().isIncognito() == incognito) {
tabLoadStatus = getActiveTab().loadUrl(params);
} else {
// Do nothing if there is no available tab to load in.
return TabLoadStatus.PAGE_LOAD_FAILED;
// If no compatible tab is active behind the sheet, open a new one.
mTabModelSelector.openNewTab(
params, TabModel.TabLaunchType.FROM_CHROME_UI, getActiveTab(), incognito);
}
// In all non-native cases, minimize the sheet.
......
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