package com.ikea.kompis.fte;

import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.Builder;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.FusedLocationProviderApi;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.ikea.kompis.BaseCustomFontActivity;
import com.ikea.kompis.IkeaApplication;
import com.ikea.kompis.WelcomeActivity;
import com.ikea.kompis.stores.event.LocationUpdateEvent;
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.config.model.Country;
import com.ikea.shared.util.L;
import com.squareup.otto.Bus;

public class FirstUserExperienceActivity extends BaseCustomFontActivity
  implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener
{
  private static final int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
  public static final String FIRST_USER_EXPERIENCE = "FIRST_USER_EXPERIENCE";
  protected static final String KEY_CURRENT_LOCATION = "KEY_CURRENT_LOCATION";
  private static final long MIN_TIME_BW_UPDATES = 1000L;
  public static final int OPEN_STORE_REQUEST_CODE = 1;
  private final Bus mBus = IkeaApplication.mBus;
  public boolean mCameFromStore = false;
  private String mCurrentCountry;
  protected Location mCurrentLocation;
  protected FirstUserExperienceFragment mFirstUserExperienceFragment;
  private GoogleApiClient mGoogleApiClient;
  protected final Handler mHandler = new Handler();
  private Runnable mLocationNotFoundRunnable;
  private LocationRequest mLocationRequest;

  public String getCurrentCountry()
  {
    return this.mCurrentCountry;
  }

  public Location getCurrentLocation()
  {
    return this.mCurrentLocation;
  }

  protected Intent getWelcomeIntent()
  {
    return new Intent(this, WelcomeActivity.class);
  }

  public void goBack()
  {
    if (!this.mFirstUserExperienceFragment.returnBackStackImmediate(getSupportFragmentManager()))
    {
      finish();
      overridePendingTransition(2130968583, 2130968582);
    }
  }

  public void moveToWelcome()
  {
    Intent localIntent = getWelcomeIntent();
    if ((getIntent() != null) && (getIntent().getExtras() != null))
    {
      Uri localUri = (Uri)getIntent().getExtras().getParcelable("LaunchedFromCatalogue");
      if (localUri != null)
      {
        localIntent.putExtra("returnFromLogin", localUri);
        localIntent.setAction("android.intent.action.VIEW");
        localIntent.addFlags(4);
      }
    }
    startActivity(localIntent);
    finish();
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if ((paramInt1 == 1) && (paramInt2 == -1))
    {
      if ((AppConfigManager.i(this).getAppConfigData() == null) || (AppConfigManager.i(this).getAppConfigData().getConfig() == null) || (AppConfigManager.i(this).getAppConfigData().getConfig().ismLoginEnabled()))
        break label76;
      moveToWelcome();
    }
    while (true)
    {
      if ((paramInt1 == 10) && (paramInt2 == -1))
        moveToWelcome();
      return;
      label76: this.mCameFromStore = true;
    }
  }

  public void onBackPressed()
  {
    goBack();
  }

  public void onConnected(Bundle paramBundle)
  {
    this.mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(this.mGoogleApiClient);
    LocationServices.FusedLocationApi.requestLocationUpdates(this.mGoogleApiClient, this.mLocationRequest, this);
    if (this.mCurrentLocation != null)
    {
      if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
        this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
      this.mBus.post(new LocationUpdateEvent(this.mCurrentLocation));
    }
  }

  public void onConnectionFailed(ConnectionResult paramConnectionResult)
  {
    L.I("GoogleApiClient connection has failed");
    if (paramConnectionResult.hasResolution());
    try
    {
      paramConnectionResult.startResolutionForResult(this, 9000);
      return;
    }
    catch (IntentSender.SendIntentException localSendIntentException)
    {
      localSendIntentException.printStackTrace();
    }
  }

  public void onConnectionSuspended(int paramInt)
  {
    L.I("GoogleApiClient connection has been suspend");
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    if (!UiUtil.isTablet(this))
      setRequestedOrientation(1);
    setContentView(2130903042);
    if (paramBundle == null)
    {
      this.mFirstUserExperienceFragment = new FirstUserExperienceFragment();
      if ((getIntent() != null) && (getIntent().getExtras() != null))
      {
        Uri localUri = (Uri)getIntent().getExtras().getParcelable("LaunchedFromCatalogue");
        if (localUri != null)
        {
          Bundle localBundle = new Bundle();
          localBundle.putParcelable("LaunchedFromCatalogue", localUri);
          this.mFirstUserExperienceFragment.setArguments(localBundle);
        }
      }
      FragmentTransaction localFragmentTransaction = getSupportFragmentManager().beginTransaction();
      localFragmentTransaction.replace(2131623964, this.mFirstUserExperienceFragment, "FIRST_USER_EXPERIENCE");
      localFragmentTransaction.commit();
    }
    while (true)
    {
      this.mLocationRequest = LocationRequest.create();
      this.mLocationRequest.setPriority(100);
      this.mLocationRequest.setInterval(1000L);
      this.mLocationRequest.setFastestInterval(1000L);
      this.mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
      return;
      this.mFirstUserExperienceFragment = ((FirstUserExperienceFragment)getSupportFragmentManager().findFragmentByTag("FIRST_USER_EXPERIENCE"));
      if (paramBundle.containsKey("KEY_CURRENT_LOCATION"))
        this.mCurrentLocation = ((Location)paramBundle.getParcelable("KEY_CURRENT_LOCATION"));
    }
  }

  public void onLocationChanged(Location paramLocation)
  {
    if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
      this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
    if (this.mCurrentLocation == null)
    {
      this.mCurrentLocation = paramLocation;
      this.mBus.post(new LocationUpdateEvent(this.mCurrentLocation));
    }
  }

  protected void onPause()
  {
    super.onPause();
    try
    {
      this.mBus.unregister(this);
      return;
    }
    catch (Exception localException)
    {
      L.W("No event handler to unregister");
    }
  }

  protected void onResume()
  {
    super.onResume();
    this.mBus.register(this);
    if ((UiUtil.isPlayServiceAvailable(this)) && ((UiUtil.isGPSOn(this)) || (UiUtil.isNetworkLocationOn(this))))
    {
      this.mGoogleApiClient.connect();
      if (this.mHandler != null)
      {
        this.mLocationNotFoundRunnable = new Runnable()
        {
          public void run()
          {
            FirstUserExperienceActivity.access$002(FirstUserExperienceActivity.this, null);
          }
        };
        this.mHandler.postDelayed(this.mLocationNotFoundRunnable, 30000L);
      }
    }
    if (this.mCameFromStore)
    {
      this.mCameFromStore = false;
      openRegistrationFragment();
    }
  }

  protected void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    paramBundle.putParcelable("KEY_CURRENT_LOCATION", this.mCurrentLocation);
  }

  protected void openRegistrationFragment()
  {
    UsageTracker.i().viewInitiate(this, 3);
    RegistrationFirstTimeFragment localRegistrationFirstTimeFragment = new RegistrationFirstTimeFragment();
    this.mFirstUserExperienceFragment.updateContentFragment(localRegistrationFirstTimeFragment, "REGISTER", false);
  }

  public void setCurrentCountry(String paramString)
  {
    this.mCurrentCountry = paramString;
  }

  public void setCurrentLocation(Location paramLocation)
  {
    this.mCurrentLocation = paramLocation;
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.fte.FirstUserExperienceActivity
 * JD-Core Version:    0.6.2
 */