From 87ae1eb8febb61858ee09103b7741338ac039b32 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Wed, 16 Mar 2016 21:20:26 -0400 Subject: [PATCH] Fixed bug where changing theme resulted in default tab icons being incorrectly themed --- .../browser/lightning/view/LightningView.java | 4 +- .../lightning/view/LightningViewTitle.java | 37 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 4122aca..d58a235 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -117,7 +117,7 @@ public class LightningView { mUIController = (UIController) activity; mWebView = new WebView(activity); mIsIncognitoTab = isIncognito; - mTitle = new LightningViewTitle(activity, mUIController.getUseDarkTheme()); + mTitle = new LightningViewTitle(activity); mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity(); @@ -1000,7 +1000,7 @@ public class LightningView { */ @NonNull public Bitmap getFavicon() { - return mTitle.getFavicon(); + return mTitle.getFavicon(mUIController.getUseDarkTheme()); } /** diff --git a/app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java b/app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java index 3d7004c..eafce74 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java @@ -16,16 +16,15 @@ import acr.browser.lightning.utils.Utils; */ class LightningViewTitle { - @Nullable private static Bitmap DEFAULT_ICON; + @Nullable private static Bitmap DEFAULT_DARK_ICON; + @Nullable private static Bitmap DEFAULT_LIGHT_ICON; - @NonNull private final Bitmap mDefault; - @NonNull private Bitmap mFavicon; + @Nullable private Bitmap mFavicon = null; @NonNull private String mTitle; + @NonNull Context mContext; - public LightningViewTitle(@NonNull Context context, boolean darkTheme) { - DEFAULT_ICON = getDefault(context, darkTheme); - mDefault = DEFAULT_ICON; - mFavicon = mDefault; + public LightningViewTitle(@NonNull Context context) { + mContext = context; mTitle = context.getString(R.string.action_new_tab); } @@ -37,25 +36,32 @@ class LightningViewTitle { */ public void setFavicon(@Nullable Bitmap favicon) { if (favicon == null) { - mFavicon = mDefault; + mFavicon = null; } else { mFavicon = Utils.padFavicon(favicon); } } /** - * Helper method to initialize the DEFAULT_ICON variable. + * Helper method to initialize the DEFAULT_ICON variables * * @param context the context needed to initialize the Bitmap. * @param darkTheme whether the icon should be themed dark or not. * @return a not null icon. */ @NonNull - private static Bitmap getDefault(@NonNull Context context, boolean darkTheme) { - if (DEFAULT_ICON == null) { - DEFAULT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme); + private static Bitmap getDefaultIcon(@NonNull Context context, boolean darkTheme) { + if (darkTheme) { + if (DEFAULT_DARK_ICON == null) { + DEFAULT_DARK_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, true); + } + return DEFAULT_DARK_ICON; + } else { + if (DEFAULT_LIGHT_ICON == null) { + DEFAULT_LIGHT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, false); + } + return DEFAULT_LIGHT_ICON; } - return DEFAULT_ICON; } /** @@ -90,7 +96,10 @@ class LightningViewTitle { * @return the favicon or a default if that is null. */ @NonNull - public Bitmap getFavicon() { + public Bitmap getFavicon(boolean darkTheme) { + if (mFavicon == null) { + return getDefaultIcon(mContext, darkTheme); + } return mFavicon; }