package com.ikea.kompis.user;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.ikea.kompis.IkeaApplication;
import com.ikea.kompis.user.event.AccountUpdatedEvent;
import com.ikea.kompis.user.event.PerformLoginEvent;
import com.ikea.kompis.user.event.ShowIkeaViewFamilyEvent;
import com.ikea.kompis.util.UiUtil;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.cart.ShoppingCart;
import com.ikea.shared.user.model.User;
import com.ikea.shared.user.service.UserService;
import com.ikea.shared.util.Constant;
import com.ikea.shared.util.ZxingBarcodeManager;
import com.squareup.otto.Bus;
import java.io.IOException;

public class IkeaFamilyFragment extends Fragment
{
  private static final String KEY_FAMILY_CONTENT = "KEY_FAMILY_CONTENT";
  protected final Bus mBus = IkeaApplication.mBus;
  private View mIkeaEditBox;
  private EditText mIkeaNumber;
  private boolean mLaunchedFromTray = false;
  private boolean mNumberLocallyStored = false;
  private Button mOk;
  private final View.OnClickListener mOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      switch (paramAnonymousView.getId())
      {
      default:
        return;
      case 2131624156:
        String str = IkeaFamilyFragment.this.mIkeaNumber.getText().toString().trim().replaceAll("\\s", "");
        Constant.i().setProductModified(true);
        Constant.i().setFamilyNumberChanged(true);
        try
        {
          UserService.i(IkeaFamilyFragment.this.getActivity()).saveLocalIkeaFamilyNumber(str);
          UsageTracker localUsageTracker = UsageTracker.i();
          FragmentActivity localFragmentActivity = IkeaFamilyFragment.this.getActivity();
          boolean bool1 = IkeaFamilyFragment.this.mLaunchedFromTray;
          if (!IkeaFamilyFragment.this.mLaunchedFromTray)
          {
            bool2 = true;
            localUsageTracker.familyCardManuallyEntered(localFragmentActivity, str, bool1, false, bool2);
            ShoppingCart.i(IkeaFamilyFragment.this.getActivity()).updateReceipt(true);
            if (!IkeaFamilyFragment.this.mLaunchedFromTray)
              break label219;
            IkeaFamilyFragment.this.mBus.post(new ShowIkeaViewFamilyEvent(true, true));
            UiUtil.closeSoftKeyBoard(IkeaFamilyFragment.this.mIkeaEditBox);
            IkeaFamilyFragment.this.mBus.post(new AccountUpdatedEvent());
          }
        }
        catch (IOException localIOException)
        {
          while (true)
          {
            localIOException.printStackTrace();
            continue;
            boolean bool2 = false;
            continue;
            label219: IkeaFamilyFragment.this.mBus.post(new ShowIkeaViewFamilyEvent(false, true));
          }
        }
      case 2131623986:
      }
      if ((!IkeaFamilyFragment.this.mUserLoggedIn) && (!IkeaFamilyFragment.this.mNumberLocallyStored) && (IkeaFamilyFragment.this.mSupprotFullCared))
      {
        IkeaFamilyFragment.this.mBus.post(new PerformLoginEvent(false, true));
        return;
      }
      UiUtil.handleSignUpForIkeaFamily(IkeaFamilyFragment.this.getActivity());
    }
  };
  private boolean mSupprotFullCared = false;
  private final TextWatcher mTextWatcher = new TextWatcher()
  {
    public void afterTextChanged(Editable paramAnonymousEditable)
    {
      IkeaFamilyFragment.this.mOk.setEnabled(ZxingBarcodeManager.isFamilyCardNumber(paramAnonymousEditable.toString().trim()));
      if (paramAnonymousEditable.toString().length() > 0)
      {
        IkeaFamilyFragment.this.mIkeaEditBox.setBackgroundResource(2130837605);
        return;
      }
      IkeaFamilyFragment.this.mIkeaEditBox.setBackgroundResource(2130837606);
    }

    public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
    }

    public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
    {
      if ((paramAnonymousInt2 == 0) && ((paramAnonymousInt1 == 5) || (paramAnonymousInt1 == 10) || (paramAnonymousInt1 == 15) || (paramAnonymousInt1 == 20)));
      try
      {
        String str = paramAnonymousCharSequence + " ";
        IkeaFamilyFragment.this.mIkeaNumber.setText(str);
        IkeaFamilyFragment.this.mIkeaNumber.setSelection(paramAnonymousInt1 + 2);
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }
  };
  private boolean mUserLoggedIn = false;

  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);
    User localUser = UserService.i(getActivity()).getUser();
    if ((localUser != null) && (localUser.isLoggedIn()));
    for (boolean bool = true; ; bool = false)
    {
      this.mUserLoggedIn = bool;
      if ((AppConfigManager.i(getActivity()) != null) && (AppConfigManager.i(getActivity()).getAppConfigData() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().isMemberFull()))
        this.mSupprotFullCared = true;
      if ((localUser != null) && (localUser.getLocalIkeaFamilyNumber() != null) && (!localUser.getLocalIkeaFamilyNumber().isEmpty()))
        this.mNumberLocallyStored = true;
      return;
    }
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView = paramLayoutInflater.inflate(2130903092, paramViewGroup, false);
    this.mIkeaNumber = ((EditText)localView.findViewById(2131624155));
    this.mIkeaEditBox = localView.findViewById(2131624154);
    this.mOk = ((Button)localView.findViewById(2131624156));
    TextView localTextView1 = (TextView)localView.findViewById(2131624157);
    TextView localTextView2 = (TextView)localView.findViewById(2131623988);
    Button localButton = (Button)localView.findViewById(2131623986);
    this.mIkeaNumber.addTextChangedListener(this.mTextWatcher);
    this.mOk.setOnClickListener(this.mOnClickListener);
    localButton.setOnClickListener(this.mOnClickListener);
    this.mIkeaNumber.setInputType(32770);
    if ((AppConfigManager.i(getActivity()) != null) && (AppConfigManager.i(getActivity()).getAppConfigData() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().isMemberLight()))
      localTextView2.setText(getResources().getString(2131165392));
    if ((paramBundle != null) && (paramBundle.containsKey("KEY_FAMILY_CONTENT")))
      this.mIkeaNumber.setText(paramBundle.getString("KEY_FAMILY_CONTENT"));
    if ((!this.mUserLoggedIn) && (!this.mNumberLocallyStored) && (this.mSupprotFullCared))
    {
      localTextView1.setVisibility(8);
      localButton.setText(getResources().getString(2131165620));
    }
    return localView;
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    if ((this.mIkeaNumber != null) && (this.mIkeaNumber.getText() != null))
      paramBundle.putString("KEY_FAMILY_CONTENT", this.mIkeaNumber.getText().toString());
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.user.IkeaFamilyFragment
 * JD-Core Version:    0.6.2
 */