Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove top sites from NTP #13519

Merged
merged 3 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import org.chromium.chrome.browser.preferences.BravePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.BackgroundImagesPreferences;
import org.chromium.chrome.browser.settings.BraveNewsPreferences;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.chrome.browser.suggestions.tile.TileGroup;
Expand Down Expand Up @@ -298,43 +299,47 @@ protected void onFinishInflate() {
}

private void showFallBackNTPLayout() {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
if (mBraveStatsViewFallBackLayout != null
&& mBraveStatsViewFallBackLayout.getParent() != null) {
((ViewGroup) mBraveStatsViewFallBackLayout.getParent())
.removeView(mBraveStatsViewFallBackLayout);
}
LayoutInflater inflater =
(LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mBraveStatsViewFallBackLayout = inflater.inflate(R.layout.brave_stats_layout, null);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
int margin = dpToPx(mActivity, 16);
layoutParams.setMargins(margin, margin, margin, margin);
mBraveStatsViewFallBackLayout.setLayoutParams(layoutParams);
mBraveStatsViewFallBackLayout.requestLayout();

mBraveStatsViewFallBackLayout.findViewById(R.id.brave_stats_title_layout)
.setVisibility(View.GONE);
mBraveStatsViewFallBackLayout.setOnClickListener(new View.OnClickListener() {
@Override
@SuppressLint("SourceLockedOrientationActivity")
public void onClick(View v) {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
checkForBraveStats();
}
});
BraveStatsUtil.updateBraveStatsLayout(mBraveStatsViewFallBackLayout);
mainLayout.addView(mBraveStatsViewFallBackLayout, 0);
int insertionPoint = mainLayout.indexOfChild(findViewById(R.id.ntp_middle_spacer)) + 1;
if (mSiteSectionView.getParent() != null) {
((ViewGroup) mSiteSectionView.getParent()).removeView(mSiteSectionView);
}
mSiteSectionView.setBackgroundResource(R.drawable.rounded_dark_bg_alpha);
mSiteSectionView.setLayoutParams(layoutParams);
mSiteSectionView.requestLayout();
mainLayout.addView(mSiteSectionView, insertionPoint);
LayoutInflater inflater =
(LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mBraveStatsViewFallBackLayout = inflater.inflate(R.layout.brave_stats_layout, null);
int margin = dpToPx(mActivity, 16);
layoutParams.setMargins(margin, margin, margin, margin);
mBraveStatsViewFallBackLayout.setLayoutParams(layoutParams);
mBraveStatsViewFallBackLayout.requestLayout();

mBraveStatsViewFallBackLayout.findViewById(R.id.brave_stats_title_layout)
.setVisibility(View.GONE);
mBraveStatsViewFallBackLayout.setOnClickListener(new View.OnClickListener() {
@Override
@SuppressLint("SourceLockedOrientationActivity")
public void onClick(View v) {
mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
checkForBraveStats();
}
});
BraveStatsUtil.updateBraveStatsLayout(mBraveStatsViewFallBackLayout);
mainLayout.addView(mBraveStatsViewFallBackLayout, 0);

if (ContextUtils.getAppSharedPreferences().getBoolean(
BackgroundImagesPreferences.PREF_SHOW_TOP_SITES, true)) {
int insertionPoint =
mainLayout.indexOfChild(findViewById(R.id.ntp_middle_spacer)) + 1;
if (mSiteSectionView.getParent() != null) {
((ViewGroup) mSiteSectionView.getParent()).removeView(mSiteSectionView);
}
mSiteSectionView.setBackgroundResource(R.drawable.rounded_dark_bg_alpha);
mSiteSectionView.setLayoutParams(layoutParams);
mSiteSectionView.requestLayout();
mainLayout.addView(mSiteSectionView, insertionPoint);
}
}

protected void updateTileGridPlaceholderVisibility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public class BackgroundImagesPreferences
// deprecated preferences from browser-android-tabs
public static final String PREF_SHOW_BACKGROUND_IMAGES = "show_background_images";
public static final String PREF_SHOW_SPONSORED_IMAGES = "show_sponsored_images";
public static final String PREF_SHOW_TOP_SITES = "show_top_sites";
public static final String PREF_SHOW_NON_DISRUPTIVE_BANNER = "show_non_disruptive_banner";
public static final String PREF_SHOW_BRE_BANNER = "show_bre_banner";

private ChromeSwitchPreference showBackgroundImagesPref;
private ChromeSwitchPreference showSponsoredImagesPref;

private SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
private SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
private ChromeSwitchPreference mShowBackgroundImagesPref;
private ChromeSwitchPreference mShowSponsoredImagesPref;
private ChromeSwitchPreference mShowBraveStatsPref;
private ChromeSwitchPreference mShowTopSitesPref;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -58,24 +58,41 @@ private void removePreferenceIfPresent(String key) {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
showBackgroundImagesPref = (ChromeSwitchPreference) findPreference(PREF_SHOW_BACKGROUND_IMAGES);
if (showBackgroundImagesPref != null) {
showBackgroundImagesPref.setEnabled(true);
showBackgroundImagesPref.setChecked(UserPrefs.get(Profile.getLastUsedRegularProfile()).getBoolean(BravePref.NEW_TAB_PAGE_SHOW_BACKGROUND_IMAGE));
showBackgroundImagesPref.setOnPreferenceChangeListener(this);
mShowBackgroundImagesPref =
(ChromeSwitchPreference) findPreference(PREF_SHOW_BACKGROUND_IMAGES);
if (mShowBackgroundImagesPref != null) {
mShowBackgroundImagesPref.setEnabled(true);
mShowBackgroundImagesPref.setChecked(
UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(BravePref.NEW_TAB_PAGE_SHOW_BACKGROUND_IMAGE));
mShowBackgroundImagesPref.setOnPreferenceChangeListener(this);
}
mShowSponsoredImagesPref =
(ChromeSwitchPreference) findPreference(PREF_SHOW_SPONSORED_IMAGES);
if (mShowSponsoredImagesPref != null) {
mShowSponsoredImagesPref.setEnabled(
UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(BravePref.NEW_TAB_PAGE_SHOW_BACKGROUND_IMAGE));
mShowSponsoredImagesPref.setChecked(
UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(
BravePref.NEW_TAB_PAGE_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE));
mShowSponsoredImagesPref.setOnPreferenceChangeListener(this);
}
showSponsoredImagesPref = (ChromeSwitchPreference) findPreference(PREF_SHOW_SPONSORED_IMAGES);
if (showSponsoredImagesPref != null) {
showSponsoredImagesPref.setEnabled(UserPrefs.get(Profile.getLastUsedRegularProfile()).getBoolean(BravePref.NEW_TAB_PAGE_SHOW_BACKGROUND_IMAGE));
showSponsoredImagesPref.setChecked(UserPrefs.get(Profile.getLastUsedRegularProfile()).getBoolean(BravePref.NEW_TAB_PAGE_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE));
showSponsoredImagesPref.setOnPreferenceChangeListener(this);
mShowTopSitesPref = (ChromeSwitchPreference) findPreference(PREF_SHOW_TOP_SITES);
if (mShowTopSitesPref != null) {
mShowTopSitesPref.setEnabled(true);
mShowTopSitesPref.setChecked(
ContextUtils.getAppSharedPreferences().getBoolean(PREF_SHOW_TOP_SITES, true));
mShowTopSitesPref.setOnPreferenceChangeListener(this);
}
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (PREF_SHOW_BACKGROUND_IMAGES.equals(preference.getKey()) && showSponsoredImagesPref != null) {
showSponsoredImagesPref.setEnabled((boolean)newValue);
if (PREF_SHOW_BACKGROUND_IMAGES.equals(preference.getKey())
&& mShowSponsoredImagesPref != null) {
mShowSponsoredImagesPref.setEnabled((boolean) newValue);
}
setOnPreferenceValue(preference.getKey(), (boolean)newValue);
BraveRelaunchUtils.askForRelaunch(getActivity());
Expand Down
6 changes: 6 additions & 0 deletions android/java/res/xml/background_images_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
android:summaryOn="@string/text_on"
android:summaryOff="@string/text_off" />

<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="show_top_sites"
android:title="@string/show_top_sites"
android:summaryOn="@string/text_on"
android:summaryOff="@string/text_off" />

</PreferenceScreen>
3 changes: 3 additions & 0 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -2977,6 +2977,9 @@ If you don't accept this request, VPN will not reconnect and your internet conne
<message name="IDS_SETTINGS_ETHEREUM_TITLE" desc="Title for Ethereum section in site settings" translateable="false">
Ethereum
</message>
<message name="IDS_SHOW_TOP_SITES" desc="New tab page settings title">
Show Top sites
</message>
</messages>
</release>
</grit>