package com.ikea.kompis.browse;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.ikea.kompis.ShoppingCartActivity;
import com.ikea.kompis.browse.event.CategorySelectedEvent;
import com.ikea.kompis.browse.event.KeyboardEvent;
import com.ikea.kompis.browse.event.PerformSearchEvent;
import com.ikea.kompis.browse.event.SubCategorySelectedEvent;
import com.ikea.kompis.fragments.ContentFragment;
import com.ikea.kompis.fragments.SecondLevelContentFragment;
import com.ikea.kompis.products.ProductTopLevelAdapter;
import com.ikea.kompis.util.UiUtil;
import com.ikea.kompis.view.CustomEditText;
import com.ikea.shared.AppError;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.browse.model.Catalog;
import com.ikea.shared.browse.model.CatalogElement;
import com.ikea.shared.browse.model.CatalogElementListArray;
import com.ikea.shared.browse.model.CatalogElementSubCatagoryTree;
import com.ikea.shared.browse.model.CatalogElementTree;
import com.ikea.shared.browse.model.CatalogListBaseResponse;
import com.ikea.shared.browse.model.CatalogTopElementListing;
import com.ikea.shared.browse.service.CatalogService;
import com.ikea.shared.util.Constant;
import com.ikea.shared.util.L;
import com.ikea.shared.util.ServiceCallback;
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 CategorysBaseFragment extends SecondLevelContentFragment
{
  private static final String FROM_HOME = "FROM_HOME";
  private static final String FROM_SEARCH = "FROM_SEARCH";
  protected static final String KEY_KEYBOARD_SHOW = "KEY_KEYBOARD_SHOW";
  protected static final String KEY_LIST_STATE = "KEY_LIST_STATE";
  private static final String SEASONAL_CATEGORY = "seasonal";
  private List<CatalogElement> mCatalogElements = null;
  protected View mClose;
  protected TextView mErrorMessage;
  private EventHandler mEventHandler;
  protected View mFadeView;
  private boolean mFromHome;
  private boolean mFromSearch;
  protected boolean mKeyboardOpened = false;
  private boolean mLaunchedFromTray = false;
  private final View.OnClickListener mOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      switch (paramAnonymousView.getId())
      {
      default:
        return;
      case 2131624104:
      }
      CategorysBaseFragment.this.mSearch.setText("");
    }
  };
  protected ProductTopLevelAdapter mPhoneAdapter;
  protected ProgressBar mProgressBar;
  protected CustomEditText mSearch;
  protected int mSearchMargin = 0;
  private final ServiceCallback<CatalogListBaseResponse> mServiceCallback = new ServiceCallback()
  {
    public void done(CatalogListBaseResponse paramAnonymousCatalogListBaseResponse, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      L.I("callback done  :: " + paramAnonymousCatalogListBaseResponse);
      CategorysBaseFragment.this.mProgressBar.setVisibility(8);
      if ((paramAnonymousCatalogListBaseResponse != null) && (paramAnonymousCatalogListBaseResponse.isSuccessful()))
      {
        if ((paramAnonymousCatalogListBaseResponse.getCatalogList() != null) && (!paramAnonymousCatalogListBaseResponse.getCatalogList().isEmpty()))
        {
          ArrayList localArrayList = new ArrayList();
          Iterator localIterator = paramAnonymousCatalogListBaseResponse.getCatalogList().iterator();
          while (localIterator.hasNext())
          {
            CatalogTopElementListing localCatalogTopElementListing = (CatalogTopElementListing)localIterator.next();
            if ((localCatalogTopElementListing != null) && (localCatalogTopElementListing.getCatalogElementListNew() != null))
            {
              localArrayList.addAll(localCatalogTopElementListing.getCatalogElementListNew().getCatalogElementList());
              if ((localCatalogTopElementListing.getCatalog() != null) && (!TextUtils.isEmpty(localCatalogTopElementListing.getCatalog().getCatalogID())) && (localCatalogTopElementListing.getCatalog().getCatalogID().equalsIgnoreCase("seasonal")))
                CategorysBaseFragment.this.mSizeOfSeasonal = localCatalogTopElementListing.getCatalogElementListNew().getCatalogElementList().size();
            }
          }
          CategorysBaseFragment.access$002(CategorysBaseFragment.this, localArrayList);
          if ((CategorysBaseFragment.this.mCatalogElements != null) && (!CategorysBaseFragment.this.mCatalogElements.isEmpty()))
          {
            CategorysBaseFragment.this.refreshUI(CategorysBaseFragment.this.mCatalogElements, paramAnonymousAppError, paramAnonymousException);
            return;
          }
          CategorysBaseFragment.this.showErrorMessage(CategorysBaseFragment.this.getString(2131165566));
          return;
        }
        CategorysBaseFragment.this.showErrorMessage(CategorysBaseFragment.this.getString(2131165566));
        return;
      }
      CategorysBaseFragment.this.showErrorMessage(CategorysBaseFragment.this.getString(2131165474));
      if (paramAnonymousAppError != null)
      {
        UsageTracker.i().formError(CategorysBaseFragment.this.getActivity(), "getcatalogelements", paramAnonymousAppError.getMessage());
        return;
      }
      UsageTracker.i().formError(CategorysBaseFragment.this.getActivity(), "getcatalogelements", CategorysBaseFragment.this.getString(2131165474));
    }
  };
  protected int mSizeOfSeasonal = 0;
  private final TextWatcher mTextWatcher = new TextWatcher()
  {
    public void afterTextChanged(Editable paramAnonymousEditable)
    {
      View localView = CategorysBaseFragment.this.mClose;
      if (paramAnonymousEditable.toString().length() > 0);
      for (int i = 0; ; i = 8)
      {
        localView.setVisibility(i);
        Constant.i().setSearchString(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)
    {
    }
  };

  private void hideErrorMessage()
  {
    if (this.mErrorMessage.getVisibility() == 0)
      this.mErrorMessage.setVisibility(8);
  }

  public static ContentFragment newInstance(boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3)
  {
    CategoryTopLevelPhoneFragment localCategoryTopLevelPhoneFragment = new CategoryTopLevelPhoneFragment();
    Bundle localBundle = new Bundle();
    localBundle.putBoolean("LaunchedFromTray", paramBoolean1);
    localBundle.putBoolean("FROM_HOME", paramBoolean2);
    localBundle.putBoolean("FROM_SEARCH", paramBoolean3);
    localCategoryTopLevelPhoneFragment.setArguments(localBundle);
    return localCategoryTopLevelPhoneFragment;
  }

  private void refreshAdapter()
  {
    this.mProgressBar.setVisibility(0);
    CatalogService.i(getActivity()).getTopElementsAsyncNew("functional", this.mServiceCallback);
  }

  @SuppressLint({"ClickableViewAccessibility"})
  protected View getRightMenu(Context paramContext, ViewGroup paramViewGroup)
  {
    View localView = LayoutInflater.from(paramContext).inflate(2130903082, paramViewGroup, false);
    this.mSearch = ((CustomEditText)localView.findViewById(2131624103));
    ViewGroup.LayoutParams localLayoutParams = this.mSearch.getLayoutParams();
    int i = (int)UiUtil.screenWidth(paramContext);
    L.I(this, "screenWidth : " + i);
    if (this.mLaunchedFromTray)
      this.mSearchMargin = ((int)getResources().getDimension(2131361880));
    localLayoutParams.width = (i - this.mSearchMargin);
    this.mSearch.setLayoutParams(localLayoutParams);
    if (UiUtil.isTablet(paramContext))
      this.mSearch.setHint(paramContext.getString(2131165628).toUpperCase());
    while (true)
    {
      this.mClose = localView.findViewById(2131624104);
      this.mClose.setOnClickListener(this.mOnClickListener);
      this.mSearch.addTextChangedListener(this.mTextWatcher);
      this.mSearch.setInputType(32768);
      this.mSearch.setOnTouchListener(new View.OnTouchListener()
      {
        @SuppressLint({"ClickableViewAccessibility"})
        public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent)
        {
          CategorysBaseFragment.this.mSearch.setFocusableInTouchMode(true);
          CategorysBaseFragment.this.mKeyboardOpened = true;
          return false;
        }
      });
      this.mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener()
      {
        public void onFocusChange(View paramAnonymousView, boolean paramAnonymousBoolean)
        {
          if (paramAnonymousBoolean)
          {
            CategorysBaseFragment.this.mFadeView.setVisibility(0);
            CategorysBaseFragment.this.mKeyboardOpened = true;
            return;
          }
          CategorysBaseFragment.this.mFadeView.setVisibility(8);
          CategorysBaseFragment.this.mKeyboardOpened = false;
        }
      });
      this.mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener()
      {
        public boolean onEditorAction(TextView paramAnonymousTextView, int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent)
        {
          L.I(this, "keybopard actionId : " + paramAnonymousInt);
          if ((paramAnonymousInt == 3) || (paramAnonymousInt == 6) || (paramAnonymousInt == 5))
          {
            if (!TextUtils.isEmpty(CategorysBaseFragment.this.mSearch.getText().toString().trim()))
            {
              UiUtil.hideKeyBoard(CategorysBaseFragment.this.mSearch.getContext(), CategorysBaseFragment.this.mSearch);
              CategorysBaseFragment.this.mHandler.postDelayed(new Runnable()
              {
                public void run()
                {
                  Constant.i().setKeyBoardOpen(true);
                  CategorysBaseFragment.this.mBus.post(new PerformSearchEvent(CategorysBaseFragment.this.mSearch.getText().toString().trim()));
                }
              }
              , 500L);
            }
            return true;
          }
          return false;
        }
      });
      return localView;
      this.mSearch.setHint(paramContext.getString(2131165627).toUpperCase());
    }
  }

  public CharSequence getTitle(Context paramContext)
  {
    return "";
  }

  protected void moveToNext(CatalogElement paramCatalogElement, boolean paramBoolean)
  {
    if ((paramCatalogElement.getCatalogElementSubCatagoryTree() != null) && (paramCatalogElement.getCatalogElementSubCatagoryTree().getmCatalogElementree() != null) && (paramCatalogElement.getCatalogElementSubCatagoryTree().getmCatalogElementree().getCatalogElementList() != null) && (!paramCatalogElement.getCatalogElementSubCatagoryTree().getmCatalogElementree().getCatalogElementList().isEmpty()))
    {
      this.mBus.post(new CategorySelectedEvent(paramCatalogElement.getName(), paramCatalogElement.getID(), paramCatalogElement.getType(), paramCatalogElement.getCatalogElementSubCatagoryTree().getmCatalogElementree(), paramBoolean));
      return;
    }
    this.mBus.post(new SubCategorySelectedEvent(paramCatalogElement.getID(), paramCatalogElement.getName()));
  }

  protected boolean needAnimOnTitleBar()
  {
    return false;
  }

  protected boolean needTray()
  {
    return this.mLaunchedFromTray;
  }

  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    Bundle localBundle = getArguments();
    if (localBundle != null)
    {
      if (localBundle.containsKey("LaunchedFromTray"))
        this.mLaunchedFromTray = localBundle.getBoolean("LaunchedFromTray");
      if (localBundle.containsKey("FROM_HOME"))
        this.mFromHome = localBundle.getBoolean("FROM_HOME");
      if (localBundle.containsKey("FROM_SEARCH"))
        this.mFromSearch = localBundle.getBoolean("FROM_SEARCH");
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mEventHandler = new EventHandler(null);
    this.mParent.getActionBar().show();
    if ((paramBundle != null) && (paramBundle.containsKey("KEY_KEYBOARD_SHOW")))
      this.mKeyboardOpened = paramBundle.getBoolean("KEY_KEYBOARD_SHOW");
  }

  public void onPause()
  {
    super.onPause();
    try
    {
      this.mBus.unregister(this.mEventHandler);
      this.mServiceCallback.markInvalid();
      UiUtil.hideKeyBoard(this.mSearch.getContext(), this.mSearch);
      hideErrorMessage();
      return;
    }
    catch (Exception localException)
    {
      while (true)
        L.W("No event handler to unregister");
    }
  }

  public void onResume()
  {
    super.onResume();
    this.mBus.register(this.mEventHandler);
    this.mServiceCallback.markValid();
    if (this.mCatalogElements == null)
      refreshAdapter();
    while (true)
    {
      this.mSearch.setText(Constant.i().getSearchString());
      if (this.mKeyboardOpened)
        this.mSearch.requestFocus();
      if (UsageTracker.i().isBackPressed())
      {
        UsageTracker.i().popCategoryNavigationInfo(getActivity(), null);
        UsageTracker.i().viewTopLevelCategory(getActivity(), this.mLaunchedFromTray, this.mFromHome, this.mFromSearch);
      }
      return;
      refreshUI(this.mCatalogElements, null, null);
    }
  }

  public abstract void refreshUI(List<CatalogElement> paramList, AppError paramAppError, Exception paramException);

  protected void showErrorMessage(String paramString)
  {
    this.mProgressBar.setVisibility(8);
    this.mErrorMessage.setText(paramString);
    this.mErrorMessage.setVisibility(0);
    if (this.mFadeView != null)
      this.mFadeView.setVisibility(8);
  }

  protected void slEvent(boolean paramBoolean)
  {
    if ((!paramBoolean) && (UsageTracker.i().isBackPressed()))
      UsageTracker.i().viewTopLevelCategory(getActivity(), this.mLaunchedFromTray, this.mFromHome, this.mFromSearch);
  }

  private class EventHandler
  {
    private EventHandler()
    {
    }

    @Subscribe
    public void handleKeyBoard(KeyboardEvent paramKeyboardEvent)
    {
      L.I("handleKeyBoard capture  : ");
      CategorysBaseFragment.this.mFadeView.setVisibility(8);
      CategorysBaseFragment.this.mSearch.setFocusable(false);
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.browse.CategorysBaseFragment
 * JD-Core Version:    0.6.2
 */