package com.ikea.shared.store.service;

import android.content.Context;
import com.ikea.shared.AppError;
import com.ikea.shared.notification.NotificationService;
import com.ikea.shared.stores.model.StoreList;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.stores.model.StoreRefList;
import com.ikea.shared.util.DataPersister;
import com.ikea.shared.util.L;
import com.ikea.shared.util.LocationUtil;
import com.ikea.shared.util.Persistable;
import com.ikea.shared.util.ServiceCallback;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

public final class StoreCache
{
  private static final String FOLDER_NAME = "storeCache";
  private static final String FOLDER_NAME_STORE = "storeCacheLists";
  private static StoreCache INSTANCE;
  private final Context mCtx;
  private final DataPersister<StoreCacheInfo> mDataPersister;
  private final DataPersister<StoreRef> mDataPersister2;
  private final ServiceCallback<StoreList> mServiceCallback = new ServiceCallback()
  {
    public void done(StoreList paramAnonymousStoreList, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
    }
  };
  private StoreCacheInfo mStoreChaceInfo;
  private List<StoreRef> mStoreRef;

  private StoreCache(Context paramContext)
  {
    this.mCtx = paramContext;
    this.mDataPersister = new DataPersister(paramContext, "storeCache", StoreCacheInfo.class, null);
    this.mDataPersister2 = new DataPersister(paramContext, "storeCacheLists", StoreRef.class, null);
    try
    {
      List localList1 = this.mDataPersister2.load();
      if ((localList1 != null) && (!localList1.isEmpty()))
        this.mStoreRef = localList1;
      List localList2 = this.mDataPersister.load();
      if ((localList2 != null) && (!localList2.isEmpty()))
        this.mStoreChaceInfo = ((StoreCacheInfo)localList2.get(0));
      if ((this.mStoreRef != null) && (this.mStoreChaceInfo != null))
      {
        StoreRefList localStoreRefList = new StoreRefList();
        localStoreRefList.setStoreRef(this.mStoreRef);
        StoreList localStoreList = new StoreList();
        localStoreList.setStoreRefList(localStoreRefList);
        this.mStoreChaceInfo.setStoreList(localStoreList);
      }
      return;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
      return;
    }
    catch (Throwable localThrowable)
    {
      localThrowable.printStackTrace();
    }
  }

  public static StoreCache i(Context paramContext)
  {
    try
    {
      if (INSTANCE == null)
        INSTANCE = new StoreCache(paramContext);
      StoreCache localStoreCache = INSTANCE;
      return localStoreCache;
    }
    finally
    {
    }
  }

  private boolean isValidCache()
  {
    String str1 = LocationUtil.getRetailCode(this.mCtx);
    String str2 = LocationUtil.getLanguageCode(this.mCtx);
    return (str1.equals(this.mStoreChaceInfo.getCountryCode())) && (str2.equals(this.mStoreChaceInfo.getLangCode())) && (System.currentTimeMillis() - this.mStoreChaceInfo.getLastUpdatedTime() < 7200000L);
  }

  private boolean isValidCacheWithRefresh()
  {
    String str1 = LocationUtil.getRetailCode(this.mCtx);
    String str2 = LocationUtil.getLanguageCode(this.mCtx);
    if ((str1.equals(this.mStoreChaceInfo.getCountryCode())) && (str2.equals(this.mStoreChaceInfo.getLangCode())))
    {
      if (System.currentTimeMillis() - this.mStoreChaceInfo.getLastUpdatedTime() < 7200000L)
        return true;
      StoreService.i(this.mCtx).getStoresAsync(this.mServiceCallback);
      return true;
    }
    return false;
  }

  public StoreList getCachedStoreList()
  {
    if ((this.mStoreChaceInfo != null) && (isValidCache()))
      return this.mStoreChaceInfo.getStoreList();
    return null;
  }

  public List<String> getGetGeofencesAddedList()
  {
    if (this.mStoreChaceInfo != null)
      return this.mStoreChaceInfo.getGeofenceIdsAdded();
    return null;
  }

  public StoreCacheInfo getStoreCacheInfo()
  {
    if (this.mStoreChaceInfo == null)
      this.mStoreChaceInfo = new StoreCacheInfo();
    return this.mStoreChaceInfo;
  }

  public StoreList getStoreList()
  {
    if ((this.mStoreChaceInfo != null) && (isValidCacheWithRefresh()))
      return this.mStoreChaceInfo.getStoreList();
    return null;
  }

  public boolean isInStore()
  {
    if (this.mStoreChaceInfo != null)
      return this.mStoreChaceInfo.isInStore();
    return false;
  }

  public void resetAppChace()
  {
    this.mStoreChaceInfo = null;
    this.mDataPersister.reset();
  }

  public void updateGeofencesList(List<String> paramList)
    throws IOException
  {
    try
    {
      if (this.mStoreChaceInfo == null)
        this.mStoreChaceInfo = new StoreCacheInfo();
      this.mStoreChaceInfo.setGeofenceIdsAdded(paramList);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mStoreChaceInfo);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateInStoreStatus(boolean paramBoolean, String paramString)
    throws IOException
  {
    try
    {
      if (this.mStoreChaceInfo == null)
        this.mStoreChaceInfo = new StoreCacheInfo();
      boolean bool = this.mStoreChaceInfo.isInStore();
      if ((paramBoolean) && (!bool))
      {
        NotificationService.i(this.mCtx).setISNotificationDismissed(false);
        NotificationService.i(this.mCtx).setASNotificationDismissed(false);
      }
      this.mStoreChaceInfo.setInStore(paramBoolean);
      this.mStoreChaceInfo.setGeofenceStoreId(paramString);
      if (paramBoolean)
        this.mStoreChaceInfo.updateStoresDistance();
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mStoreChaceInfo);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateStoreList(StoreList paramStoreList, long paramLong, String paramString1, String paramString2)
    throws IOException
  {
    try
    {
      if (this.mStoreChaceInfo == null)
        this.mStoreChaceInfo = new StoreCacheInfo();
      List localList = null;
      if (paramStoreList != null)
      {
        StoreRefList localStoreRefList = paramStoreList.getStoreRefList();
        localList = null;
        if (localStoreRefList != null)
          localList = paramStoreList.getStoreRefList().getStoreRef();
      }
      this.mDataPersister2.reset();
      if ((localList != null) && (!localList.isEmpty()))
        for (int i = 0; i < localList.size(); i++)
          this.mDataPersister2.save((Persistable)localList.get(i));
      this.mStoreChaceInfo.setLastUpdatedTime(paramLong);
      this.mStoreChaceInfo.setCountryCode(paramString1);
      this.mStoreChaceInfo.setLangCode(paramString2);
      this.mStoreChaceInfo.setStoreList(paramStoreList);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mStoreChaceInfo);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
    catch (Throwable localThrowable)
    {
      localThrowable.printStackTrace();
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.store.service.StoreCache
 * JD-Core Version:    0.6.2
 */