package com.ikea.kompis.stores;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
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.ShoppingCartActivity;
import com.ikea.kompis.fragments.SecondLevelContentFragment;
import com.ikea.kompis.stores.event.LocationUpdateEvent;
import com.ikea.kompis.util.CustomPopUp;
import com.ikea.kompis.util.CustomPopUp.CustomPopupClickListener;
import com.ikea.kompis.util.UiUtil;
import com.ikea.shared.util.L;
import com.squareup.otto.Bus;

public abstract class StoreBaseFragment extends SecondLevelContentFragment
  implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener
{
  private static final int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
  public static final String FROM_SETTINGS = "FROM_SETTINGS";
  public static final String FROM_SL = "FROM_SL";
  public static final String FROM_WELCOME = "FROM_WELCOME";
  private static final String IS_TIMER_NEEDED = "is_timer_needed";
  private static final long MIN_TIME_BW_UPDATES = 1000L;
  private static final String SHOW_LBS_ERROR_MESSAGE = "SHOW_LBS_ERROR_MESSAGE";
  private static final String SHOW_NO_lBS_ERROR_MESSAGE = "SHOW_NO_lBS_ERROR_MESSAGE";
  private boolean isGPSON = false;
  private boolean isTimerNeeded = true;
  protected Location mCurrentLocation;
  private GoogleApiClient mGoogleApiClient;
  protected boolean mLaunchedFromFirstUserExp = false;
  protected boolean mLaunchedFromSL = false;
  protected boolean mLaunchedFromSetting = false;
  protected boolean mLaunchedFromTray = false;
  protected boolean mLaunchedFromWelcome = false;
  private Runnable mLocationNotFoundRunnable;
  private LocationRequest mLocationRequest;
  private CustomPopUp mShowLBSTurnedOffDialog;
  private CustomPopUp mShowNoLBSServiceDialog;
  private CustomPopUp mShowNoNetworkServiceDialog;
  private boolean showLBSTurnedOffErrorMsg = true;
  private boolean showNoLBSErrorMsg = true;

  public static StoreBaseFragment newInstance(Context paramContext, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4, boolean paramBoolean5)
  {
    StoreFragment localStoreFragment = new StoreFragment();
    Bundle localBundle = new Bundle();
    localBundle.putBoolean("FROM_FIRST_USER_EXPERIENCE", paramBoolean1);
    localBundle.putBoolean("LaunchedFromTray", paramBoolean2);
    localBundle.putBoolean("FROM_SL", paramBoolean4);
    localBundle.putBoolean("FROM_WELCOME", paramBoolean3);
    localBundle.putBoolean("FROM_SETTINGS", paramBoolean5);
    localStoreFragment.setArguments(localBundle);
    return localStoreFragment;
  }

  private void showLBSTurnedOff()
  {
    this.mShowLBSTurnedOffDialog = new CustomPopUp(this.mParent, getString(2131165743), getString(2131165489), getString(2131165431), "", "");
    this.mShowLBSTurnedOffDialog.setCancelable(false);
    this.mShowLBSTurnedOffDialog.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        StoreBaseFragment.this.mShowLBSTurnedOffDialog.dismiss();
        StoreBaseFragment.access$002(StoreBaseFragment.this, false);
        StoreBaseFragment.this.showNoLBSService();
        return true;
      }

      public void onCancel()
      {
        StoreBaseFragment.access$302(StoreBaseFragment.this, null);
      }

      public void onLinkClick()
      {
      }

      public void onPrimaryBtnClick()
      {
        StoreBaseFragment.this.startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
        StoreBaseFragment.this.mParent.overridePendingTransition(2130968587, 2130968584);
      }

