package com.ikea.shared.geofence;

import android.app.PendingIntent;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
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.GeofencingApi;
import com.google.android.gms.location.LocationServices;
import com.ikea.shared.util.ServiceCallback;
import java.util.List;

public class GeofenceRemover
  implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener
{
  private GoogleApiClient googleApiClient;
  private ServiceCallback<Integer> mCallback;
  private final Context mContext;
  private List<String> mCurrentGeofenceIds;
  private PendingIntent mCurrentIntent;
  private boolean mInProgress;
  private GeofenceUtils.REMOVE_TYPE mRequestType;

  public GeofenceRemover(Context paramContext)
  {
    this.mContext = paramContext;
    this.mCurrentGeofenceIds = null;
    this.googleApiClient = null;
    this.mInProgress = false;
  }

  private void continueRemoveGeofences()
  {
    switch (1.$SwitchMap$com$ikea$shared$geofence$GeofenceUtils$REMOVE_TYPE[this.mRequestType.ordinal()])
    {
    default:
    case 1:
    case 2:
    }
    do
    {
      do
        return;
      while (this.googleApiClient == null);
      LocationServices.GeofencingApi.removeGeofences(this.googleApiClient, this.mCurrentIntent);
      return;
    }
    while (this.googleApiClient == null);
    LocationServices.GeofencingApi.removeGeofences(this.googleApiClient, this.mCurrentGeofenceIds);
  }

  private GoogleApiClient getLocationClient()
  {
    if (this.googleApiClient == null)
      this.googleApiClient = new GoogleApiClient.Builder(this.mContext).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    return this.googleApiClient;
  }

  private void requestConnection()
  {
    getLocationClient().connect();
  }

  private void requestDisconnection()
  {
    this.mInProgress = false;
    getLocationClient().disconnect();
    if (this.mRequestType == GeofenceUtils.REMOVE_TYPE.INTENT)
      this.mCurrentIntent.cancel();
  }

  public boolean getInProgressFlag()
  {
    return this.mInProgress;
  }

  public void onConnected(Bundle paramBundle)
  {
    Log.d("Geofence Detection", "Client connected");
    continueRemoveGeofences();
  }

  public void onConnectionFailed(ConnectionResult paramConnectionResult)
  {
    this.mInProgress = false;
    if (this.mCallback != null)
    {
      this.mCallback.callbackDone(Integer.valueOf(-1), null, null);
      this.mCallback = null;
    }
  }

  public void onConnectionSuspended(int paramInt)
  {
    this.mInProgress = false;
    Log.d("Geofence Detection", "Client disconnected");
    if (this.mCallback != null)
    {
      this.mCallback.callbackDone(Integer.valueOf(-1), null, null);
      this.mCallback = null;
    }
    this.googleApiClient = null;
  }

  public void removeGeofencesById(List<String> paramList, ServiceCallback<Integer> paramServiceCallback)
  {
    if ((paramList == null) || (paramList.isEmpty()))
    {
      this.mCallback = paramServiceCallback;
      if (this.mCallback != null)
      {
        this.mCallback.callbackDone(Integer.valueOf(-1), null, null);
        this.mCallback = null;
      }
    }
    do
    {
      return;
      if (!this.mInProgress)
      {
        this.mRequestType = GeofenceUtils.REMOVE_TYPE.LIST;
        this.mCurrentGeofenceIds = paramList;
        this.mCallback = paramServiceCallback;
        requestConnection();
        return;
      }
    }
    while (this.mCallback == null);
    this.mCallback.callbackDone(Integer.valueOf(-1), null, null);
    this.mCallback = null;
  }

  public void removeGeofencesByIntent(PendingIntent paramPendingIntent)
  {
    if (!this.mInProgress)
    {
      this.mRequestType = GeofenceUtils.REMOVE_TYPE.INTENT;
      this.mCurrentIntent = paramPendingIntent;
      requestConnection();
    }
    while (this.mCallback == null)
      return;
    this.mCallback.callbackDone(Integer.valueOf(-1), null, null);
    this.mCallback = null;
  }

  public void setInProgressFlag(boolean paramBoolean)
  {
    this.mInProgress = paramBoolean;
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.geofence.GeofenceRemover
 * JD-Core Version:    0.6.2
 */