Browse Source

Fixed bug where changing theme resulted in default tab icons being incorrectly themed

master
Anthony Restaino 9 years ago
parent
commit
87ae1eb8fe
  1. 4
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  2. 37
      app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java

4
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -117,7 +117,7 @@ public class LightningView { @@ -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 { @@ -1000,7 +1000,7 @@ public class LightningView {
*/
@NonNull
public Bitmap getFavicon() {
return mTitle.getFavicon();
return mTitle.getFavicon(mUIController.getUseDarkTheme());
}
/**

37
app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java

@ -16,16 +16,15 @@ import acr.browser.lightning.utils.Utils; @@ -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 { @@ -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 { @@ -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;
}

Loading…
Cancel
Save