package com.ikea.shared;

import android.content.Context;
import android.text.TextUtils;
import com.ikea.shared.config.model.Country;
import com.ikea.shared.config.model.KillSwitchConfig;
import com.ikea.shared.config.model.Region;
import com.ikea.shared.notification.NotificationService;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.util.AppExecutors;
import com.ikea.shared.util.DataPersister;
import com.ikea.shared.util.L;
import com.ikea.shared.util.ServiceCallback;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;

public final class AppConfigManager
{
  private static final String FOLDER_NAME = "appConfig";
  private static AppConfigManager INSTANCE;
  private AppConfigData mAppConfigData;
  private final DataPersister<AppConfigData> mDataPersister;
  private final ExecutorService mExecutorService = AppExecutors.highPrio();
  private final Context mctx;

  private AppConfigManager(Context paramContext)
  {
    this.mctx = paramContext;
    this.mDataPersister = new DataPersister(paramContext, "appConfig", AppConfigData.class, null);
    try
    {
      List localList = this.mDataPersister.load();
      if ((localList != null) && (!localList.isEmpty()))
        this.mAppConfigData = ((AppConfigData)localList.get(0));
      return;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
    }
  }

  public static final AppConfigManager i(Context paramContext)
  {
    try
    {
      if (INSTANCE == null)
        INSTANCE = new AppConfigManager(paramContext);
      AppConfigManager localAppConfigManager = INSTANCE;
      return localAppConfigManager;
    }
    finally
    {
    }
  }

  public void fetchFavotireStore(final ServiceCallback<StoreRef> paramServiceCallback)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        if (AppConfigManager.this.mAppConfigData != null)
        {
          paramServiceCallback.callbackDone(AppConfigManager.this.mAppConfigData.getFavStore(), null, null);
          return;
        }
        paramServiceCallback.callbackDone(null, null, null);
      }
    });
  }

  public AppConfigData getAppConfigData()
  {
    if (this.mAppConfigData == null)
      this.mAppConfigData = new AppConfigData();
    return this.mAppConfigData;
  }

  public void resetAppConfigData()
  {
    this.mAppConfigData = null;
    this.mDataPersister.reset();
  }

  public void resetKillSwitchConfig()
    throws IOException
  {
    try
    {
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      this.mAppConfigData.setKillSwithConfig(null);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void saveFavStore(StoreRef paramStoreRef)
    throws IOException
  {
    try
    {
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      StoreRef localStoreRef = this.mAppConfigData.getFavStore();
      this.mAppConfigData.setFavStore(paramStoreRef);
      if ((localStoreRef == null) || (paramStoreRef == null) || ((localStoreRef == null) && (paramStoreRef != null) && (!localStoreRef.getStoreNo().equalsIgnoreCase(paramStoreRef.getStoreNo()))))
      {
        NotificationService.i(this.mctx).setCSNotificationDismissed(false);
        NotificationService.i(this.mctx).setASNotificationDismissed(false);
      }
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void saveKillSwitchConfig(KillSwitchConfig paramKillSwitchConfig)
    throws IOException
  {
    try
    {
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      this.mAppConfigData.setKillSwithConfig(paramKillSwitchConfig);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateFirstTimeExp(boolean paramBoolean)
    throws IOException
  {
    try
    {
      if ((this.mAppConfigData != null) && (this.mAppConfigData.isFirstTimeUser() == paramBoolean))
        return;
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      this.mAppConfigData.setFirstTimeUser(paramBoolean);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateSelcetedCountry(String paramString1, String paramString2, Country paramCountry)
    throws IOException
  {
    if ((paramCountry != null) && (!TextUtils.isEmpty(paramString1)) && (!TextUtils.isEmpty(paramString2)));
    try
    {
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      this.mAppConfigData.setCountryName(paramString1);
      this.mAppConfigData.setCountryCode(paramString2);
      this.mAppConfigData.setConfig(paramCountry);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateSelcetedLanguage(String paramString1, String paramString2)
    throws IOException
  {
    if ((!TextUtils.isEmpty(paramString1)) && (!TextUtils.isEmpty(paramString2)));
    try
    {
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      this.mAppConfigData.setLanguageName(paramString1);
      this.mAppConfigData.setLanguageCode(paramString2);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateSelcetedRegion(String paramString1, String paramString2, Region paramRegion)
    throws IOException
  {
    try
    {
      if (this.mAppConfigData == null)
        this.mAppConfigData = new AppConfigData();
      this.mAppConfigData.setRegionName(paramString1);
      this.mAppConfigData.setRegionCode(paramString2);
      this.mAppConfigData.setRegion(paramRegion);
      if (this.mAppConfigData.getConfig() != null)
        this.mAppConfigData.getConfig().setSectedRegion(paramRegion);
      this.mDataPersister.reset();
      this.mDataPersister.save(this.mAppConfigData);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception saving ", localIOException);
      throw localIOException;
    }
  }

  public void updateSelectedConfig(Country paramCountry, Region paramRegion, String paramString1, String paramString2)
    throws IOException
  {
    if ((paramCountry != null) && (!TextUtils.isEmpty(paramString1)) && (!TextUtils.isEmpty(paramString2)))
      try
      {
        if (this.mAppConfigData == null)
          this.mAppConfigData = new AppConfigData();
        this.mAppConfigData.setCountryName(paramCountry.getCountryName());
        this.mAppConfigData.setCountryCode(paramCountry.getCountrycode());
        this.mAppConfigData.setConfig(paramCountry);
        if (paramRegion != null)
        {
          this.mAppConfigData.setRegionName(paramRegion.getName());
          this.mAppConfigData.setRegionCode(paramRegion.getValue());
          this.mAppConfigData.setRegion(paramRegion);
        }
        while (true)
        {
          this.mAppConfigData.setLanguageName(paramString1);
          this.mAppConfigData.setLanguageCode(paramString2);
          this.mDataPersister.reset();
          this.mDataPersister.save(this.mAppConfigData);
          return;
          this.mAppConfigData.setRegionName("");
          this.mAppConfigData.setRegionCode("");
          this.mAppConfigData.setRegion(paramRegion);
        }
      }
      catch (IOException localIOException)
      {
        L.E(this, "exception saving ", 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.AppConfigManager
 * JD-Core Version:    0.6.2
 */