Skip to content

Commit

Permalink
Merge pull request #5969 from brave/Remove_bg_images_dp
Browse files Browse the repository at this point in the history
Remove background images for low end devices
  • Loading branch information
deeppandya authored and mkarolin committed Jul 7, 2020
1 parent 066913f commit 8af37e0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.chromium.chrome.browser.preferences.ChromePreferenceKeys.UI_THEME_SETTING;

import android.os.Bundle;
import android.os.Build;
import android.support.annotation.Nullable;
import androidx.preference.Preference;

Expand All @@ -34,8 +35,9 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root
Profile mProfile = Profile.getLastUsedProfile();
NTPBackgroundImagesBridge mNTPBackgroundImagesBridge = NTPBackgroundImagesBridge.getInstance(mProfile);
if (!NTPBackgroundImagesBridge.enableSponsoredImages()
|| (mNTPBackgroundImagesBridge != null
&& !mNTPBackgroundImagesBridge.isSuperReferral())) {
|| (mNTPBackgroundImagesBridge != null
&& !mNTPBackgroundImagesBridge.isSuperReferral())
|| Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
Preference superReferralPreference = getPreferenceScreen().findPreference(SUPER_REFERRAL);
if (superReferralPreference != null) {
getPreferenceScreen().removePreference(superReferralPreference);
Expand All @@ -44,23 +46,23 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, String root

SharedPreferencesManager sharedPreferencesManager = SharedPreferencesManager.getInstance();
BraveRadioButtonGroupThemePreference radioButtonGroupThemePreference =
(BraveRadioButtonGroupThemePreference) findPreference(PREF_UI_THEME_PREF);
(BraveRadioButtonGroupThemePreference) findPreference(PREF_UI_THEME_PREF);

int defaultThemePref = ThemeType.SYSTEM_DEFAULT;
if (!BuildInfo.isAtLeastQ()) {
defaultThemePref = GlobalNightModeStateProviderHolder.getInstance().isInNightMode()
? ThemeType.DARK
: ThemeType.LIGHT;
? ThemeType.DARK
: ThemeType.LIGHT;
}
radioButtonGroupThemePreference.initialize(
sharedPreferencesManager.readInt(UI_THEME_SETTING, defaultThemePref),
sharedPreferencesManager.readBoolean(UI_THEME_DARKEN_WEBSITES_ENABLED, false));
sharedPreferencesManager.readInt(UI_THEME_SETTING, defaultThemePref),
sharedPreferencesManager.readBoolean(UI_THEME_DARKEN_WEBSITES_ENABLED, false));

radioButtonGroupThemePreference.setOnPreferenceChangeListener((preference, newValue) -> {
if (ChromeFeatureList.isEnabled(
ChromeFeatureList.DARKEN_WEBSITES_CHECKBOX_IN_THEMES_SETTING)) {
ChromeFeatureList.DARKEN_WEBSITES_CHECKBOX_IN_THEMES_SETTING)) {
sharedPreferencesManager.writeBoolean(UI_THEME_DARKEN_WEBSITES_ENABLED,
radioButtonGroupThemePreference.isDarkenWebsitesEnabled());
radioButtonGroupThemePreference.isDarkenWebsitesEnabled());
}
int theme = (int) newValue;
sharedPreferencesManager.writeInt(UI_THEME_SETTING, theme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,14 @@ protected void insertSiteSectionView() {
int insertionPoint = mainLayout.indexOfChild(mBraveStatsView) + 1;
if (!mNTPBackgroundImagesBridge.isSuperReferral()
|| !NTPBackgroundImagesBridge.enableSponsoredImages()
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
mainLayout.addView(mSiteSectionView, insertionPoint);
}

@Override
protected int getMaxTileRows() {
boolean isMoreTabs = false;
ChromeTabbedActivity chromeTabbedActivity = BraveRewardsHelper.getChromeTabbedActivity();
if (chromeTabbedActivity != null) {
TabModel tabModel = chromeTabbedActivity.getCurrentTabModel();
isMoreTabs = tabModel.getCount() >= SponsoredImageUtil.MAX_TABS ? true : false;
}

if (BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE)
&& NTPUtil.shouldEnableNTPFeature(isMoreTabs)) {
&& NTPUtil.shouldEnableNTPFeature()) {
return 1;
} else {
return 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected void onDetachedFromWindow() {

@Override
public void onConfigurationChanged(Configuration newConfig) {
if (sponsoredTab != null && NTPUtil.shouldEnableNTPFeature(sponsoredTab.isMoreTabs())) {
if (sponsoredTab != null && NTPUtil.shouldEnableNTPFeature()) {
NTPImage ntpImage = sponsoredTab.getTabNTPImage(false);
if (ntpImage == null) {
sponsoredTab.setNTPImage(SponsoredImageUtil.getBackgroundImage());
Expand Down Expand Up @@ -200,7 +200,7 @@ private void updateBraveStats() {

if ((BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE)
|| NTPUtil.isReferralEnabled())
&& sponsoredTab != null && NTPUtil.shouldEnableNTPFeature(sponsoredTab.isMoreTabs())) {
&& sponsoredTab != null && NTPUtil.shouldEnableNTPFeature()) {
mAdsBlockedTextView.setTextColor(mNewTabPageLayout.getResources().getColor(android.R.color.white));
mDataSavedTextView.setTextColor(mNewTabPageLayout.getResources().getColor(android.R.color.white));
mEstTimeSavedTextView.setTextColor(mNewTabPageLayout.getResources().getColor(android.R.color.white));
Expand Down Expand Up @@ -269,7 +269,7 @@ private void showNTPImage(NTPImage ntpImage) {
TextView mCreditText = (TextView)mNewTabPageLayout.findViewById(R.id.credit_text);
if (ntpImage instanceof Wallpaper
&& NTPUtil.isReferralEnabled()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setBackgroundImage(ntpImage);
mSuperReferralLogo.setVisibility(View.VISIBLE);
mCreditText.setVisibility(View.GONE);
Expand All @@ -285,7 +285,7 @@ public void onClick(View view) {
}
});
} else if (BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE)
&& sponsoredTab != null && NTPUtil.shouldEnableNTPFeature(sponsoredTab.isMoreTabs())) {
&& sponsoredTab != null && NTPUtil.shouldEnableNTPFeature()) {
setBackgroundImage(ntpImage);
if (ntpImage instanceof BackgroundImage) {
BackgroundImage backgroundImage = (BackgroundImage) ntpImage;
Expand Down Expand Up @@ -358,7 +358,7 @@ private void initilizeSponsoredTab() {
sponsoredTab = TabAttributes.from(mTab).get(String.valueOf((mTabImpl).getId()));
if (mNTPBackgroundImagesBridge.isSuperReferral()
&& NTPBackgroundImagesBridge.enableSponsoredImages()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
mNTPBackgroundImagesBridge.getTopSites();
}

Expand Down Expand Up @@ -403,11 +403,12 @@ protected void onPostExecute(Void result) {
public void onUpdated() {
if (NTPUtil.isReferralEnabled()) {
checkAndShowNTPImage(true);
((BraveNewTabPageLayout)mNewTabPageLayout).removeDefaultTopSites();
if (mNTPBackgroundImagesBridge.isSuperReferral()
&& NTPBackgroundImagesBridge.enableSponsoredImages()
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
((BraveNewTabPageLayout)mNewTabPageLayout).removeDefaultTopSites();
mNTPBackgroundImagesBridge.getTopSites();
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ public class SponsoredTab {
private NTPImage ntpImage;
private int tabIndex;
private boolean mShouldShowBanner;
private boolean isMoreTabs;

public SponsoredTab(NTPBackgroundImagesBridge mNTPBackgroundImagesBridge) {
this.mNTPBackgroundImagesBridge = mNTPBackgroundImagesBridge;
ChromeTabbedActivity chromeTabbedActivity = BraveRewardsHelper.getChromeTabbedActivity();
if (chromeTabbedActivity != null) {
TabModel tabModel = chromeTabbedActivity.getCurrentTabModel();
isMoreTabs = tabModel.getCount() > SponsoredImageUtil.MAX_TABS ? true : false;
}

if (NTPUtil.shouldEnableNTPFeature(isMoreTabs)) {
if (NTPUtil.shouldEnableNTPFeature()) {
ntpImage = NTPUtil.getNTPImage(mNTPBackgroundImagesBridge);
tabIndex = SponsoredImageUtil.getTabIndex();
updateBannerPref();
Expand Down Expand Up @@ -63,8 +56,4 @@ public boolean shouldShowBanner() {
public void updateBannerPref() {
mShouldShowBanner = ContextUtils.getAppSharedPreferences().getBoolean(BackgroundImagesPreferences.PREF_SHOW_NON_DISTRUPTIVE_BANNER, true);
}

public boolean isMoreTabs() {
return isMoreTabs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,8 @@ public static void addToRemovedTopSite(String url) {
sharedPreferencesEditor.apply();
}

public static boolean shouldEnableNTPFeature(boolean isMoreTabs) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M
|| (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !isMoreTabs)) {
public static boolean shouldEnableNTPFeature() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void updateBravePreferences() {
removePreferenceIfPresent(PREF_WELCOME_TOUR);
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
|| (NTPUtil.isReferralEnabled() && NTPBackgroundImagesBridge.enableSponsoredImages())) {
removePreferenceIfPresent(PREF_BACKGROUND_IMAGES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,16 @@
import org.chromium.chrome.browser.ntp_background_images.util.NTPUtil;

public class BraveTileWithTextView extends TileWithTextView {
public BraveTileWithTextView(Context context, AttributeSet attrs) {
public BraveTileWithTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public void setTitle(String title, int titleLines) {

super.setTitle(title, titleLines);

super.setTitle(title, titleLines);
TextView mTitleView = findViewById(R.id.tile_view_title);

boolean isMoreTabs = false;
ChromeTabbedActivity chromeTabbedActivity = BraveRewardsHelper.getChromeTabbedActivity();
if(chromeTabbedActivity != null) {
TabModel tabModel = chromeTabbedActivity.getCurrentTabModel();
isMoreTabs = tabModel.getCount() >= SponsoredImageUtil.MAX_TABS ? true : false;
}

if(BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE)
&& NTPUtil.shouldEnableNTPFeature(isMoreTabs)) {
if (BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE)
&& NTPUtil.shouldEnableNTPFeature()) {
mTitleView.setTextColor(getResources().getColor(android.R.color.white));
}
}
Expand Down

0 comments on commit 8af37e0

Please sign in to comment.