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

Add an option to hide brave stats #16205

Merged
merged 1 commit into from
Dec 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
2 changes: 1 addition & 1 deletion android/brave_java_resources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -393,6 +400,7 @@ private void setNtpRecyclerView(LinearLayoutManager linearLayoutManager) {
} else {
mNtpAdapter.setRecyclerViewHeight(mRecyclerView.getHeight());
mNtpAdapter.setTopSitesEnabled(mIsTopSitesEnabled);
mNtpAdapter.setBraveStatsEnabled(mIsBraveStatsEnabled);
mNtpAdapter.setDisplayNews(mIsDisplayNews);
}

Expand Down Expand Up @@ -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);
}
};
}
Expand Down
28 changes: 24 additions & 4 deletions android/java/org/chromium/chrome/browser/ntp/BraveNtpAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -74,6 +76,7 @@ public class BraveNtpAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private boolean mIsNewContent;
private boolean mIsNewContentLoading;
private boolean mIsTopSitesEnabled;
private boolean mIsBraveStatsEnabled;
private int mRecyclerViewHeight;
private int mStatsHeight;
private int mTopSitesHeight;
Expand All @@ -97,8 +100,8 @@ public BraveNtpAdapter(Activity activity, OnBraveNtpListener onBraveNtpListener,
BraveNewsController braveNewsController, View mvTilesContainerLayout, NTPImage ntpImage,
SponsoredTab sponsoredTab, Wallpaper wallpaper, Bitmap sponsoredLogo,
NTPBackgroundImagesBridge nTPBackgroundImagesBridge, boolean isNewsLoading,
int recyclerViewHeight, boolean isTopSitesEnabled, boolean isDisplayNews,
boolean isDisplayNewsOptin) {
int recyclerViewHeight, boolean isTopSitesEnabled, boolean isBraveStatsEnabled,
boolean isDisplayNews, boolean isDisplayNewsOptin) {
mActivity = activity;
mOnBraveNtpListener = onBraveNtpListener;
mGlide = glide;
Expand All @@ -113,6 +116,7 @@ public BraveNtpAdapter(Activity activity, OnBraveNtpListener onBraveNtpListener,
mIsNewsLoading = isNewsLoading;
mRecyclerViewHeight = recyclerViewHeight;
mIsTopSitesEnabled = isTopSitesEnabled;
mIsBraveStatsEnabled = isBraveStatsEnabled;
mIsDisplayNews = isDisplayNews;
mIsDisplayNewsOptin = isDisplayNewsOptin;
}
Expand All @@ -122,7 +126,10 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
if (holder instanceof StatsViewHolder) {
StatsViewHolder statsViewHolder = (StatsViewHolder) holder;

statsViewHolder.titleLayout.setVisibility(View.GONE);
statsViewHolder.hideStatsImg.setOnClickListener(view -> {
SharedPreferencesManager.getInstance().writeBoolean(
BackgroundImagesPreferences.PREF_SHOW_BRAVE_STATS, false);
});
List<Pair<String, String>> statsPairs = BraveStatsUtil.getStatsPairs();

statsViewHolder.adsBlockedCountTv.setText(statsPairs.get(0).first);
Expand Down Expand Up @@ -402,7 +409,7 @@ public int getStatsCount() {

// Will be used in privacy hub feature
private boolean isStatsEnabled() {
return true;
return mIsBraveStatsEnabled;
}

public int getTopSitesCount() {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions android/java/res/drawable/ic_more_horiz.xml

This file was deleted.

5 changes: 5 additions & 0 deletions android/java/res/drawable/ic_visibility_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
</vector>
2 changes: 1 addition & 1 deletion android/java/res/layout/brave_stats_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

</LinearLayout>

Expand Down
52 changes: 35 additions & 17 deletions android/java/res/xml/background_images_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,40 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >

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

<org.chromium.components.browser_ui.settings.ChromeSwitchPreference
android:key="show_sponsored_images"
android:title="@string/show_sponsored_images"
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" />
<PreferenceCategory
android:key="background_images"
android:title="@string/background_images">

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

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

</PreferenceCategory>

<PreferenceCategory
android:key="widgets"
android:title="@string/widgets">

<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" />

<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" />

</PreferenceCategory>

</PreferenceScreen>
15 changes: 12 additions & 3 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,24 @@ Are you sure you want to do this?
<message name="IDS_PREFS_NEW_TAB_PAGE" desc="Title of New Tab Page settings.">
New Tab Page
</message>
<message name="IDS_BACKGROUND_IMAGES" desc= "Category title of background images option.">
Background Images
</message>
<message name="IDS_SHOW_BACKGROUND_IMAGES" desc= "Title of show background images option.">
Show Background Images
</message>
<message name="IDS_SHOW_SPONSORED_IMAGES" desc ="Title of show sponsored images option.">
Show Sponsored Images
</message>
<message name="IDS_WIDGETS" desc ="Categary of Widget option.">
Widgets
</message>
<message name="IDS_SHOW_TOP_SITES" desc="New tab page settings title">
Show Top Sites
</message>
<message name="IDS_SHOW_BRAVE_STATS" desc="New tab page settings title">
Show Brave Stats
</message>
<message name="IDS_PHOTO_BY" desc="Text for image credit for background images on NTP">
Photo by <ph name="PHOTO_BY">%1$s</ph>
</message>
Expand Down Expand Up @@ -2922,9 +2934,6 @@ If you don't accept this request, VPN will not reconnect and your internet conne
<message name="IDS_SETTINGS_SOLANA_TITLE" desc="Title for Solana section in site settings" translateable="false">
Solana
</message>
<message name="IDS_SHOW_TOP_SITES" desc="New tab page settings title">
Show Top Sites
</message>
<message name="IDS_CONNECTED_TO_HOST" desc="Brave Vpn notification statistics text">
Connected to <ph name="VALUE">%1$s</ph>
</message>
Expand Down