Commit 7ed89d70 authored by Carlos Knippschild's avatar Carlos Knippschild Committed by Commit Bot

Show branded Feed header on non-Google NTP.

Update the articles suggestions' header to show a Google branded title
when a non-default search engine is selected. This is to make it clear
to users that even though the search engine is different, the suggested
content is still being provided by Google.

Bug: 1031288
Change-Id: I550176d03ef9d9eeff442157a780467e5b2bc6cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959628
Commit-Queue: Carlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723409}
parent bf97733f
...@@ -26,17 +26,20 @@ import org.chromium.chrome.browser.ntp.snippets.SectionHeader; ...@@ -26,17 +26,20 @@ import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar; import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView; import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
import org.chromium.chrome.browser.signin.SigninManager; import org.chromium.chrome.browser.signin.SigninManager;
import org.chromium.chrome.browser.signin.SigninPromoUtil; import org.chromium.chrome.browser.signin.SigninPromoUtil;
import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
/** /**
* A mediator for the {@link FeedSurfaceCoordinator} responsible for interacting with the * A mediator for the {@link FeedSurfaceCoordinator} responsible for interacting with the
* native library and handling business logic. * native library and handling business logic.
*/ */
class FeedSurfaceMediator class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
implements NewTabPageLayout.ScrollDelegate, ContextMenuManager.TouchEnabledDelegate { ContextMenuManager.TouchEnabledDelegate,
TemplateUrlServiceObserver {
private final FeedSurfaceCoordinator mCoordinator; private final FeedSurfaceCoordinator mCoordinator;
private final @Nullable SnapScrollHelper mSnapScrollHelper; private final @Nullable SnapScrollHelper mSnapScrollHelper;
private final PrefChangeRegistrar mPrefChangeRegistrar; private final PrefChangeRegistrar mPrefChangeRegistrar;
...@@ -78,6 +81,7 @@ class FeedSurfaceMediator ...@@ -78,6 +81,7 @@ class FeedSurfaceMediator
void destroy() { void destroy() {
destroyPropertiesForStream(); destroyPropertiesForStream();
mPrefChangeRegistrar.destroy(); mPrefChangeRegistrar.destroy();
TemplateUrlServiceFactory.get().removeObserver(this);
} }
private void initialize() { private void initialize() {
...@@ -146,12 +150,11 @@ class FeedSurfaceMediator ...@@ -146,12 +150,11 @@ class FeedSurfaceMediator
PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_LIST_VISIBLE); PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_LIST_VISIBLE);
if (mHasHeader) { if (mHasHeader) {
Resources res = mCoordinator.getSectionHeaderView().getResources();
mSectionHeader = new SectionHeader( mSectionHeader = new SectionHeader(
res.getString(R.string.ntp_article_suggestions_section_header), getSectionHeaderText(), suggestionsVisible, this::onSectionHeaderToggled);
suggestionsVisible, this::onSectionHeaderToggled);
mPrefChangeRegistrar.addObserver( mPrefChangeRegistrar.addObserver(
Pref.NTP_ARTICLES_LIST_VISIBLE, this::updateSectionHeader); Pref.NTP_ARTICLES_LIST_VISIBLE, this::updateSectionHeader);
TemplateUrlServiceFactory.get().addObserver(this);
mCoordinator.getSectionHeaderView().setHeader(mSectionHeader); mCoordinator.getSectionHeaderView().setHeader(mSectionHeader);
} }
// Show feed if there is no header that would allow user to hide feed. // Show feed if there is no header that would allow user to hide feed.
...@@ -191,6 +194,7 @@ class FeedSurfaceMediator ...@@ -191,6 +194,7 @@ class FeedSurfaceMediator
} }
mPrefChangeRegistrar.removeObserver(Pref.NTP_ARTICLES_LIST_VISIBLE); mPrefChangeRegistrar.removeObserver(Pref.NTP_ARTICLES_LIST_VISIBLE);
TemplateUrlServiceFactory.get().removeObserver(this);
} }
/** /**
...@@ -203,8 +207,9 @@ class FeedSurfaceMediator ...@@ -203,8 +207,9 @@ class FeedSurfaceMediator
} }
} }
/** Update whether the section header should be expanded. */ /** Update whether the section header should be expanded and its text contents. */
private void updateSectionHeader() { private void updateSectionHeader() {
mSectionHeader.setHeaderText(getSectionHeaderText());
boolean suggestionsVisible = boolean suggestionsVisible =
PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_LIST_VISIBLE); PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_LIST_VISIBLE);
if (mSectionHeader.isExpanded() != suggestionsVisible) mSectionHeader.toggleHeader(); if (mSectionHeader.isExpanded() != suggestionsVisible) mSectionHeader.toggleHeader();
...@@ -213,6 +218,7 @@ class FeedSurfaceMediator ...@@ -213,6 +218,7 @@ class FeedSurfaceMediator
} }
if (suggestionsVisible) mCoordinator.getStreamLifecycleManager().activate(); if (suggestionsVisible) mCoordinator.getStreamLifecycleManager().activate();
mStreamContentChanged = true; mStreamContentChanged = true;
mCoordinator.getSectionHeaderView().updateVisuals();
} }
/** /**
...@@ -227,6 +233,16 @@ class FeedSurfaceMediator ...@@ -227,6 +233,16 @@ class FeedSurfaceMediator
mCoordinator.getSectionHeaderView().updateVisuals(); mCoordinator.getSectionHeaderView().updateVisuals();
} }
/** Returns the section header text based on the selected default search engine */
private String getSectionHeaderText() {
Resources res = mCoordinator.getSectionHeaderView().getResources();
final int sectionHeaderStringId =
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()
? R.string.ntp_article_suggestions_section_header
: R.string.ntp_article_suggestions_section_header_branded;
return res.getString(sectionHeaderStringId);
}
/** /**
* Callback on sign-in promo is dismissed. * Callback on sign-in promo is dismissed.
*/ */
...@@ -328,6 +344,11 @@ class FeedSurfaceMediator ...@@ -328,6 +344,11 @@ class FeedSurfaceMediator
} }
} }
@Override
public void onTemplateURLServiceChanged() {
updateSectionHeader();
}
/** /**
* The {@link SignInPromo} for the Feed. * The {@link SignInPromo} for the Feed.
* TODO(huayinz): Update content and visibility through a ModelChangeProcessor. * TODO(huayinz): Update content and visibility through a ModelChangeProcessor.
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.ntp.snippets; package org.chromium.chrome.browser.ntp.snippets;
import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.chromium.chrome.browser.ntp.cards.ItemViewType; import org.chromium.chrome.browser.ntp.cards.ItemViewType;
...@@ -15,7 +17,7 @@ import org.chromium.chrome.browser.ntp.cards.OptionalLeaf; ...@@ -15,7 +17,7 @@ import org.chromium.chrome.browser.ntp.cards.OptionalLeaf;
*/ */
public class SectionHeader extends OptionalLeaf { public class SectionHeader extends OptionalLeaf {
/** The header text to be shown. */ /** The header text to be shown. */
private final String mHeaderText; private String mHeaderText;
private Runnable mToggleCallback; private Runnable mToggleCallback;
private boolean mIsExpanded; private boolean mIsExpanded;
...@@ -51,6 +53,13 @@ public class SectionHeader extends OptionalLeaf { ...@@ -51,6 +53,13 @@ public class SectionHeader extends OptionalLeaf {
return mHeaderText; return mHeaderText;
} }
public void setHeaderText(String headerText) {
if (TextUtils.equals(mHeaderText, headerText)) return;
mHeaderText = headerText;
notifyItemChanged(0, SectionHeaderViewHolder::updateVisuals);
}
/** /**
* @return Whether or not the header is expandable. * @return Whether or not the header is expandable.
*/ */
......
...@@ -48,18 +48,21 @@ public class SectionHeaderView extends LinearLayout implements View.OnClickListe ...@@ -48,18 +48,21 @@ public class SectionHeaderView extends LinearLayout implements View.OnClickListe
mHeader = header; mHeader = header;
if (mHeader == null) return; if (mHeader == null) return;
mTitleView.setText(header.getHeaderText()); mStatusView.setVisibility(mHeader.isExpandable() ? View.VISIBLE : View.GONE);
mStatusView.setVisibility(header.isExpandable() ? View.VISIBLE : View.GONE);
updateVisuals(); updateVisuals();
setOnClickListener(header.isExpandable() ? this : null); setOnClickListener(mHeader.isExpandable() ? this : null);
} }
/** Update the header view based on whether the header is expanded. */ /** Update the header view based on whether the header is expanded and its text contents. */
public void updateVisuals() { public void updateVisuals() {
if (mHeader == null || !mHeader.isExpandable()) return; if (mHeader == null) return;
mTitleView.setText(mHeader.getHeaderText());
mStatusView.setText(mHeader.isExpanded() ? R.string.hide : R.string.show); if (mHeader.isExpandable()) {
setBackgroundResource( mStatusView.setText(mHeader.isExpanded() ? R.string.hide : R.string.show);
mHeader.isExpanded() ? 0 : R.drawable.hairline_border_card_background); setBackgroundResource(
mHeader.isExpanded() ? 0 : R.drawable.hairline_border_card_background);
}
} }
} }
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