Remove brave stats and top sites from NTP

This commit is contained in:
deep
2022-06-02 11:13:40 -04:00
parent 8bda75a4d6
commit 08a4e56947
4 changed files with 98 additions and 51 deletions
@@ -120,6 +120,7 @@ import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
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;
@@ -298,43 +299,49 @@ public class BraveNewTabPageLayout extends NewTabPageLayout implements Connectio
}
private void showFallBackNTPLayout() {
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();
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
if (ContextUtils.getAppSharedPreferences().getBoolean(
BackgroundImagesPreferences.PREF_SHOW_BRAVE_STATS, true)) {
if (mBraveStatsViewFallBackLayout != null
&& mBraveStatsViewFallBackLayout.getParent() != null) {
((ViewGroup) mBraveStatsViewFallBackLayout.getParent())
.removeView(mBraveStatsViewFallBackLayout);
}
});
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);
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);
}
mSiteSectionView.setBackgroundResource(R.drawable.rounded_dark_bg_alpha);
mSiteSectionView.setLayoutParams(layoutParams);
mSiteSectionView.requestLayout();
mainLayout.addView(mSiteSectionView, insertionPoint);
}
protected void updateTileGridPlaceholderVisibility() {
@@ -31,14 +31,15 @@ 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_BRAVE_STATS = "show_brave_stats";
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) {
@@ -58,24 +59,48 @@ public class BackgroundImagesPreferences
@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);
}
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);
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);
}
mShowBraveStatsPref = (ChromeSwitchPreference) findPreference(PREF_SHOW_BRAVE_STATS);
if (mShowBraveStatsPref != null) {
mShowBraveStatsPref.setEnabled(true);
mShowBraveStatsPref.setChecked(
ContextUtils.getAppSharedPreferences().getBoolean(PREF_SHOW_BRAVE_STATS, true));
mShowBraveStatsPref.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());
@@ -19,4 +19,16 @@
android:summaryOn="@string/text_on"
android:summaryOff="@string/text_off" />
<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="show_brave_stats"
android:title="@string/show_brave_stats"
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>