      public void onSecondaryBtnClick()
      {
        StoreBaseFragment.access$002(StoreBaseFragment.this, false);
        StoreBaseFragment.this.showNoLBSService();
      }
    });
  }

  private void showNoLBSService()
  {
    this.mShowNoLBSServiceDialog = new CustomPopUp(this.mParent, getString(2131165517), getString(2131165491));
    this.mShowNoLBSServiceDialog.setCancelable(false);
    this.mShowNoLBSServiceDialog.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        StoreBaseFragment.this.mShowNoLBSServiceDialog.dismiss();
        StoreBaseFragment.access$402(StoreBaseFragment.this, false);
        return true;
      }

      public void onCancel()
      {
        StoreBaseFragment.access$502(StoreBaseFragment.this, null);
      }

      public void onLinkClick()
      {
      }

      public void onPrimaryBtnClick()
      {
        StoreBaseFragment.access$402(StoreBaseFragment.this, false);
      }

      public void onSecondaryBtnClick()
      {
      }
    });
  }

  private void showNoLocationFound()
  {
    final CustomPopUp localCustomPopUp = new CustomPopUp(this.mParent, getString(2131165517), getString(2131165440));
    localCustomPopUp.setCancelable(false);
    localCustomPopUp.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        localCustomPopUp.dismiss();
        return true;
      }

      public void onCancel()
      {
      }

      public void onLinkClick()
      {
      }

      public void onPrimaryBtnClick()
      {
      }

      public void onSecondaryBtnClick()
      {
      }
    });
    if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
      this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
  }

  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_FIRST_USER_EXPERIENCE"))
        this.mLaunchedFromFirstUserExp = localBundle.getBoolean("FROM_FIRST_USER_EXPERIENCE");
      if (localBundle.containsKey("FROM_WELCOME"))
        this.mLaunchedFromWelcome = localBundle.getBoolean("FROM_WELCOME");
      if (localBundle.containsKey("FROM_SL"))
        this.mLaunchedFromSL = localBundle.getBoolean("FROM_SL");
      if (localBundle.containsKey("FROM_SETTINGS"))
        this.mLaunchedFromSetting = localBundle.getBoolean("FROM_SETTINGS");
    }
  }

  public void onConnected(Bundle paramBundle)
  {
    this.mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(this.mGoogleApiClient);
    LocationServices.FusedLocationApi.requestLocationUpdates(this.mGoogleApiClient, this.mLocationRequest, this);
    if ((this.mCurrentLocation != null) && (this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
    {
      this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
      this.isTimerNeeded = false;
      this.mHandler.postDelayed(new Runnable()
      {
        public void run()
        {
          StoreBaseFragment.this.mBus.post(new LocationUpdateEvent(StoreBaseFragment.this.mCurrentLocation));
        }
      }
      , 200L);
    }
  }

  public void onConnectionFailed(ConnectionResult paramConnectionResult)
  {
    showNoLocationFound();
    this.isTimerNeeded = false;
    if (paramConnectionResult.hasResolution());
    try
    {
      paramConnectionResult.startResolutionForResult(this.mParent, 9000);
      return;
    }
    catch (IntentSender.SendIntentException localSendIntentException)
    {
      localSendIntentException.printStackTrace();
    }
  }

  public void onConnectionSuspended(int paramInt)
  {
    L.I("GoogleApiClient connection has been suspend");
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mLocationRequest = LocationRequest.create();
    this.mLocationRequest.setPriority(100);
    this.mLocationRequest.setInterval(1000L);
    this.mLocationRequest.setFastestInterval(1000L);
    this.mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    if (paramBundle != null)
    {
      this.isTimerNeeded = paramBundle.getBoolean("is_timer_needed", false);
      this.showLBSTurnedOffErrorMsg = paramBundle.getBoolean("SHOW_LBS_ERROR_MESSAGE", true);
      this.showNoLBSErrorMsg = paramBundle.getBoolean("SHOW_NO_lBS_ERROR_MESSAGE", true);
    }
  }

  public void onLocationChanged(Location paramLocation)
  {
    if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
      this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
    this.isTimerNeeded = false;
    if (this.mCurrentLocation == null)
    {
      this.mCurrentLocation = paramLocation;
      this.mHandler.postDelayed(new Runnable()
      {
        public void run()
        {
          StoreBaseFragment.this.mBus.post(new LocationUpdateEvent(StoreBaseFragment.this.mCurrentLocation));
        }
      }
      , 200L);
    }
    if ((this.mGoogleApiClient.isConnected()) && (this.mCurrentLocation != null))
    {
      LocationServices.FusedLocationApi.removeLocationUpdates(this.mGoogleApiClient, this);
      this.mGoogleApiClient.disconnect();
    }
  }

  public void onPause()
  {
    super.onPause();
    if ((this.mHandler != null) && (this.mLocationNotFoundRunnable != null))
      this.mHandler.removeCallbacks(this.mLocationNotFoundRunnable);
    if (this.mShowLBSTurnedOffDialog != null)
      this.mShowLBSTurnedOffDialog.dismiss();
    if (this.mShowNoLBSServiceDialog != null)
      this.mShowNoLBSServiceDialog.dismiss();
    if (this.mShowNoNetworkServiceDialog != null)
      this.mShowNoNetworkServiceDialog.dismiss();
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    paramBundle.putBoolean("is_timer_needed", this.isTimerNeeded);
    paramBundle.putBoolean("SHOW_LBS_ERROR_MESSAGE", this.showLBSTurnedOffErrorMsg);
    paramBundle.putBoolean("SHOW_NO_lBS_ERROR_MESSAGE", this.showNoLBSErrorMsg);
  }

  public void onStart()
  {
    super.onStart();
    if (UiUtil.isPlayServiceAvailable(this.mParent))
    {
      if ((!UiUtil.isGPSOn(this.mParent)) && (!UiUtil.isNetworkLocationOn(this.mParent)))
        break label90;
      this.mGoogleApiClient.connect();
      this.isGPSON = true;
      if ((this.isTimerNeeded) && (this.mHandler != null))
      {
        this.mLocationNotFoundRunnable = new Runnable()
        {
          public void run()
          {
            StoreBaseFragment.access$902(StoreBaseFragment.this, null);
            StoreBaseFragment.this.showNoLocationFound();
          }
        };
        this.mHandler.postDelayed(this.mLocationNotFoundRunnable, 10000L);
      }
    }
    return;
    label90: if ((this.showLBSTurnedOffErrorMsg) || (this.isGPSON))
      showLBSTurnedOff();
    while (true)
    {
      this.isGPSON = false;
      return;
      if (this.showNoLBSErrorMsg)
        showNoLBSService();
    }
  }

  public void onStop()
  {
    if (this.mGoogleApiClient.isConnected())
      this.mGoogleApiClient.disconnect();
    super.onStop();
  }

  protected void showNoNetowrk()
  {
    this.mShowNoNetworkServiceDialog = new CustomPopUp(this.mParent, getString(2131165517), getString(2131165477));
    this.mShowNoNetworkServiceDialog.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        return false;
      }

      public void onCancel()
      {
        StoreBaseFragment.access$602(StoreBaseFragment.this, null);
      }

      public void onLinkClick()
      {
      }

      public void onPrimaryBtnClick()
      {
      }

      public void onSecondaryBtnClick()
      {
      }
    });
  }
}

/* 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.StoreBaseFragment
 * JD-Core Version:    0.6.2
 */