From cecc9f57ffcf631937311abfce43e76f697a7b8a Mon Sep 17 00:00:00 2001 From: deeppandya Date: Fri, 2 Dec 2022 12:55:51 -0500 Subject: [PATCH] Add an option to hide brave stats --- android/brave_java_resources.gni | 2 +- .../browser/ntp/BraveNewTabPageLayout.java | 13 ++++- .../chrome/browser/ntp/BraveNtpAdapter.java | 28 ++++++++-- .../settings/BackgroundImagesPreferences.java | 8 +++ android/java/res/drawable/ic_more_horiz.xml | 5 -- .../java/res/drawable/ic_visibility_off.xml | 5 ++ .../java/res/layout/brave_stats_layout.xml | 2 +- .../res/xml/background_images_preferences.xml | 52 +++++++++++++------ .../android/strings/android_brave_strings.grd | 15 ++++-- 9 files changed, 98 insertions(+), 32 deletions(-) delete mode 100644 android/java/res/drawable/ic_more_horiz.xml create mode 100644 android/java/res/drawable/ic_visibility_off.xml diff --git a/android/brave_java_resources.gni b/android/brave_java_resources.gni index 897c60387f5c..1299adf2ed9d 100644 --- a/android/brave_java_resources.gni +++ b/android/brave_java_resources.gni @@ -564,7 +564,6 @@ brave_java_resources = [ "java/res/drawable/ic_mask.xml", "java/res/drawable/ic_menu.xml", "java/res/drawable/ic_money_bag_coins.xml", - "java/res/drawable/ic_more_horiz.xml", "java/res/drawable/ic_new_tab_page.xml", "java/res/drawable/ic_news.xml", "java/res/drawable/ic_news_settings.xml", @@ -639,6 +638,7 @@ brave_java_resources = [ "java/res/drawable/ic_uphold.xml", "java/res/drawable/ic_verify_wallet_arrow.xml", "java/res/drawable/ic_vimeo.xml", + "java/res/drawable/ic_visibility_off.xml", "java/res/drawable/ic_vpn.xml", "java/res/drawable/ic_vpn_promo.xml", "java/res/drawable/ic_vpn_shield.xml", diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java index 1319295d74c6..e4e6792b42a8 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java @@ -183,6 +183,7 @@ public class BraveNewTabPageLayout private SharedPreferencesManager.Observer mPreferenceObserver; private boolean mComesFromNewTab; private boolean mIsTopSitesEnabled; + private boolean mIsBraveStatsEnabled; private boolean mIsDisplayNews; private boolean mIsDisplayNewsOptin; @@ -371,15 +372,21 @@ private boolean shouldDisplayTopSites() { BackgroundImagesPreferences.PREF_SHOW_TOP_SITES, true); } + private boolean shouldDisplayBraveStats() { + return ContextUtils.getAppSharedPreferences().getBoolean( + BackgroundImagesPreferences.PREF_SHOW_BRAVE_STATS, true); + } + private void setNtpRecyclerView(LinearLayoutManager linearLayoutManager) { mIsTopSitesEnabled = shouldDisplayTopSites(); + mIsBraveStatsEnabled = shouldDisplayBraveStats(); if (mNtpAdapter == null) { mNtpAdapter = new BraveNtpAdapter(mActivity, this, Glide.with(mActivity), mNewsItemsFeedCard, mBraveNewsController, mMvTilesContainerLayout, mNtpImageGlobal, mSponsoredTab, mWallpaper, mSponsoredLogo, mNTPBackgroundImagesBridge, false, mRecyclerView.getHeight(), - mIsTopSitesEnabled, mIsDisplayNews, mIsDisplayNewsOptin); + mIsTopSitesEnabled, mIsBraveStatsEnabled, mIsDisplayNews, mIsDisplayNewsOptin); mRecyclerView.setAdapter(mNtpAdapter); @@ -393,6 +400,7 @@ private void setNtpRecyclerView(LinearLayoutManager linearLayoutManager) { } else { mNtpAdapter.setRecyclerViewHeight(mRecyclerView.getHeight()); mNtpAdapter.setTopSitesEnabled(mIsTopSitesEnabled); + mNtpAdapter.setBraveStatsEnabled(mIsBraveStatsEnabled); mNtpAdapter.setDisplayNews(mIsDisplayNews); } @@ -767,6 +775,9 @@ private void initPreferenceObserver() { } else if (TextUtils.equals(key, BackgroundImagesPreferences.PREF_SHOW_TOP_SITES)) { mIsTopSitesEnabled = shouldDisplayTopSites(); mNtpAdapter.setTopSitesEnabled(mIsTopSitesEnabled); + } else if (TextUtils.equals(key, BackgroundImagesPreferences.PREF_SHOW_BRAVE_STATS)) { + mIsBraveStatsEnabled = shouldDisplayBraveStats(); + mNtpAdapter.setBraveStatsEnabled(mIsBraveStatsEnabled); } }; } diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNtpAdapter.java b/android/java/org/chromium/chrome/browser/ntp/BraveNtpAdapter.java index 2ec75198f5b3..e9173b80c620 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNtpAdapter.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNtpAdapter.java @@ -48,7 +48,9 @@ import org.chromium.chrome.browser.ntp_background_images.model.Wallpaper; import org.chromium.chrome.browser.ntp_background_images.util.NTPUtil; import org.chromium.chrome.browser.preferences.BravePref; +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.util.BraveConstants; import org.chromium.chrome.browser.util.TabUtils; import org.chromium.components.user_prefs.UserPrefs; @@ -74,6 +76,7 @@ public class BraveNtpAdapter extends RecyclerView.Adapter { + SharedPreferencesManager.getInstance().writeBoolean( + BackgroundImagesPreferences.PREF_SHOW_BRAVE_STATS, false); + }); List> statsPairs = BraveStatsUtil.getStatsPairs(); statsViewHolder.adsBlockedCountTv.setText(statsPairs.get(0).first); @@ -402,7 +409,7 @@ public int getStatsCount() { // Will be used in privacy hub feature private boolean isStatsEnabled() { - return true; + return mIsBraveStatsEnabled; } public int getTopSitesCount() { @@ -422,6 +429,17 @@ public void setTopSitesEnabled(boolean isTopSitesEnabled) { } } + public void setBraveStatsEnabled(boolean isBraveStatsEnabled) { + if (mIsBraveStatsEnabled != isBraveStatsEnabled) { + mIsBraveStatsEnabled = isBraveStatsEnabled; + if (mIsBraveStatsEnabled) { + notifyItemInserted(getStatsCount()); + } else { + notifyItemRemoved(getStatsCount()); + } + } + } + public void setDisplayNews(boolean isDisplayNews) { if (mIsDisplayNews != isDisplayNews) { mIsDisplayNews = isDisplayNews; @@ -517,6 +535,7 @@ public void setRecyclerViewHeight(int recyclerViewHeight) { public static class StatsViewHolder extends RecyclerView.ViewHolder { LinearLayout ntpStatsLayout; LinearLayout titleLayout; + ImageView hideStatsImg; TextView adsBlockedCountTv; TextView adsBlockedCountTextTv; TextView dataSavedValueTv; @@ -528,6 +547,7 @@ public static class StatsViewHolder extends RecyclerView.ViewHolder { super(itemView); this.ntpStatsLayout = (LinearLayout) itemView.findViewById(R.id.ntp_stats_layout); this.titleLayout = (LinearLayout) itemView.findViewById(R.id.brave_stats_title_layout); + this.hideStatsImg = (ImageView) itemView.findViewById(R.id.widget_more_option); this.adsBlockedCountTv = (TextView) itemView.findViewById(R.id.brave_stats_text_ads_count); this.adsBlockedCountTextTv = diff --git a/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java b/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java index 790bdf0ec022..7ba392e71da1 100644 --- a/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java +++ b/android/java/org/chromium/chrome/browser/settings/BackgroundImagesPreferences.java @@ -32,6 +32,7 @@ public class BackgroundImagesPreferences 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_BRAVE_STATS = "show_brave_stats"; public static final String PREF_SHOW_NON_DISRUPTIVE_BANNER = "show_non_disruptive_banner"; public static final String PREF_SHOW_BRE_BANNER = "show_bre_banner"; @@ -86,6 +87,13 @@ public void onActivityCreated(Bundle savedInstanceState) { ContextUtils.getAppSharedPreferences().getBoolean(PREF_SHOW_TOP_SITES, true)); mShowTopSitesPref.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); + } } @Override diff --git a/android/java/res/drawable/ic_more_horiz.xml b/android/java/res/drawable/ic_more_horiz.xml deleted file mode 100644 index bc4c55abbda4..000000000000 --- a/android/java/res/drawable/ic_more_horiz.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/android/java/res/drawable/ic_visibility_off.xml b/android/java/res/drawable/ic_visibility_off.xml new file mode 100644 index 000000000000..32ab2aed697b --- /dev/null +++ b/android/java/res/drawable/ic_visibility_off.xml @@ -0,0 +1,5 @@ + + + diff --git a/android/java/res/layout/brave_stats_layout.xml b/android/java/res/layout/brave_stats_layout.xml index bbd65ed11306..557c487f15db 100644 --- a/android/java/res/layout/brave_stats_layout.xml +++ b/android/java/res/layout/brave_stats_layout.xml @@ -41,7 +41,7 @@ android:layout_width="24dp" android:layout_height="24dp" android:contentDescription="@null" - app:srcCompat="@drawable/ic_more_horiz"/> + app:srcCompat="@drawable/ic_visibility_off"/> diff --git a/android/java/res/xml/background_images_preferences.xml b/android/java/res/xml/background_images_preferences.xml index 3f0eabce5d4c..2c2a20c2b416 100644 --- a/android/java/res/xml/background_images_preferences.xml +++ b/android/java/res/xml/background_images_preferences.xml @@ -7,22 +7,40 @@ - - - - - + + + + + + + + + + + + + + + diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index 1de998654e6d..9033151be621 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -1074,12 +1074,24 @@ Are you sure you want to do this? New Tab Page + + Background Images + Show Background Images Show Sponsored Images + + Widgets + + + Show Top Sites + + + Show Brave Stats + Photo by %1$s @@ -2922,9 +2934,6 @@ If you don't accept this request, VPN will not reconnect and your internet conne Solana - - Show Top Sites - Connected to %1$s