package acr.browser.lightning.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import acr.browser.lightning.R;
import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils;

/**
 * {@link LightningViewTitle} acts as a container class
 * for the favicon and page title, the information used
 * by the tab adapters to show the tabs to the user.
 */
class LightningViewTitle {

    private static Bitmap DEFAULT_ICON = null;

    @NonNull private Bitmap mFavicon;
    @NonNull private String mTitle;

    public LightningViewTitle(@NonNull Context context, boolean darkTheme) {
        if (DEFAULT_ICON == null) {
            DEFAULT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
        }
        mFavicon = DEFAULT_ICON;
        mTitle = context.getString(R.string.action_new_tab);
    }

    /**
     * Set the current favicon to a new Bitmap.
     * May be null, if null, the default will be used.
     *
     * @param favicon the potentially null favicon to set.
     */
    public void setFavicon(@Nullable Bitmap favicon) {
        if (favicon == null) {
            mFavicon = DEFAULT_ICON;
        } else {
            mFavicon = Utils.padFavicon(favicon);
        }
    }

    /**
     * Set the current title to a new title.
     * Must not be null.
     *
     * @param title the non-null title to set.
     */
    public void setTitle(@Nullable String title) {
        if (title == null) {
            mTitle = "";
        } else {
            mTitle = title;
        }
    }

    /**
     * Gets the current title, which is not null.
     * Can be an empty string.
     *
     * @return the non-null title.
     */
    @NonNull
    public String getTitle() {
        return mTitle;
    }

    /**
     * Gets the favicon of the page, which is not null.
     * Either the favicon, or a default icon.
     *
     * @return the favicon or a default if that is null.
     */
    @NonNull
    public Bitmap getFavicon() {
        return mFavicon;
    }

}

@@ -509,16 +509,26 @@
  %7B%0A%0A    
+@Nullable 
 private 
@@ -557,17 +557,54 @@
 ICON
- = null;%0A
+;%0A%0A    @NonNull private final Bitmap mDefault;
 %0A   
@@ -760,20 +760,16 @@
         
-if (
 DEFAULT_
@@ -778,125 +778,73 @@
 ON =
-= null) %7B%0A            DEFAULT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);%0A        %7D
+ getDefault(context, darkTheme);%0A        mDefault = DEFAULT_ICON;
 %0A   
@@ -855,36 +855,32 @@
  mFavicon = 
-DEFAULT_ICON
+mDefault
 ;%0A        mT
@@ -1231,28 +1231,24 @@
 vicon = 
-DEFAULT_ICON
+mDefault
 ;%0A      
@@ -1317,32 +1317,566 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Helper method to initialize the DEFAULT_ICON variable.%0A     *%0A     * @param context   the context needed to initialize the Bitmap.%0A     * @param darkTheme whether the icon should be themed dark or not.%0A     * @return a not null icon.%0A     */%0A    @NonNull%0A    private static Bitmap getDefault(@NonNull Context context, boolean darkTheme) %7B%0A        if (DEFAULT_ICON == null) %7B%0A            DEFAULT_ICON = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);%0A        %7D%0A        return DEFAULT_ICON;%0A    %7D%0A%0A
     /**%0A     * S

Fix null issues with bitmap