package com.ikea.kompis.stores;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.ikea.kompis.fragments.BaseFragment;
import com.ikea.kompis.stores.event.StoreInfoSelectedEvent;
import com.ikea.kompis.stores.event.StoreMarkerSelectedEvent;
import com.ikea.kompis.stores.event.StoreSelectedEvent;
import com.ikea.kompis.util.UiUtil;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.stores.model.StoreRefList;
import com.ikea.shared.user.event.FavStoreChangeEvent;
import com.ikea.shared.util.L;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import java.util.List;

public class IKEAStoresFragment extends BaseFragment
{
  protected TextView mErrorMessage;
  private EventHandler mEventHandler;
  private StoreRef mFavStore;
  protected ProgressBar mProgressBar;
  private int mSelectedIndex = -1;
  private View mStatusInfoLayout;
  private ListView mStoreList;
  private StoreListAdapter mStoreListAdapter;
  protected List<StoreRef> mStoreRef;
  private Object obj = new Object();

  private void hideErrorMessage()
  {
    if ((this.mErrorMessage != null) && (this.mErrorMessage.getVisibility() == 0))
      this.mErrorMessage.setVisibility(8);
    if (this.mStatusInfoLayout != null)
      this.mStatusInfoLayout.setVisibility(8);
  }

  private void refreshUI(List<StoreRef> paramList)
  {
    if (getActivity() != null)
    {
      hideProgressBar(this.mStoreList);
      hideErrorMessage();
      if (this.mStoreList != null)
        synchronized (this.obj)
        {
          if (this.mStoreListAdapter == null)
          {
            this.mStoreList.setChoiceMode(1);
            this.mStoreListAdapter = new StoreListAdapter(this.mParent, paramList, this.mFavStore, this.mSelectedIndex);
            this.mStoreList.setAdapter(this.mStoreListAdapter);
          }
          return;
        }
    }
  }

  protected void hideProgressBar(View paramView)
  {
    if (this.mStatusInfoLayout != null)
      this.mStatusInfoLayout.setVisibility(8);
    if (this.mProgressBar != null)
      this.mProgressBar.setVisibility(8);
    if (paramView != null)
      paramView.setVisibility(0);
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView = paramLayoutInflater.inflate(2130903157, paramViewGroup, false);
    TextView localTextView = (TextView)localView.findViewById(2131624476);
    if (UiUtil.isTablet(getActivity()))
    {
      localTextView.setVisibility(0);
      localTextView.setText(getActivity().getResources().getString(2131165473));
    }
    while (true)
    {
      this.mEventHandler = new EventHandler(null);
      this.mStoreList = ((ListView)localView.findViewById(2131624477));
      this.mProgressBar = ((ProgressBar)localView.findViewById(2131624004));
      this.mErrorMessage = ((TextView)localView.findViewById(2131624003));
      this.mStatusInfoLayout = localView.findViewById(2131624478);
      this.mStoreList.setOnItemClickListener(new AdapterView.OnItemClickListener()
      {
        public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
        {
          if ((paramAnonymousInt >= 0) && (paramAnonymousInt < IKEAStoresFragment.this.mStoreList.getCount()))
            IKEAStoresFragment.this.mBus.post(new StoreSelectedEvent(IKEAStoresFragment.this.mStoreListAdapter.getItem(paramAnonymousInt)));
        }
      });
      showProgressBar(this.mStoreList);
      return localView;
      localTextView.setVisibility(8);
    }
  }

  public void onPause()
  {
    super.onPause();
    try
    {
      this.mBus.unregister(this.mEventHandler);
      return;
    }
    catch (Exception localException)
    {
      L.W("No event handler to unregister");
    }
  }

  public void onResume()
  {
    this.mBus.register(this.mEventHandler);
    super.onResume();
    if ((getActivity() != null) && (this.mStoreRef != null))
      refreshUI(this.mStoreRef);
  }

  public void setData(StoreRefList paramStoreRefList, StoreRef paramStoreRef)
  {
    this.mStoreRef = paramStoreRefList.getStoreRef();
    this.mFavStore = paramStoreRef;
    if ((getActivity() != null) && (this.mStoreRef != null))
      refreshUI(this.mStoreRef);
  }

  protected void showErrorMessage(String paramString)
  {
    if (this.mStatusInfoLayout != null)
      this.mStatusInfoLayout.setVisibility(0);
    if (this.mProgressBar != null)
      this.mProgressBar.setVisibility(8);
    if (this.mErrorMessage != null)
    {
      this.mErrorMessage.setText(paramString);
      this.mErrorMessage.setVisibility(0);
    }
  }

  protected void showProgressBar(View paramView)
  {
    if (this.mStatusInfoLayout != null)
      this.mStatusInfoLayout.setVisibility(0);
    if (this.mProgressBar != null)
      this.mProgressBar.setVisibility(0);
    if (paramView != null)
      paramView.setVisibility(8);
  }

  private class EventHandler
  {
    private EventHandler()
    {
    }

    @Subscribe
    public void handleFavStoreChanged(FavStoreChangeEvent paramFavStoreChangeEvent)
    {
      if (IKEAStoresFragment.this.getActivity() != null)
      {
        IKEAStoresFragment.access$402(IKEAStoresFragment.this, paramFavStoreChangeEvent.favStore);
        if (IKEAStoresFragment.this.mStoreRef != null)
          IKEAStoresFragment.this.refreshUI(IKEAStoresFragment.this.mStoreRef);
      }
    }

    @Subscribe
    public void storeMarkerSelected(StoreInfoSelectedEvent paramStoreInfoSelectedEvent)
    {
      if (IKEAStoresFragment.this.mStoreListAdapter != null)
      {
        StoreRef localStoreRef = paramStoreInfoSelectedEvent.store;
        if ((localStoreRef != null) && (IKEAStoresFragment.this.mStoreRef != null))
        {
          IKEAStoresFragment.access$602(IKEAStoresFragment.this, IKEAStoresFragment.this.mStoreListAdapter.getStoreIndex(localStoreRef));
          IKEAStoresFragment.this.mStoreListAdapter.setSelectedIndex(IKEAStoresFragment.this.mSelectedIndex);
          IKEAStoresFragment.this.mStoreList.setItemChecked(IKEAStoresFragment.this.mSelectedIndex, true);
        }
      }
    }

    @Subscribe
    public void storeMarkerSelected(StoreMarkerSelectedEvent paramStoreMarkerSelectedEvent)
    {
      if (IKEAStoresFragment.this.mStoreListAdapter != null)
      {
        StoreRef localStoreRef = paramStoreMarkerSelectedEvent.store;
        if ((localStoreRef != null) && (IKEAStoresFragment.this.mStoreRef != null))
        {
          IKEAStoresFragment.access$602(IKEAStoresFragment.this, IKEAStoresFragment.this.mStoreListAdapter.getStoreIndex(localStoreRef));
          IKEAStoresFragment.this.mStoreListAdapter.setSelectedIndex(IKEAStoresFragment.this.mSelectedIndex);
          IKEAStoresFragment.this.mStoreList.setItemChecked(IKEAStoresFragment.this.mSelectedIndex, true);
        }
      }
    }
  }
}

/* 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.IKEAStoresFragment
 * JD-Core Version:    0.6.2
 */