Skip to content

Commit

Permalink
Merge pull request #13657 from brave/pr13519_remove_stats_and_topsite…
Browse files Browse the repository at this point in the history
…s_from_ntp_1.40.x

Remove top sites from NTP (uplift to 1.40.x)
  • Loading branch information
kjozwiak authored Jun 15, 2022
2 parents cce2452 + e341563 commit 49cb7eb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 49 deletions.
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 @@ -297,43 +298,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 @@ -3083,6 +3083,9 @@ If you don't accept this request, VPN will not reconnect and your internet conne
<message name="IDS_TRIAL" desc="Brave VPN trial text">
Trial
</message>
<message name="IDS_SHOW_TOP_SITES" desc="New tab page settings title">
Show Top sites
</message>
</messages>
</release>
</grit>

0 comments on commit 49cb7eb

Please sign in to comment.