package com.ikea.shared;

import android.content.Context;
import com.ikea.shared.browse.model.CatalogListBaseResponse;
import com.ikea.shared.util.AppExecutors;
import com.ikea.shared.util.DataPersister;
import com.ikea.shared.util.L;
import com.ikea.shared.util.LocationUtil;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;

public final class AppCache
{
  private static final String FOLDER_NAME = "appCache";
  private static AppCache INSTANCE;
  private AppCacheInfo mAppCacheInfo;
  private final Context mCtx;
  private final DataPersister<AppCacheInfo> mDataPersister;
  private final ExecutorService mExecutorService = AppExecutors.highPrio();

  private AppCache(Context paramContext)
  {
    this.mCtx = paramContext;
    this.mDataPersister = new DataPersister(paramContext, "appCache", AppCacheInfo.class, null);
    try
    {
      List localList = this.mDataPersister.load();
      if ((localList != null) && (!localList.isEmpty()))
        this.mAppCacheInfo = ((AppCacheInfo)localList.get(0));
      return;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
    }
  }

  public static final AppCache i(Context paramContext)
  {
    try
    {
      if (INSTANCE == null)
        INSTANCE = new AppCache(paramContext);
      AppCache localAppCache = INSTANCE;
      return localAppCache;
    }
    finally
    {
    }
  }

  private boolean isValidCache(CatalogListBaseResponse paramCatalogListBaseResponse)
  {
    if ((paramCatalogListBaseResponse != null) && (paramCatalogListBaseResponse.getCatalogList() != null) && (!paramCatalogListBaseResponse.getCatalogList().isEmpty()))
    {
      String str1 = LocationUtil.getRetailCode(this.mCtx);
      String str2 = LocationUtil.getLanguageCode(this.mCtx);
      if ((str1.equals(paramCatalogListBaseResponse.getCountryCode())) && (str2.equals(paramCatalogListBaseResponse.getLanguageCode())) && (System.currentTimeMillis() - paramCatalogListBaseResponse.getLastUpdatedTime() < 604800000L))
        return true;
    }
    return false;
  }

  public AppCacheInfo getAppChaceInfo()
  {
    if (this.mAppCacheInfo == null)
      this.mAppCacheInfo = new AppCacheInfo();
    return this.mAppCacheInfo;
  }

  public CatalogListBaseResponse getCatalogListBaseResponse()
  {
    if ((this.mAppCacheInfo != null) && (isValidCache(this.mAppCacheInfo.getCatalogListBaseResponse())))
      return this.mAppCacheInfo.getCatalogListBaseResponse();
    resetAppChace();
    return null;
  }

  public int getLastUsedImageId()
  {
    if (this.mAppCacheInfo != null)
      return this.mAppCacheInfo.getLastUsedImageID();
    return 0;
  }

  public void resetAppChace()
  {
    this.mAppCacheInfo = null;
    this.mDataPersister.reset();
  }

  public void updateLastUsedImageId(final int paramInt)
    throws IOException
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        try
        {
          if (AppCache.this.mAppCacheInfo == null)
            AppCache.access$002(AppCache.this, new AppCacheInfo());
          AppCache.this.mAppCacheInfo.setLastUsedImageID(paramInt);
          AppCache.this.mDataPersister.reset();
          AppCache.this.mDataPersister.save(AppCache.this.mAppCacheInfo);
          return;
        }
        catch (IOException localIOException)
        {
          L.E(this, "exception saving ", localIOException);
        }
      }
    });
  }

  public void updateTopCatalogInfo(CatalogListBaseResponse paramCatalogListBaseResponse)
    throws IOException
  {
    try
    {
      if (this.mAppCacheInfo == null)
        this.mAppCacheInfo = new AppCacheInfo();
      this.mAppCacheInfo.setCatalogListBaseResponse(paramCatalogListBaseResponse);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppCacheInfo);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.AppCache
 * JD-Core Version:    0.6.2
 */