package com.ikea.kompis.products;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewPropertyAnimator;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.ikea.kompis.ShoppingCartActivity;
import com.ikea.kompis.fragments.SecondLevelContentFragment;
import com.ikea.kompis.products.event.CancelFilterFragmentEvent;
import com.ikea.kompis.products.event.FilterAppliedEvent;
import com.ikea.kompis.products.event.ProductSelectedEvent;
import com.ikea.kompis.shopping.event.ShoppingListStateEvent;
import com.ikea.kompis.util.ErrorMessages;
import com.ikea.kompis.util.TempFilterCache;
import com.ikea.kompis.util.TempObjectCache;
import com.ikea.kompis.util.UiUtil;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.AppError;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.browse.model.CatalogElement;
import com.ikea.shared.browse.model.CatalogElementSubTree;
import com.ikea.shared.browse.model.ProductListing;
import com.ikea.shared.browse.service.CatalogService;
import com.ikea.shared.config.model.Country;
import com.ikea.shared.filter.model.AppliedFilters;
import com.ikea.shared.filter.model.AvailableFilters;
import com.ikea.shared.filter.model.CategoryFilter;
import com.ikea.shared.filter.model.CategoryFilterList;
import com.ikea.shared.products.model.RetailItemCommunication;
import com.ikea.shared.sort.model.SortList;
import com.ikea.shared.store.service.StoreCache;
import com.ikea.shared.util.Constant;
import com.ikea.shared.util.L;
import com.ikea.shared.util.ServiceCallback;
import com.ikea.shared.util.Util;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class ProductListBaseFragment extends SecondLevelContentFragment
{
  protected static final String CATALOG_ELEMENT = "CATALOG_ELEMENT";
  protected static final String CATEGORY_ID = "CATEGORY_ID";
  protected static final String CATEGORY_NAME = "CATEGORY_NAME";
  protected static final String FILTER_FRAGMENT = "FILTER_FRAGMENT";
  private static final String FILTER_FRAGMENT_EMPTY = "FILTER_FRAGMENT_EMPTY";
  protected static final String FROM_SEARCH = "FROM_SEARCH";
  private static final String IS_FROM_FILTER = "FROM_FILTER";
  protected static final String IS_SEASONAL = "IS_SEASONAL";
  protected static final String KEY_KEYBOARD_SHOW = "KEY_KEYBOARD_SHOW";
  protected static final String KEY_LIST_STATE = "KEY_LIST_STATE";
  protected static final String KEY_SEARCHED_TEXT = "KEY_SEARCHED_TEXT";
  protected static final String KEY_SEARCH_EDIT_STATE = "KEY_SEARCH_EDIT_STATE";
  private static final String OPEN_FILTER_FRAGMENT = "OPEN_FILTER_FRAGMENT";
  protected static final String PARENT_CATEGORY_ID = "PARENT_CATEGORY_ID";
  private static final String PRODUCT_ITEM = "PRODUCT_ITEM";
  protected static final String SEARCH_TEXT = "SEARCH_TEXT";
  private static final float VIEW_FADED = 0.7F;
  private AppliedFilters appliedFilters;
  protected boolean isFilterFragmentEmpty = true;
  protected boolean isFilterListOpen;
  protected boolean isFragmentEmpty = false;
  private boolean isLandscape;
  protected boolean isSeasonal;
  private boolean isTablet;
  private AvailableFilters mAvailablefilters;
  protected CatalogElement mCatalogElement = null;
  protected String mCategoryId;
  private String mCategoryName = "";
  protected View mClose;
  private float mDeviceHeight;
  private float mDeviceWidth;
  protected TextView mEmptySearchText;
  protected View mEmptySearchView;
  private int mErrorCode;
  private EventHandler mEventHandler;
  protected View mFadeView;
  protected View mFilterBar;
  protected View mFilterFadeView;
  public FilterFragment mFilterFragment;
  protected TextView mFilterHeader;
  protected FrameLayout mFilterHolder;
  protected boolean mFromFilter = false;
  protected boolean mFromSearch = false;
  private String mFunctionName = "functional";
  protected boolean mKeyboardOpened = false;
  protected final View.OnClickListener mOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      switch (paramAnonymousView.getId())
      {
      default:
        return;
      case 2131624104:
        ProductListBaseFragment.this.mSearch.setText("");
        Constant.i().setSearchString("");
        Constant.i().setTopSearchString("");
        return;
      case 2131624000:
        ProductListBaseFragment.this.showFilter(true);
        return;
      case 2131624006:
      }
      ProductListBaseFragment.this.showFilter(true);
    }
  };
  protected String mParentCategoryId;
  private final ServiceCallback<ProductListing> mProductListServiceCallback = new ServiceCallback()
  {
    public void done(ProductListing paramAnonymousProductListing, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      if (ProductListBaseFragment.this.getActivity() == null);
      do
      {
        return;
        if (ProductListBaseFragment.this.mFromSearch)
        {
          ProductListBaseFragment.this.mSearch.setEnabled(true);
          ProductListBaseFragment.this.mClose.setEnabled(true);
        }
        if (paramAnonymousProductListing != null)
        {
          ProductListBaseFragment.access$002(ProductListBaseFragment.this, paramAnonymousProductListing.getmAvailablefilters());
          ProductListBaseFragment.access$102(ProductListBaseFragment.this, paramAnonymousProductListing.getSortList());
          ProductListBaseFragment.this.tempFilterCache.setCachedSortList(ProductListBaseFragment.this.mSortList);
          if ((paramAnonymousProductListing.isSuccessful()) && (paramAnonymousProductListing.getRetailItemComm() != null) && (!paramAnonymousProductListing.getRetailItemComm().isEmpty()))
          {
            if (!UiUtil.isConnectionAvailable(ProductListBaseFragment.this.mParent))
              UiUtil.showNetworkToast(ProductListBaseFragment.this.mParent, true);
            ProductListBaseFragment.access$502(ProductListBaseFragment.this, paramAnonymousProductListing.getRetailItemComm());
            ProductListBaseFragment.this.tempFilterCache.cacheOrignalRetailItemComm(ProductListBaseFragment.this.mRetailItemComm);
            ProductListBaseFragment.this.tempFilterCache.cacheCurrentRetailItemComm(ProductListBaseFragment.this.mRetailItemComm);
            L.I("ProductInfoListing refreshUI " + paramAnonymousProductListing);
            if (ProductListBaseFragment.this.mFromSearch)
              UsageTracker.i().viewSearchResult(ProductListBaseFragment.this.getActivity(), ProductListBaseFragment.this.mSearchText, ProductListBaseFragment.this.mRetailItemComm.size());
            while (true)
            {
              ProductListBaseFragment.this.tempFilterCache.setAvailableCachedFilter(ProductListBaseFragment.this.mAvailablefilters);
              ProductListBaseFragment.this.tempFilterCache.setAvailableCurrentCachedFilter(ProductListBaseFragment.this.mAvailablefilters);
              ProductListBaseFragment.this.hideError();
              ProductListBaseFragment.this.refreshUI(ProductListBaseFragment.this.mRetailItemComm, paramAnonymousAppError, paramAnonymousException);
              return;
              UsageTracker.i().viewCategoryProducts(ProductListBaseFragment.this.getActivity());
              ProductListBaseFragment.this.addChapterFilterInCategoryFilter();
            }
          }
          if ((ProductListBaseFragment.this.mFromSearch) && (paramAnonymousProductListing.getRetailItemComm() != null) && (paramAnonymousProductListing.getRetailItemComm().size() == 0))
            UsageTracker.i().viewSearchResult(ProductListBaseFragment.this.getActivity(), ProductListBaseFragment.this.mSearchText, 0);
          while (true)
          {
            ProductListBaseFragment.this.showFilterHeader(false);
            if (!ProductListBaseFragment.this.isAdded())
              break;
            String str3 = ErrorMessages.getErrorMessage(ProductListBaseFragment.this.mParent, paramAnonymousProductListing.getErrorCode());
            if (str3.isEmpty())
              str3 = ProductListBaseFragment.this.getResources().getString(2131165494);
            ProductListBaseFragment.this.showError(str3, ProductListBaseFragment.this.getResources().getString(2131165714), UiUtil.isConnectionAvailable(ProductListBaseFragment.this.mParent), paramAnonymousException, ProductListBaseFragment.this.mErrorCode);
            return;
            UsageTracker.i().formError(ProductListBaseFragment.this.getActivity(), "getproductlistforcategory", "");
          }
        }
        if (paramAnonymousAppError != null)
          ProductListBaseFragment.access$902(ProductListBaseFragment.this, paramAnonymousAppError.getErrorCode());
      }
      while (!ProductListBaseFragment.this.isAdded());
      if (UiUtil.isConnectionAvailable(ProductListBaseFragment.this.mParent))
      {
        ProductListBaseFragment.this.showError(ProductListBaseFragment.this.getResources().getString(2131165474), ProductListBaseFragment.this.getResources().getString(2131165714), true, paramAnonymousException, ProductListBaseFragment.this.mErrorCode);
        ProductListBaseFragment.this.showFilterHeader(false);
        if (!ProductListBaseFragment.this.mFromSearch)
          break label793;
        if (paramAnonymousAppError != null)
          UsageTracker.i().formError(ProductListBaseFragment.this.getActivity(), "search", paramAnonymousAppError.getMessage());
      }
      else
      {
        if ((StoreCache.i(ProductListBaseFragment.this.getActivity()).isInStore()) && (AppConfigManager.i(ProductListBaseFragment.this.getActivity()).getAppConfigData() != null) && (AppConfigManager.i(ProductListBaseFragment.this.getActivity()).getAppConfigData().getConfig() != null) && (AppConfigManager.i(ProductListBaseFragment.this.getActivity()).getAppConfigData().getConfig().ismWifiEnabled()));
        for (String str1 = ProductListBaseFragment.this.getResources().getString(2131165509); ; str1 = ProductListBaseFragment.this.getResources().getString(2131165512))
        {
          ProductListBaseFragment localProductListBaseFragment = ProductListBaseFragment.this;
          String str2 = ProductListBaseFragment.this.getResources().getString(2131165750);
          int i = ProductListBaseFragment.this.mErrorCode;
          localProductListBaseFragment.showError(str2, str1, false, paramAnonymousException, i);
          break;
        }
      }
      UsageTracker.i().formError(ProductListBaseFragment.this.getActivity(), "search", ProductListBaseFragment.this.getString(2131165474));
      return;
      label793: if (paramAnonymousAppError != null)
      {
        UsageTracker.i().formError(ProductListBaseFragment.this.getActivity(), "getproductlistforcategory", paramAnonymousAppError.getMessage());
        return;
      }
      UsageTracker.i().formError(ProductListBaseFragment.this.getActivity(), "getproductlistforcategory", ProductListBaseFragment.this.getString(2131165474));
    }
  };
  private List<RetailItemCommunication> mRetailItemComm;
  protected EditText mSearch;
  protected int mSearchMargin;
  protected TextView mSearchResultHeader;
  protected String mSearchText;
  private SortList mSortList;
  protected Button mStartAgain;
  private final TextWatcher mTextWatcher = new TextWatcher()
  {
    public void afterTextChanged(Editable paramAnonymousEditable)
    {
      View localView;
      if (ProductListBaseFragment.this.mClose != null)
      {
        localView = ProductListBaseFragment.this.mClose;
        if (paramAnonymousEditable.toString().length() <= 0)
          break label57;
      }
      label57: for (int i = 0; ; i = 8)
      {
        localView.setVisibility(i);
        if (ProductListBaseFragment.this.mFromSearch)
          ProductListBaseFragment.this.mTmpSearchText = paramAnonymousEditable.toString();
        return;
      }
    }

    public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
    }

    public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
    }
  };
  protected String mTmpSearchText;
  private boolean needToOpenFilterFragment;
  private TempFilterCache tempFilterCache;

  private void addChapterFilterInCategoryFilter()
  {
    if (this.mAvailablefilters == null)
      this.mAvailablefilters = new AvailableFilters();
    CategoryFilterList localCategoryFilterList = new CategoryFilterList();
    this.mAvailablefilters.setCategoryFilter(localCategoryFilterList);
    if (this.mAvailablefilters.getCategoryFilter().getCategoryFiltersList() == null)
    {
      ArrayList localArrayList = new ArrayList();
      this.mAvailablefilters.getCategoryFilter().setCategoryFiltersList(localArrayList);
    }
    if ((this.mCatalogElement != null) && (this.mCatalogElement.getmCatalogElementSubTree() != null) && (this.mCatalogElement.getmCatalogElementSubTree().getCatalogElementList() != null) && (this.mCatalogElement.getmCatalogElementSubTree().getCatalogElementList().size() > 0))
    {
      Iterator localIterator = this.mCatalogElement.getmCatalogElementSubTree().getCatalogElementList().iterator();
      while (localIterator.hasNext())
      {
        CatalogElement localCatalogElement = (CatalogElement)localIterator.next();
        if ((localCatalogElement.getType().equalsIgnoreCase("CHAPTER")) || (localCatalogElement.getType().equalsIgnoreCase("CATEGORY SYSTEM CHAPTER")))
        {
          CategoryFilter localCategoryFilter = new CategoryFilter(localCatalogElement.getName(), localCatalogElement.getID());
          this.mAvailablefilters.getCategoryFilter().getCategoryFiltersList().add(localCategoryFilter);
        }
      }
    }
  }

  private static ProductListBaseFragment getFragment(Context paramContext)
  {
    if (UiUtil.isTablet(paramContext))
      return new ProductListTabFragment();
    return new ProductListPhoneFragment();
  }

  private void hideTitleIcons()
  {
    if (this.mFromSearch)
    {
      this.mSearch.setVisibility(4);
      this.mClose.setVisibility(4);
      this.mParent.setTitle(this.mSearch.getText().toString());
    }
    if (!this.isTablet)
    {
      this.mParent.hideSL();
      this.mParent.hideBackButton();
    }
  }

  public static ProductListBaseFragment newInstance(Context paramContext, String paramString, Boolean paramBoolean)
  {
    Bundle localBundle = new Bundle();
    localBundle.putString("SEARCH_TEXT", paramString);
    localBundle.putBoolean("FROM_SEARCH", paramBoolean.booleanValue());
    ProductListBaseFragment localProductListBaseFragment = getFragment(paramContext);
    localProductListBaseFragment.setArguments(localBundle);
    return localProductListBaseFragment;
  }

  public static ProductListBaseFragment newInstance(Context paramContext, String paramString1, String paramString2, String paramString3, CatalogElement paramCatalogElement, boolean paramBoolean)
  {
    Bundle localBundle = new Bundle();
    localBundle.putString("CATEGORY_ID", paramString2);
    localBundle.putString("CATEGORY_NAME", paramString3);
    localBundle.putString("PARENT_CATEGORY_ID", paramString1);
    localBundle.putBoolean("IS_SEASONAL", paramBoolean);
    localBundle.putSerializable("CATALOG_ELEMENT", paramCatalogElement);
    ProductListBaseFragment localProductListBaseFragment = getFragment(paramContext);
    localProductListBaseFragment.setArguments(localBundle);
    return localProductListBaseFragment;
  }

  private void refreshAdapter()
  {
    L.I("mFunctionName : " + this.mFunctionName);
    if (this.mFromSearch)
      CatalogService.i(getActivity()).searchItemAsync(this.mSearchText, null, this.mProductListServiceCallback);
    while (true)
    {
      this.mFromFilter = false;
      return;
      this.mCategoryId = this.mCategoryId.trim();
      if (UiUtil.isTablet(this.mParent))
        CatalogService.i(getActivity()).getCatalogElementsNewAsync(this.mFunctionName, this.mParentCategoryId, this.mCategoryId, null, this.mProductListServiceCallback);
      else
        this.mHandler.postDelayed(new Runnable()
        {
          public void run()
          {
            CatalogService.i(ProductListBaseFragment.this.getActivity()).getCatalogElementsNewAsync(ProductListBaseFragment.this.mFunctionName, ProductListBaseFragment.this.mParentCategoryId, ProductListBaseFragment.this.mCategoryId, null, ProductListBaseFragment.this.mProductListServiceCallback);
          }
        }
        , 350L);
    }
  }

  private void sendRequestWithNewString()
  {
    if ((this.mRetailItemComm != null) && (!this.mRetailItemComm.isEmpty()))
    {
      this.mRetailItemComm.clear();
      this.mRetailItemComm = null;
      notifyDataChanged();
    }
    if (this.mEmptySearchView.getVisibility() == 0)
      this.mEmptySearchView.setVisibility(8);
    showProgress();
    this.mSearchResultHeader.setVisibility(4);
    refreshAdapter();
  }

  private void showTitleIcons()
  {
    if (this.mFromSearch)
    {
      this.mSearch.setVisibility(0);
      this.mClose.setVisibility(0);
      this.mParent.setTitle("");
    }
    if (!this.isTablet)
    {
      this.mParent.showSL();
      this.mParent.showBackButton();
    }
  }

  protected void checkAndCloseSL()
  {
    if ((UiUtil.isTablet(this.mParent)) && (UiUtil.isLandscape(this.mParent)) && (this.mParent.isShoppingListMaximize()))
    {
      this.mParent.closeShoppingList();
      this.mBus.post(new ShoppingListStateEvent(false));
    }
  }

  protected View getRightMenu(Context paramContext, ViewGroup paramViewGroup)
  {
    boolean bool = this.mFromSearch;
    View localView = null;
    if (bool)
    {
      localView = LayoutInflater.from(paramContext).inflate(2130903082, paramViewGroup, false);
      this.mSearch = ((EditText)localView.findViewById(2131624103));
      ViewGroup.LayoutParams localLayoutParams = this.mSearch.getLayoutParams();
      localLayoutParams.width = ((int)UiUtil.screenWidth(paramContext));
      this.mSearch.setLayoutParams(localLayoutParams);
      this.mSearch.setInputType(32768);
      this.mClose = localView.findViewById(2131624104);
      this.mClose.setOnClickListener(this.mOnClickListener);
      this.mSearch.addTextChangedListener(this.mTextWatcher);
      this.mSearch.setEnabled(false);
      this.mClose.setEnabled(false);
      this.mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener()
      {
        public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean)
        {
          if (paramAnonymousBoolean)
          {
            ProductListBaseFragment.this.checkAndCloseSL();
            ProductListBaseFragment.this.mFadeView.setVisibility(0);
            return;
          }
          ProductListBaseFragment.this.mFadeView.setVisibility(8);
        }
      });
      this.mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener()
      {
        public boolean onEditorAction(TextView paramAnonymousTextView, int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent)
        {
          if (paramAnonymousInt == 3)
          {
            ProductListBaseFragment.this.mSearchText = ProductListBaseFragment.this.mSearch.getText().toString().trim();
            if (ProductListBaseFragment.this.mSearchText.length() > 0)
            {
              UiUtil.hideKeyBoard(ProductListBaseFragment.this.mParent, ProductListBaseFragment.this.mSearch);
              ProductListBaseFragment.this.hideError();
              Constant.i().setSearchString(ProductListBaseFragment.this.mSearchText);
              Constant.i().setTopSearchString(ProductListBaseFragment.this.mSearchText);
              ProductListBaseFragment.this.mSearch.setEnabled(false);
              ProductListBaseFragment.this.mClose.setEnabled(false);
              TempObjectCache.i(ProductListBaseFragment.this.mParent).resetCachedRetailItemComm();
              TempFilterCache.i(ProductListBaseFragment.this.mParent).resetFilterCache();
              ProductListBaseFragment.this.isFilterFragmentEmpty = true;
              ProductListBaseFragment.this.showFilterHeader(false);
              ProductListBaseFragment.this.sendRequestWithNewString();
            }
            return true;
          }
          return false;
        }
      });
    }
    return localView;
  }

  protected CharSequence getTitle(Context paramContext)
  {
    return this.mCategoryName;
  }

  public boolean goBack()
  {
    if (this.isFilterListOpen)
    {
      showFilter(true);
      if (this.mFilterFragment != null)
      {
        this.mFilterFragment.mCanceRequest = true;
        this.mFilterFragment.showProgress(false);
      }
      return true;
    }
    TempObjectCache.i(this.mParent).resetCachedRetailItemComm();
    TempFilterCache.i(this.mParent).resetFilterCache();
    return super.goBack();
  }

  protected abstract void hideError();

  protected void moveToNext(int paramInt)
  {
    if (this.mRetailItemComm != null)
    {
      RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)this.mRetailItemComm.get(paramInt);
      if (localRetailItemCommunication != null)
        this.mBus.post(new ProductSelectedEvent(localRetailItemCommunication.getItemType().trim(), localRetailItemCommunication.getItemNo().trim(), paramInt, localRetailItemCommunication.getGPRItemOrigin(), this.mFromSearch));
    }
  }

  protected boolean needAnimOnTitleBar()
  {
    return !this.mFromSearch;
  }

  protected abstract void notifyDataChanged();

  public void onActivityCreated(@Nullable Bundle paramBundle)
  {
    super.onActivityCreated(paramBundle);
    if ((paramBundle != null) && (paramBundle.containsKey("PRODUCT_ITEM")))
      this.mRetailItemComm = TempObjectCache.i(this.mParent).getCachedProductListData();
    if ((paramBundle != null) && (paramBundle.containsKey("OPEN_FILTER_FRAGMENT")))
      this.needToOpenFilterFragment = true;
    if ((paramBundle != null) && (paramBundle.containsKey("FILTER_FRAGMENT_EMPTY")))
      this.isFilterFragmentEmpty = paramBundle.getBoolean("FILTER_FRAGMENT_EMPTY");
    if ((paramBundle != null) && (paramBundle.containsKey("FROM_FILTER")))
      this.mFromFilter = paramBundle.getBoolean("FROM_FILTER");
  }

  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    Bundle localBundle = getArguments();
    if (localBundle != null)
    {
      if (localBundle.containsKey("PARENT_CATEGORY_ID"))
        this.mParentCategoryId = localBundle.getString("PARENT_CATEGORY_ID");
      if (localBundle.containsKey("CATEGORY_ID"))
        this.mCategoryId = localBundle.getString("CATEGORY_ID");
      if (localBundle.containsKey("CATEGORY_NAME"))
        this.mCategoryName = localBundle.getString("CATEGORY_NAME");
      if (!localBundle.containsKey("FROM_SEARCH"))
        break label190;
    }
    label190: for (this.mFromSearch = localBundle.getBoolean("FROM_SEARCH"); ; this.mFromSearch = false)
    {
      if (localBundle.containsKey("CATALOG_ELEMENT"))
        this.mCatalogElement = ((CatalogElement)localBundle.getSerializable("CATALOG_ELEMENT"));
      if (localBundle.containsKey("SEARCH_TEXT"))
      {
        this.mSearchText = localBundle.getString("SEARCH_TEXT");
        this.mTmpSearchText = this.mSearchText;
      }
      if (Util.isNWP(this.mParent))
        this.mFunctionName = "products";
      if (localBundle.containsKey("IS_SEASONAL"))
      {
        this.isSeasonal = localBundle.getBoolean("IS_SEASONAL");
        if (this.isSeasonal)
          this.mFunctionName = "seasonal";
      }
      return;
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mEventHandler = new EventHandler(null);
    if (this.mFromSearch)
      setListnerToRootView();
    this.isTablet = UiUtil.isTablet(getActivity());
    this.isLandscape = UiUtil.isLandscape(getActivity());
    this.mDeviceWidth = UiUtil.screenWidth(getActivity());
    this.mDeviceHeight = UiUtil.screenHeight(getActivity());
    this.tempFilterCache = TempFilterCache.i(getActivity());
  }

  public void onPause()
  {
    super.onPause();
    L.E("onPause() called");
    try
    {
      this.mBus.unregister(this.mEventHandler);
      this.mProductListServiceCallback.markInvalid();
      return;
    }
    catch (Exception localException)
    {
      while (true)
        L.W("No event handler to unregister");
    }
  }

  public void onResume()
  {
    super.onResume();
    this.mBus.register(this.mEventHandler);
    this.mProductListServiceCallback.markValid();
    if ((this.mRetailItemComm == null) && (!this.mFromFilter))
    {
      refreshAdapter();
      if (this.mFromSearch)
      {
        this.mSearch.setText(this.mTmpSearchText);
        if (this.mKeyboardOpened)
          this.mSearch.requestFocus();
      }
      if (UsageTracker.i().isBackPressed())
      {
        if ((!this.mFromSearch) || (this.mRetailItemComm == null) || (this.mRetailItemComm.isEmpty()))
          break label344;
        UsageTracker.i().viewSearchResult(getActivity(), this.mSearchText, this.mRetailItemComm.size());
      }
      label131: if (!this.needToOpenFilterFragment)
        break label357;
      this.needToOpenFilterFragment = false;
      showFilter(false);
    }
    label344: label357: 
    while (!this.isFilterListOpen)
    {
      return;
      if (this.mFromSearch)
      {
        this.mSearch.setEnabled(true);
        this.mClose.setEnabled(true);
      }
      if (((this.tempFilterCache.getCurrentCachedRetailItemComm() == null) || ((this.tempFilterCache.getCurrentCachedRetailItemComm() != null) && (this.tempFilterCache.getCurrentCachedRetailItemComm().isEmpty()))) && (this.tempFilterCache.isResetFilters()))
      {
        this.tempFilterCache.setResetFilters(false);
        refreshAdapter();
        break;
      }
      this.mRetailItemComm = this.tempFilterCache.getCurrentCachedRetailItemComm();
      this.mAvailablefilters = this.tempFilterCache.getAvailableCurrentCachedFilter();
      this.appliedFilters = this.tempFilterCache.getAppliedCurrentCachedFilters();
      this.mSortList = this.tempFilterCache.getCachedSortList();
      refreshUI(this.mRetailItemComm, null, null);
      if ((this.mRetailItemComm == null) || (!this.mRetailItemComm.isEmpty()))
        break;
      showError(getResources().getString(2131165345), getResources().getString(2131165714), UiUtil.isConnectionAvailable(this.mParent), null, this.mErrorCode);
      break;
      UsageTracker.i().viewCategoryProducts(getActivity());
      break label131;
    }
    hideTitleIcons();
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    if (this.mRetailItemComm != null)
    {
      paramBundle.putString("PRODUCT_ITEM", "PRODUCT_ITEM");
      TempObjectCache.i(this.mParent).cacheRetailItemComm(this.mRetailItemComm);
    }
    paramBundle.putBoolean("FROM_FILTER", this.mFromFilter);
    if (this.isFilterListOpen)
      paramBundle.putBoolean("OPEN_FILTER_FRAGMENT", this.isFilterListOpen);
    paramBundle.putBoolean("FILTER_FRAGMENT_EMPTY", this.isFilterFragmentEmpty);
  }

  public void refreshUI(List<RetailItemCommunication> paramList, AppError paramAppError, Exception paramException)
  {
  }

  public void setFilterWidth()
  {
    ViewGroup.LayoutParams localLayoutParams = this.mFilterHolder.getLayoutParams();
    if (this.isTablet)
    {
      this.mFilterHolder.setTranslationX(this.mDeviceWidth);
      if (this.isLandscape)
        localLayoutParams.width = ((int)(this.mDeviceWidth / 3.0F));
    }
    while (true)
    {
      this.mFilterHolder.setLayoutParams(localLayoutParams);
      return;
      localLayoutParams.width = ((int)(this.mDeviceWidth / 2.0F));
      continue;
      localLayoutParams.width = ((int)this.mDeviceWidth);
      this.mFilterHolder.setTranslationY(this.mDeviceHeight);
      this.mFilterHolder.animate().translationY(this.mDeviceHeight).setListener(new Animator.AnimatorListener()
      {
        public void onAnimationCancel(Animator paramAnonymousAnimator)
        {
        }

        public void onAnimationEnd(Animator paramAnonymousAnimator)
        {
          if (!ProductListBaseFragment.this.isFilterListOpen)
            ProductListBaseFragment.this.mFilterHolder.setVisibility(4);
        }

        public void onAnimationRepeat(Animator paramAnonymousAnimator)
        {
        }

        public void onAnimationStart(Animator paramAnonymousAnimator)
        {
        }
      });
    }
  }

  public void setListnerToRootView()
  {
    final View localView = getActivity().getWindow().getDecorView().findViewById(16908290);
    localView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
      public void onGlobalLayout()
      {
        if (localView.getRootView().getHeight() - localView.getHeight() > 400)
        {
          if ((ProductListBaseFragment.this.mFadeView != null) && (ProductListBaseFragment.this.mFadeView.getVisibility() == 8))
          {
            ProductListBaseFragment.this.mFadeView.setVisibility(0);
            ProductListBaseFragment.this.mSearch.requestFocus();
          }
          ProductListBaseFragment.this.mKeyboardOpened = true;
        }
        while (!ProductListBaseFragment.this.mKeyboardOpened)
          return;
        if ((ProductListBaseFragment.this.mFadeView != null) && (ProductListBaseFragment.this.mFadeView.getVisibility() == 0))
        {
          ProductListBaseFragment.this.mFadeView.setVisibility(8);
          ProductListBaseFragment.this.mSearch.clearFocus();
        }
        ProductListBaseFragment.this.mKeyboardOpened = false;
      }
    });
  }

  protected abstract void showError(String paramString1, String paramString2, boolean paramBoolean, Exception paramException, int paramInt);

  public void showFilter(boolean paramBoolean)
  {
    if (this.isFilterFragmentEmpty)
    {
      FragmentTransaction localFragmentTransaction = getChildFragmentManager().beginTransaction();
      if (this.mFromSearch)
      {
        this.mFilterFragment = FilterFragment.newInstance(this.mFromSearch, this.mSearchText);
        localFragmentTransaction.replace(this.mFilterHolder.getId(), this.mFilterFragment, "FILTER_FRAGMENT");
        localFragmentTransaction.commit();
        this.isFilterFragmentEmpty = false;
        label68: if (this.isFilterListOpen)
          break label293;
        if (this.mFilterHolder != null)
        {
          this.isFilterListOpen = true;
          hideTitleIcons();
          if (!this.isTablet)
            break label272;
          if (!paramBoolean)
            break label221;
          if (!this.isLandscape)
            break label196;
          this.mFilterHolder.animate().translationX(this.mDeviceWidth - this.mDeviceWidth / 3.0F);
        }
      }
    }
    while (true)
    {
      this.mFilterFadeView.setVisibility(0);
      this.mFilterFadeView.animate().alpha(0.7F);
      return;
      this.mFilterFragment = FilterFragment.newInstance(this.mFunctionName, this.mParentCategoryId, this.mCategoryId);
      break;
      this.mFilterFragment = ((FilterFragment)getChildFragmentManager().findFragmentByTag("FILTER_FRAGMENT"));
      break label68;
      label196: this.mFilterHolder.animate().translationX(this.mDeviceWidth - this.mDeviceWidth / 2.0F);
      continue;
      label221: if (this.isLandscape)
        this.mFilterHolder.setTranslationX(this.mDeviceWidth - this.mDeviceWidth / 3.0F);
      else
        this.mFilterHolder.setTranslationX(this.mDeviceWidth - this.mDeviceWidth / 2.0F);
    }
    label272: this.mFilterHolder.setVisibility(0);
    this.mFilterHolder.animate().translationY(0.0F);
    return;
    label293: this.isFilterListOpen = false;
    showTitleIcons();
    if (this.isTablet)
    {
      if (paramBoolean)
        this.mFilterHolder.animate().translationX(this.mDeviceWidth);
      while (true)
      {
        this.mFilterFadeView.setVisibility(8);
        this.mFilterFadeView.animate().alpha(0.0F);
        return;
        this.mFilterHolder.setTranslationX(this.mDeviceWidth);
      }
    }
    this.mFilterHolder.animate().translationY(this.mDeviceHeight);
  }

  protected abstract void showFilterHeader(boolean paramBoolean);

  protected abstract void showProgress();

  protected void slEvent(boolean paramBoolean)
  {
    if (!paramBoolean)
    {
      if ((this.mFromSearch) && (this.mRetailItemComm != null) && (!this.mRetailItemComm.isEmpty()))
        UsageTracker.i().viewSearchResult(getActivity(), this.mSearchText, this.mRetailItemComm.size());
    }
    else
      return;
    UsageTracker.i().viewCategoryProducts(getActivity());
  }

  private class EventHandler
  {
    private EventHandler()
    {
    }

    @Subscribe
    public void dismissFilterFragment(CancelFilterFragmentEvent paramCancelFilterFragmentEvent)
    {
      try
      {
        ProductListBaseFragment.this.showFilter(true);
        ProductListBaseFragment.this.mFromFilter = true;
        if (ProductListBaseFragment.this.mRetailItemComm.isEmpty())
        {
          String str = ProductListBaseFragment.this.getResources().getString(2131165345);
          ProductListBaseFragment.this.showError(str, ProductListBaseFragment.this.getResources().getString(2131165714), UiUtil.isConnectionAvailable(ProductListBaseFragment.this.mParent), null, ProductListBaseFragment.this.mErrorCode);
        }
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }

    @Subscribe
    public void handleFilterEvent(FilterAppliedEvent paramFilterAppliedEvent)
    {
      try
      {
        ProductListBaseFragment.access$502(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getCurrentCachedRetailItemComm());
        ProductListBaseFragment.access$002(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getAvailableCurrentCachedFilter());
        ProductListBaseFragment.access$1802(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getAppliedCurrentCachedFilters());
        ProductListBaseFragment.access$102(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getCachedSortList());
        ProductListBaseFragment.this.mFromFilter = true;
        if (ProductListBaseFragment.this.tempFilterCache.isResetFilters())
        {
          ProductListBaseFragment.access$502(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getOrignalCachedProductListData());
          ProductListBaseFragment.access$002(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getAvailableCurrentCachedFilter());
          ProductListBaseFragment.access$1802(ProductListBaseFragment.this, null);
          ProductListBaseFragment.access$102(ProductListBaseFragment.this, ProductListBaseFragment.this.tempFilterCache.getCachedSortList());
          ProductListBaseFragment.this.tempFilterCache.setResetFilters(false);
        }
        if (ProductListBaseFragment.this.mRetailItemComm.isEmpty())
        {
          ProductListBaseFragment.this.refreshUI(ProductListBaseFragment.this.mRetailItemComm, null, null);
          String str = ProductListBaseFragment.this.getResources().getString(2131165345);
          ProductListBaseFragment.this.showError(str, ProductListBaseFragment.this.getResources().getString(2131165714), UiUtil.isConnectionAvailable(ProductListBaseFragment.this.mParent), null, ProductListBaseFragment.this.mErrorCode);
          return;
        }
        ProductListBaseFragment.this.hideError();
        ProductListBaseFragment.this.refreshUI(ProductListBaseFragment.this.mRetailItemComm, null, null);
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.products.ProductListBaseFragment
 * JD-Core Version:    0.6.2
 */