diff --git a/android/java/org/chromium/chrome/browser/night_mode/settings/BraveThemePreferences.java b/android/java/org/chromium/chrome/browser/night_mode/settings/BraveThemePreferences.java index 6e25573e9550..eb97ed4855e9 100644 --- a/android/java/org/chromium/chrome/browser/night_mode/settings/BraveThemePreferences.java +++ b/android/java/org/chromium/chrome/browser/night_mode/settings/BraveThemePreferences.java @@ -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; @@ -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); @@ -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); diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java index 20f506689bdc..18f3092a6cb3 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java @@ -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; diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java index 0c2c54cf0f9c..39f3c521b997 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageView.java @@ -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()); @@ -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)); @@ -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); @@ -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; @@ -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(); } @@ -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(); + } } } }; diff --git a/android/java/org/chromium/chrome/browser/ntp_background_images/model/SponsoredTab.java b/android/java/org/chromium/chrome/browser/ntp_background_images/model/SponsoredTab.java index df3c5072d661..1271a4524803 100644 --- a/android/java/org/chromium/chrome/browser/ntp_background_images/model/SponsoredTab.java +++ b/android/java/org/chromium/chrome/browser/ntp_background_images/model/SponsoredTab.java @@ -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(); @@ -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; - } } diff --git a/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java b/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java index 6ef4dfd08428..663dce1c321b 100644 --- a/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java +++ b/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java @@ -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; diff --git a/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java b/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java index 9486f9eb78eb..1a20a73f2a66 100644 --- a/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java +++ b/android/java/org/chromium/chrome/browser/settings/BraveMainPreferencesBase.java @@ -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); } diff --git a/android/java/org/chromium/chrome/browser/widget/tile/BraveTileWithTextView.java b/android/java/org/chromium/chrome/browser/widget/tile/BraveTileWithTextView.java index 9ffbe27b7aca..dcb92311ab18 100644 --- a/android/java/org/chromium/chrome/browser/widget/tile/BraveTileWithTextView.java +++ b/android/java/org/chromium/chrome/browser/widget/tile/BraveTileWithTextView.java @@ -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)); } }