package com.ikea.kompis.stores;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Layout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.ImageView;
import android.widget.TextView;
import com.ikea.kompis.stores.event.HeaderDrawnEvent;
import com.ikea.kompis.view.StoreDetailsLayout;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.store.service.StoreCache;
import com.ikea.shared.stores.model.StoreList;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.stores.model.StoreRefList;
import com.squareup.otto.Bus;
import java.util.ArrayList;
import java.util.List;

public class StorePagerAdapter extends PagerAdapter
{
  public static final String STORE_TAG = "STORE_TAG";
  private final Bus mBus;
  private final Context mContext;
  private final int mDeviceHight;
  private StoreRef mFavStore;
  private final boolean mFromFirstUserExp;
  private final LayoutInflater mInflater;
  private List<StoreRef> mList;
  private final View.OnClickListener mOnClick;
  private final View.OnTouchListener mOnTouch;

  public StorePagerAdapter(Context paramContext, List<StoreRef> paramList, Bus paramBus, View.OnClickListener paramOnClickListener, View.OnTouchListener paramOnTouchListener, int paramInt1, int paramInt2, boolean paramBoolean, StoreRef paramStoreRef)
  {
    this.mContext = paramContext;
    this.mList = new ArrayList(paramList);
    this.mBus = paramBus;
    this.mOnClick = paramOnClickListener;
    this.mOnTouch = paramOnTouchListener;
    this.mDeviceHight = paramInt1;
    this.mFavStore = paramStoreRef;
    this.mFromFirstUserExp = paramBoolean;
    this.mInflater = ((LayoutInflater)paramContext.getSystemService("layout_inflater"));
  }

  private boolean isFavStore(StoreRef paramStoreRef)
  {
    return (this.mFavStore != null) && (!TextUtils.isEmpty(this.mFavStore.getStoreNo())) && (paramStoreRef != null) && (!TextUtils.isEmpty(paramStoreRef.getStoreNo())) && (this.mFavStore.getStoreNo().equals(paramStoreRef.getStoreNo()));
  }

  public void destroyItem(View paramView, int paramInt, Object paramObject)
  {
    ((ViewPager)paramView).removeView((View)paramObject);
  }

  public int getCount()
  {
    return this.mList.size();
  }

  public int getItemPosition(Object paramObject)
  {
    return -2;
  }

  public int getStoreIndex(StoreRef paramStoreRef)
  {
    if ((paramStoreRef != null) && (this.mList != null))
    {
      int i = 0;
      int j = this.mList.size();
      while (i < j)
      {
        if (((StoreRef)this.mList.get(i)).getStoreNo().equals(paramStoreRef.getStoreNo()))
          return i;
        i++;
      }
    }
    return 0;
  }

  public StoreRef getStoreInfo(int paramInt)
  {
    if ((this.mList != null) && (!this.mList.isEmpty()))
      return (StoreRef)this.mList.get(paramInt);
    return null;
  }

  public Object instantiateItem(ViewGroup paramViewGroup, final int paramInt)
  {
    final StoreDetailsLayout localStoreDetailsLayout = (StoreDetailsLayout)this.mInflater.inflate(2130903153, paramViewGroup, false);
    localStoreDetailsLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener()
    {
      public boolean onPreDraw()
      {
        localStoreDetailsLayout.getViewTreeObserver().removeOnPreDrawListener(this);
        View localView = localStoreDetailsLayout.findViewById(2131624449);
        int i = localStoreDetailsLayout.findViewById(2131624448).getHeight();
        int j = localView.getHeight();
        if (j != 0)
          StorePagerAdapter.this.mBus.post(new HeaderDrawnEvent(j, i, paramInt));
        return true;
      }
    });
    localStoreDetailsLayout.setTag("STORE_TAG" + paramInt);
    final ImageView localImageView = (ImageView)localStoreDetailsLayout.findViewById(2131624301);
    final TextView localTextView = (TextView)localStoreDetailsLayout.findViewById(2131624302);
    localTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
      public void onGlobalLayout()
      {
        Layout localLayout = localTextView.getLayout();
        if (localLayout != null)
        {
          int i = localLayout.getLineCount();
          if ((i > 0) && (localLayout.getEllipsisCount(i - 1) > 0))
            localImageView.setVisibility(8);
          localTextView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
      }
    });
    View localView = localStoreDetailsLayout.findViewById(2131624447);
    ViewGroup.LayoutParams localLayoutParams = localView.getLayoutParams();
    localLayoutParams.height = (2 * this.mDeviceHight / 3);
    localView.setLayoutParams(localLayoutParams);
    ((StoreDetailsLayout)localStoreDetailsLayout).updateStoreData(this.mContext, this.mBus, getStoreInfo(paramInt), paramInt, isFavStore(getStoreInfo(paramInt)), this.mOnClick, this.mOnTouch, this.mFromFirstUserExp);
    paramViewGroup.addView(localStoreDetailsLayout);
    return localStoreDetailsLayout;
  }

  public boolean isViewFromObject(View paramView, Object paramObject)
  {
    return paramView == (View)paramObject;
  }

  public void notifyDataSetChanged()
  {
    AppConfigData localAppConfigData = AppConfigManager.i(this.mContext).getAppConfigData();
    StoreList localStoreList = StoreCache.i(this.mContext).getStoreList();
    if ((localAppConfigData != null) && (localAppConfigData.getFavStore() != null))
      this.mFavStore = localAppConfigData.getFavStore();
    if ((localStoreList != null) && (localStoreList.getStoreRefList() != null))
      this.mList = new ArrayList(localStoreList.getStoreRefList().getStoreRef());
    super.notifyDataSetChanged();
  }

  public void setFavorite(StoreRef paramStoreRef)
  {
    this.mFavStore = paramStoreRef;
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.stores.StorePagerAdapter
 * JD-Core Version:    0.6.2
 */