Commit 6db0d801 authored by Theresa's avatar Theresa Committed by Commit Bot

[EoC] Add a model property for the toolbar title

BUG=822943

Change-Id: Ic824bef823886958f0f2dae47aa9262a870dc4f7
Reviewed-on: https://chromium-review.googlesource.com/976872Reviewed-by: default avatarBecky Zhou <huayinz@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545431}
parent 082707af
......@@ -22,13 +22,13 @@
android:contentDescription="@null" />
<TextView
android:id="@+id/title"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:ellipsize="end"
android:text="@string/more"
android:textAppearance="@style/BlackBodyDefault" />
<!-- Use 50dp width and 16dp end/start padding to produce an 18dp, centered icon. -->
......
......@@ -8,7 +8,6 @@ import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.modelutil.RecyclerViewAdapter;
import org.chromium.chrome.browser.ntp.cards.ItemViewType;
import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo;
......@@ -72,8 +71,7 @@ class ContextualSuggestionsAdapter
mUiConfig = uiConfig;
mUiDelegate = uiDelegate;
mCategoryInfo = new SuggestionsCategoryInfo(KnownCategories.CONTEXTUAL,
context.getString(R.string.contextual_suggestions_title),
mCategoryInfo = new SuggestionsCategoryInfo(KnownCategories.CONTEXTUAL, "",
ContentSuggestionsCardLayout.FULL_CARD, ContentSuggestionsAdditionalAction.NONE,
false, "");
}
......
......@@ -48,7 +48,8 @@ public class ContextualSuggestionsCoordinator {
mProfile = Profile.getLastUsedProfile().getOriginalProfile();
mModel = new ContextualSuggestionsModel();
mMediator = new ContextualSuggestionsMediator(mProfile, tabModelSelector, this, mModel);
mMediator = new ContextualSuggestionsMediator(
mActivity, mProfile, tabModelSelector, this, mModel);
SuggestionsSource suggestionsSource = mMediator.getSuggestionsSource();
SuggestionsNavigationDelegate navigationDelegate = new SuggestionsNavigationDelegateImpl(
......
......@@ -4,11 +4,13 @@
package org.chromium.chrome.browser.contextual_suggestions;
import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.webkit.URLUtil;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
......@@ -31,10 +33,10 @@ import java.util.List;
* component coordinator(s).
*/
class ContextualSuggestionsMediator {
private ContextualSuggestionsCoordinator mCoordinator;
private ContextualSuggestionsModel mModel;
private SnippetsBridge mBridge;
private final Context mContext;
private final ContextualSuggestionsCoordinator mCoordinator;
private final ContextualSuggestionsModel mModel;
private final SnippetsBridge mBridge;
private final TabModelSelectorTabModelObserver mTabModelObserver;
private final TabObserver mTabObserver;
......@@ -45,13 +47,16 @@ class ContextualSuggestionsMediator {
/**
* Construct a new {@link ContextualSuggestionsMediator}.
* @param context The {@link Context} used to retrieve resources.
* @param profile The regular {@link Profile}.
* @param tabModelSelector The {@link TabModelSelector} for the containing activity.
* @param coordinator The {@link ContextualSuggestionsCoordinator} for the component.
* @param model The {@link ContextualSuggestionsModel} for the component.
*/
ContextualSuggestionsMediator(Profile profile, TabModelSelector tabModelSelector,
ContextualSuggestionsCoordinator coordinator, ContextualSuggestionsModel model) {
ContextualSuggestionsMediator(Context context, Profile profile,
TabModelSelector tabModelSelector, ContextualSuggestionsCoordinator coordinator,
ContextualSuggestionsModel model) {
mContext = context;
mCoordinator = coordinator;
mModel = model;
......@@ -128,12 +133,18 @@ class ContextualSuggestionsMediator {
private void clearSuggestions() {
mModel.setSuggestions(new ArrayList<SnippetArticle>());
mModel.setCloseButtonOnClickListener(null);
mModel.setTitle(null);
mCoordinator.removeSuggestions();
}
private void displaySuggestions(List<SnippetArticle> suggestions) {
mModel.setSuggestions(suggestions);
mModel.setCloseButtonOnClickListener(view -> { clearSuggestions(); });
// TODO(twellington): Replace this with the first cluster title.
mModel.setTitle(mContext.getString(
R.string.contextual_suggestions_toolbar_title, suggestions.get(0).mTitle));
mCoordinator.displaySuggestions();
}
......
......@@ -46,6 +46,7 @@ class ContextualSuggestionsModel extends PropertyObservable<PropertyKey> {
SuggestionsList mSuggestionsList = new SuggestionsList();
private OnClickListener mCloseButtonOnClickListener;
private String mTitle;
/**
* @param suggestions The list of current suggestions. May be an empty list if no
......@@ -63,11 +64,22 @@ class ContextualSuggestionsModel extends PropertyObservable<PropertyKey> {
/** @param listener The {@link OnClickListener} for the close button. */
void setCloseButtonOnClickListener(OnClickListener listener) {
mCloseButtonOnClickListener = listener;
notifyPropertyChanged(new PropertyKey(PropertyKey.ON_CLICK_LISTENER_PROPERTY));
notifyPropertyChanged(new PropertyKey(PropertyKey.CLOSE_BUTTON_ON_CLICK_LISTENER));
}
/** @return The {@link OnClickListener} for the close button. */
OnClickListener getCloseButtonOnClickListener() {
return mCloseButtonOnClickListener;
}
/** @param title The title to display in the toolbar. */
void setTitle(String title) {
mTitle = title;
notifyPropertyChanged(new PropertyKey(PropertyKey.TITLE));
}
/** @return title The title to display in the toolbar. */
String getTitle() {
return mTitle;
}
}
......@@ -14,11 +14,11 @@ import java.lang.annotation.RetentionPolicy;
*/
class PropertyKey {
/** The unique identifiers for properties held in the model. */
@IntDef({ON_CLICK_LISTENER_PROPERTY})
@IntDef({CLOSE_BUTTON_ON_CLICK_LISTENER, TITLE})
@Retention(RetentionPolicy.SOURCE)
@interface Key {}
static final int ON_CLICK_LISTENER_PROPERTY = 0;
// TODO(twellington): Add a property for the toolbar title.
static final int CLOSE_BUTTON_ON_CLICK_LISTENER = 0;
static final int TITLE = 1;
@Key
Integer mKey;
......
......@@ -24,9 +24,12 @@ class ToolbarModelChangeProcessor implements PropertyObserver<PropertyKey> {
private static void bindProperty(
ToolbarView view, ContextualSuggestionsModel model, PropertyKey propertyKey) {
switch (propertyKey.mKey) {
case PropertyKey.ON_CLICK_LISTENER_PROPERTY:
case PropertyKey.CLOSE_BUTTON_ON_CLICK_LISTENER:
view.setOnClickListener(model.getCloseButtonOnClickListener());
break;
case PropertyKey.TITLE:
view.setTitle(model.getTitle());
break;
default:
assert false;
}
......@@ -48,7 +51,8 @@ class ToolbarModelChangeProcessor implements PropertyObserver<PropertyKey> {
// The ToolbarCoordinator is created dynamically as needed, so the initial model state
// needs to be bound on creation.
ViewBinder.bindProperty(
mToolbarView, mModel, new PropertyKey(PropertyKey.ON_CLICK_LISTENER_PROPERTY));
mToolbarView, mModel, new PropertyKey(PropertyKey.CLOSE_BUTTON_ON_CLICK_LISTENER));
ViewBinder.bindProperty(mToolbarView, mModel, new PropertyKey(PropertyKey.TITLE));
}
@Override
......
......@@ -8,12 +8,14 @@ import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.chrome.R;
/** The toolbar view, containing an icon, title and close button. */
public class ToolbarView extends LinearLayout {
private View mCloseButton;
private TextView mTitle;
public ToolbarView(Context context, AttributeSet attrs) {
super(context, attrs);
......@@ -24,9 +26,14 @@ public class ToolbarView extends LinearLayout {
super.onFinishInflate();
mCloseButton = findViewById(R.id.close_button);
mTitle = (TextView) findViewById(R.id.title);
}
void setCloseButtonOnClickListener(OnClickListener listener) {
mCloseButton.setOnClickListener(listener);
}
void setTitle(String title) {
mTitle.setText(title);
}
}
......@@ -2447,8 +2447,8 @@ Google may use your browsing activity, content on some sites you visit, and othe
<message name="IDS_NTP_ALL_DISMISSED_REFRESH" desc="Text label for button to refresh the New Tab Page when all suggested content has been dismissed. [CHAR-LIMIT=20]">
Refresh
</message>
<message name="IDS_CONTEXTUAL_SUGGESTIONS_TITLE" desc="The title for a section containing a list of article suggestions based on the user's current webpage. The title tells users that the list contains articles viewed by people who also viewed the current webpage.">
People also viewed
<message name="IDS_CONTEXTUAL_SUGGESTIONS_TOOLBAR_TITLE" desc="The title displayed above a list of content suggestions based on the user's current webpage. The title tells the user that the list contains more suggestions related to the topic they are currently viewing.">
More about <ph name="TOPIC">%1$s<ex>Game of Thrones</ex></ph>
</message>
<!-- Toolbar button strings -->
......
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