package com.ikea.kompis.campaign;

import android.app.ActionBar;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.text.Spannable.Factory;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ikea.kompis.ShoppingCartActivity;
import com.ikea.kompis.fragments.SecondLevelContentFragment;
import com.ikea.kompis.util.UiUtil;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.campaign.model.BodyText;
import com.ikea.shared.campaign.model.BodyTextList;
import com.ikea.shared.campaign.model.Campaign;
import com.ikea.shared.campaign.model.Link;
import com.ikea.shared.campaign.model.LinkList;
import com.ikea.shared.campaign.model.Paragraph;
import com.ikea.shared.campaign.model.ParagraphList;
import com.ikea.shared.util.L;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;

public class CampaignViewFragment extends SecondLevelContentFragment
{
  private static final String CAMPAIGN_DATA = "CAMPAIGN_DATA";
  private static final int LINK_UNIQUE_ID = (int)(System.currentTimeMillis() % 2147483647L);
  private TextView details;
  private Campaign mCampaign = null;
  private String mImageUrl;
  private boolean mLaunchedFromTray = false;
  private LinearLayout mLinkLayout = null;
  private String[] mLinkTitle = null;
  private String[] mLinkUrl = null;
  private String mMainTitle = "";
  private final View.OnClickListener mOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      if (paramAnonymousView.getId() >= CampaignViewFragment.LINK_UNIQUE_ID)
        CampaignViewFragment.this.openLink(paramAnonymousView.getId() - CampaignViewFragment.LINK_UNIQUE_ID);
    }
  };
  private String mTitle = "";
  private String mdetails = "";

  private String getCampaignParagraph()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    Object localObject = "";
    int i = 0;
    try
    {
      int j = this.mCampaign.getBodyTextList().getBodyText().size();
      while (i < j)
      {
        int k = 0;
        int m = ((BodyText)this.mCampaign.getBodyTextList().getBodyText().get(i)).getParagraphList().getParagraph().size();
        while (k < m)
        {
          String str1 = ((Paragraph)((BodyText)this.mCampaign.getBodyTextList().getBodyText().get(i)).getParagraphList().getParagraph().get(k)).getParagraphText();
          localStringBuffer.append("<p>" + str1 + "</p>");
          k++;
        }
        localObject = localStringBuffer.toString();
        localObject = ((String)localObject).replace("{0}", "");
        BodyText localBodyText = (BodyText)this.mCampaign.getBodyTextList().getBodyText().get(i);
        if ((localBodyText != null) && (localBodyText.getLinkList() != null) && (localBodyText.getLinkList().getLink() != null) && (!localBodyText.getLinkList().getLink().isEmpty()))
        {
          List localList = localBodyText.getLinkList().getLink();
          int n = 1;
          Iterator localIterator = localList.iterator();
          while (localIterator.hasNext())
          {
            Link localLink = (Link)localIterator.next();
            if ((((String)localObject).contains("{" + n + "}")) && (localLink.getLinkName() != null) && (localLink.getLinkUrl() != null))
            {
              String str2 = ((String)localObject).replace("{" + n + "}", "<a  href=\"" + localLink.getLinkUrl() + "\" style=\"text-decoration: none" + "\">" + localLink.getLinkName() + "</a>");
              localObject = str2;
            }
            n++;
          }
        }
        i++;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return localObject;
  }

  private void initLinkView()
  {
    this.mLinkLayout.setVisibility(0);
    for (int i = 0; i < this.mLinkTitle.length; i++)
    {
      View localView = LayoutInflater.from(this.mParent).inflate(2130903060, this.mLinkLayout, false);
      ((TextView)localView.findViewById(2131624049)).setText(this.mLinkTitle[i]);
      localView.setOnClickListener(this.mOnClickListener);
      localView.setClickable(true);
      localView.setId(i + LINK_UNIQUE_ID);
      this.mLinkLayout.addView(localView);
    }
  }

  private void openLink(int paramInt)
  {
    UiUtil.launchExternalApplication(getActivity(), this.mLinkUrl[paramInt]);
  }

  protected boolean needTray()
  {
    return this.mLaunchedFromTray;
  }

  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    Bundle localBundle = getArguments();
    if ((localBundle != null) && (localBundle.containsKey("LaunchedFromTray")))
      this.mLaunchedFromTray = localBundle.getBoolean("LaunchedFromTray");
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mParent.getActionBar().show();
    if ((paramBundle != null) && (paramBundle.containsKey("CAMPAIGN_DATA")))
    {
      this.mCampaign = ((Campaign)paramBundle.getSerializable("CAMPAIGN_DATA"));
      setCampaign(this.mCampaign);
    }
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView = paramLayoutInflater.inflate(2130903064, paramViewGroup, false);
    ImageView localImageView = (ImageView)localView.findViewById(2131624047);
    TextView localTextView1 = (TextView)localView.findViewById(2131624046);
    this.mLinkLayout = ((LinearLayout)localView.findViewById(2131624062));
    this.mLinkLayout.setVisibility(8);
    L.I("Width " + localImageView.getLayoutParams().width);
    L.I("Height " + localImageView.getLayoutParams().height);
    if (!UiUtil.isTablet(getActivity()))
    {
      localImageView.getLayoutParams().height = ((int)UiUtil.screenWidth(getActivity()));
      localImageView.requestLayout();
    }
    UiUtil.loadImageAsync(getActivity(), localImageView, this.mImageUrl);
    ((TextView)localView.findViewById(2131624059)).setText(Html.fromHtml(this.mTitle));
    TextView localTextView2 = (TextView)localView.findViewById(2131624058);
    localTextView2.setText(Html.fromHtml(this.mMainTitle));
    localTextView2.setVisibility(8);
    this.details = ((TextView)localView.findViewById(2131624060));
    this.details.setClickable(true);
    this.details.setMovementMethod(LinkMovementMethod.getInstance());
    this.mdetails = getCampaignParagraph();
    Spanned localSpanned = Html.fromHtml(UiUtil.removeUnderlines(Spannable.Factory.getInstance().newSpannable(this.mdetails)).toString(), new Html.ImageGetter()
    {
      public Drawable getDrawable(String paramAnonymousString)
      {
        LevelListDrawable localLevelListDrawable = new LevelListDrawable();
        new CampaignViewFragment.LoadImage(CampaignViewFragment.this).execute(new Object[] { paramAnonymousString, localLevelListDrawable });
        return localLevelListDrawable;
      }
    }
    , null);
    this.details.setText(localSpanned);
    UiUtil.setHiddenTitle(getActivity(), localTextView1, this.mCampaign);
    if ((this.mLinkTitle != null) && (this.mLinkTitle.length > 0))
      initLinkView();
    return localView;
  }

  public void onPause()
  {
    super.onPause();
  }

  public void onResume()
  {
    super.onResume();
    if (UsageTracker.i().isBackPressed())
      UsageTracker.i().viewCampaignDetails(getActivity(), this.mCampaign, false);
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    paramBundle.putSerializable("CAMPAIGN_DATA", this.mCampaign);
  }

  public void onStop()
  {
    super.onStop();
  }

  public void setCampaign(Campaign paramCampaign)
  {
    this.mCampaign = paramCampaign;
    this.mImageUrl = this.mCampaign.getImageUrl();
    this.mMainTitle = this.mCampaign.getMainHeadline();
    this.mdetails = "";
    int i = 0;
    try
    {
      int j = this.mCampaign.getBodyTextList().getBodyText().size();
      while (i < j)
      {
        int k = 0;
        int m = ((BodyText)this.mCampaign.getBodyTextList().getBodyText().get(i)).getParagraphList().getParagraph().size();
        while (k < m)
        {
          this.mTitle = ((BodyText)this.mCampaign.getBodyTextList().getBodyText().get(i)).getBodyTextHeadline();
          k++;
        }
        if ((this.mCampaign.getLinkList() != null) && (this.mCampaign.getLinkList().getLink() != null))
        {
          List localList = this.mCampaign.getLinkList().getLink();
          this.mLinkTitle = new String[localList.size()];
          this.mLinkUrl = new String[localList.size()];
          for (int n = 0; n < localList.size(); n++)
          {
            this.mLinkTitle[n] = ((Link)localList.get(n)).getLinkName();
            this.mLinkUrl[n] = ((Link)localList.get(n)).getLinkUrl();
          }
        }
        i++;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  protected void slEvent(boolean paramBoolean)
  {
    if ((!paramBoolean) && (UsageTracker.i().isBackPressed()))
      UsageTracker.i().viewCampaignDetails(getActivity(), this.mCampaign, false);
  }

  class LoadImage extends AsyncTask<Object, Void, Bitmap>
  {
    private LevelListDrawable mDrawable;

    LoadImage()
    {
    }

    protected Bitmap doInBackground(Object[] paramArrayOfObject)
    {
      String str = (String)paramArrayOfObject[0];
      this.mDrawable = ((LevelListDrawable)paramArrayOfObject[1]);
      L.D("doInBackground " + str);
      try
      {
        Bitmap localBitmap = BitmapFactory.decodeStream(new URL(str).openStream());
        return localBitmap;
      }
      catch (FileNotFoundException localFileNotFoundException)
      {
        localFileNotFoundException.printStackTrace();
        return null;
      }
      catch (MalformedURLException localMalformedURLException)
      {
        while (true)
          localMalformedURLException.printStackTrace();
      }
      catch (IOException localIOException)
      {
        while (true)
          localIOException.printStackTrace();
      }
    }

    protected void onPostExecute(Bitmap paramBitmap)
    {
      L.D("onPostExecute drawable " + this.mDrawable);
      L.D("onPostExecute bitmap " + paramBitmap);
      if (paramBitmap != null)
      {
        BitmapDrawable localBitmapDrawable = new BitmapDrawable(paramBitmap);
        this.mDrawable.addLevel(1, 1, localBitmapDrawable);
        this.mDrawable.setBounds(0, 0, paramBitmap.getWidth(), paramBitmap.getHeight());
        this.mDrawable.setLevel(1);
        CharSequence localCharSequence = CampaignViewFragment.this.details.getText();
        CampaignViewFragment.this.details.setText(localCharSequence);
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.campaign.CampaignViewFragment
 * JD-Core Version:    0.6.2
 */