package com.ikea.shared.cart;

import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.LibConfig;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.cart.model.ShoppingBagItem;
import com.ikea.shared.cart.model.SyncEventModel;
import com.ikea.shared.notification.NotificationService;
import com.ikea.shared.products.model.DisplayPriceInfo;
import com.ikea.shared.products.model.PriceGroup;
import com.ikea.shared.products.model.Quantity;
import com.ikea.shared.products.model.RICComparator;
import com.ikea.shared.products.model.RetailItemCommChild;
import com.ikea.shared.products.model.RetailItemCommChildList;
import com.ikea.shared.products.model.RetailItemCommunication;
import com.ikea.shared.products.model.RetailItemCommunication.SL_ITEM_TYPE;
import com.ikea.shared.products.service.ProductService;
import com.ikea.shared.products.service.ProductService.STOCK_STATUS;
import com.ikea.shared.shopping.event.SLChangedEvent;
import com.ikea.shared.shopping.model.Receipt;
import com.ikea.shared.shopping.service.ShoppingCartService;
import com.ikea.shared.stores.model.RetailItemAvailability;
import com.ikea.shared.stores.model.RetailItemCommChildAvailability;
import com.ikea.shared.stores.model.RetailItemCommChildAvailabilityList;
import com.ikea.shared.stores.model.StockAvailability;
import com.ikea.shared.stores.model.StockAvailabilityResponse;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.user.model.User;
import com.ikea.shared.user.service.UserService;
import com.ikea.shared.util.AppExecutors;
import com.ikea.shared.util.BasePriceUtil;
import com.ikea.shared.util.Constant;
import com.ikea.shared.util.DataPersister;
import com.ikea.shared.util.L;
import com.ikea.shared.util.Persistable;
import com.ikea.shared.util.ServiceCallback;
import com.squareup.otto.Bus;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;

public final class ShoppingCart
{
  public static final String CONTACT_STAFF_DEPARTMENT = "CONTACT STAFF";
  public static final String DDS_SERVICE_CODE = "3";
  private static final String FILE_NAME_META = "slmeta";
  private static final String FILE_NAME_SL_LIST = "sllist";
  public static final String FULL_SERVICE_CODE = "2";
  public static final String ITEM_TYPE_SPR = "SPR";
  public static final String MARKET_HALL_DEPARTMENT = "MARKET HALL";
  public static final String SATELITE_SERVICE_CODE = "0";
  public static final String SELF_SERVICE_CODE = "1";
  public static final String SELF_SERVICE_DEPARTMENT = "Self-Service";
  public static final String SHOWROOM_DEPARTMENT = "SHOWROOM";
  private static ShoppingCart mInstance;
  private final Bus mBus = LibConfig.i().bus();
  private final Context mCtx;
  private final ExecutorService mExecutorService = AppExecutors.highPrio();
  private final Handler mHandler = new Handler();
  private final DataPersister<RetailItemCommunication> mSLListDataPersister;
  private final DataPersister<SLMeta> mSLMetaDataPersister;
  private ShoppingCartModel mShoppingCart;
  private SLMeta mSlMeta;

  private ShoppingCart(Context paramContext)
  {
    this.mCtx = paramContext.getApplicationContext();
    this.mSLMetaDataPersister = new DataPersister(this.mCtx, "slmeta", SLMeta.class, null);
    this.mSLListDataPersister = new DataPersister(this.mCtx, "sllist", RetailItemCommunication.class, null);
    try
    {
      loadCartFromDisk();
      return;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
    }
  }

  private void calculateStockAvailibility()
  {
    if (this.mShoppingCart != null)
    {
      Collection localCollection = this.mShoppingCart.getProductList();
      int i = 0;
      Iterator localIterator = localCollection.iterator();
      while (localIterator.hasNext())
        if (isLoworOutOfStock((RetailItemCommunication)localIterator.next()))
          i++;
      setLowOrOutofStockProducts(i);
    }
  }

  public static final ShoppingCart i(Context paramContext)
  {
    try
    {
      if (mInstance == null)
        mInstance = new ShoppingCart(paramContext);
      ShoppingCart localShoppingCart = mInstance;
      return localShoppingCart;
    }
    finally
    {
    }
  }

  private boolean isExists(RetailItemCommunication paramRetailItemCommunication, List<RetailItemCommunication> paramList)
  {
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext())
      if (((RetailItemCommunication)localIterator.next()).getItemNo().equalsIgnoreCase(paramRetailItemCommunication.getItemNo()))
        return true;
    return false;
  }

  private boolean isLoworOutOfStock(RetailItemCommunication paramRetailItemCommunication)
  {
    ProductService.STOCK_STATUS localSTOCK_STATUS = ProductService.i(this.mCtx).getStockStatus(paramRetailItemCommunication);
    return (localSTOCK_STATUS.equals(ProductService.STOCK_STATUS.LOW_STOCK)) || (localSTOCK_STATUS.equals(ProductService.STOCK_STATUS.NOT_STOCK));
  }

  private boolean isSaved(RetailItemCommunication paramRetailItemCommunication)
  {
    ShoppingCartModel localShoppingCartModel = this.mShoppingCart;
    boolean bool = false;
    if (localShoppingCartModel != null)
    {
      int i = this.mShoppingCart.getQuantityOfProduct(paramRetailItemCommunication);
      bool = false;
      if (i != 0)
        bool = true;
    }
    return bool;
  }

  private void loadCartFromDisk()
    throws FileNotFoundException
  {
    List localList = this.mSLMetaDataPersister.load();
    this.mShoppingCart = new ShoppingCartModel();
    if ((localList != null) && (!localList.isEmpty()))
      this.mSlMeta = ((SLMeta)localList.get(0));
    Iterator localIterator = this.mSLListDataPersister.load().iterator();
    while (localIterator.hasNext())
    {
      RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)localIterator.next();
      if (localRetailItemCommunication != null)
        this.mShoppingCart.addProductAtInit(localRetailItemCommunication);
    }
    if (this.mShoppingCart == null)
      this.mShoppingCart = new ShoppingCartModel();
    if (this.mSlMeta == null)
      this.mSlMeta = new SLMeta(null);
    User localUser = UserService.i(this.mCtx).getUser();
    if (((localUser.getIkeaFamilyNumber() != null) && (!localUser.getIkeaFamilyNumber().isEmpty())) || ((localUser.getLocalIkeaFamilyNumber() != null) && (!localUser.getLocalIkeaFamilyNumber().isEmpty())))
    {
      updateReceipt(true);
      return;
    }
    updateReceipt(false);
  }

  private RetailItemCommunication makeCopy(RetailItemCommunication paramRetailItemCommunication)
  {
    Gson localGson = new Gson();
    return (RetailItemCommunication)localGson.fromJson(localGson.toJson(paramRetailItemCommunication), paramRetailItemCommunication.getClass());
  }

  private void removeProduct(RetailItemCommunication paramRetailItemCommunication)
    throws Exception
  {
    if (isSaved(paramRetailItemCommunication))
    {
      L.D(this, "object found lets remove " + paramRetailItemCommunication.getItemNo());
      try
      {
        this.mSLListDataPersister.remove(paramRetailItemCommunication);
        SLMeta.access$1102(this.mSlMeta, System.currentTimeMillis());
        this.mSLMetaDataPersister.save(this.mSlMeta);
        this.mShoppingCart.removeProduct(paramRetailItemCommunication);
        calculateStockAvailibility();
        User localUser = UserService.i(this.mCtx).getUser();
        if (((localUser.getIkeaFamilyNumber() != null) && (!localUser.getIkeaFamilyNumber().isEmpty())) || ((localUser.getLocalIkeaFamilyNumber() != null) && (!localUser.getLocalIkeaFamilyNumber().isEmpty())))
          updateReceipt(true);
        while ((localUser != null) && (localUser.isLoggedIn()))
        {
          ArrayList localArrayList = new ArrayList();
          localArrayList.add(new ShoppingBagItem(paramRetailItemCommunication.getItemNo(), paramRetailItemCommunication.getQuantity().getQuantity(), paramRetailItemCommunication.getItemType()));
          ShoppingCartService.i(this.mCtx).processSyncSL(new SyncEventModel(localArrayList, "event_remove"));
          return;
          updateReceipt(false);
        }
      }
      catch (Exception localException)
      {
        L.E(this, "exception saving ", localException);
        throw localException;
      }
    }
  }

  private void saveProduct(RetailItemCommunication paramRetailItemCommunication)
    throws IOException
  {
    RetailItemCommunication localRetailItemCommunication1 = this.mShoppingCart.getProduct(paramRetailItemCommunication.getItemNo());
    Quantity localQuantity;
    if (localRetailItemCommunication1 != null)
    {
      L.D(this, "object found lets update " + paramRetailItemCommunication.getItemNo());
      localRetailItemCommunication1.setLastUpDatedTime(System.currentTimeMillis());
      localQuantity = localRetailItemCommunication1.getQuantity();
      if (paramRetailItemCommunication.isFabric())
      {
        localQuantity.setQuantity(String.valueOf(Double.parseDouble(paramRetailItemCommunication.getQuantity().getQuantity())));
        localRetailItemCommunication1.setQuantity(localQuantity);
      }
    }
    while (true)
    {
      this.mSLListDataPersister.save(localRetailItemCommunication1);
      User localUser2 = UserService.i(this.mCtx).getUser();
      if (((localUser2.getIkeaFamilyNumber() != null) && (!localUser2.getIkeaFamilyNumber().isEmpty())) || ((localUser2.getLocalIkeaFamilyNumber() != null) && (!localUser2.getLocalIkeaFamilyNumber().isEmpty())))
      {
        updateReceipt(true);
        label151: if ((localUser2 != null) && (localUser2.isLoggedIn()))
        {
          ArrayList localArrayList2 = new ArrayList();
          localArrayList2.add(new ShoppingBagItem(localRetailItemCommunication1.getItemNo(), localQuantity.getQuantity(), localRetailItemCommunication1.getItemType()));
          ShoppingCartService.i(this.mCtx).processSyncSL(new SyncEventModel(localArrayList2, "event_update"));
        }
      }
      try
      {
        while (true)
        {
          calculateStockAvailibility();
          SLMeta.access$1102(this.mSlMeta, System.currentTimeMillis());
          this.mSLMetaDataPersister.save(this.mSlMeta);
          return;
          int i = Integer.parseInt(localQuantity.getQuantity());
          int j = (int)Double.parseDouble(paramRetailItemCommunication.getQuantity().getQuantity());
          if (j == 0)
            j = 1;
          localQuantity.setQuantity(String.valueOf(i + j));
          localRetailItemCommunication1.setQuantity(localQuantity);
          localRetailItemCommunication1.setCollected(paramRetailItemCommunication.isCollected());
          break;
          updateReceipt(false);
          break label151;
          L.D(this, "object not found lets save " + paramRetailItemCommunication.getItemNo() + " list is " + paramRetailItemCommunication);
          paramRetailItemCommunication.setLastUpDatedTime(System.currentTimeMillis());
          RetailItemCommunication localRetailItemCommunication2 = makeCopy(paramRetailItemCommunication);
          this.mShoppingCart.addProduct(localRetailItemCommunication2);
          this.mSLListDataPersister.save(localRetailItemCommunication2);
          User localUser1 = UserService.i(this.mCtx).getUser();
          if (((localUser1.getIkeaFamilyNumber() != null) && (!localUser1.getIkeaFamilyNumber().isEmpty())) || ((localUser1.getLocalIkeaFamilyNumber() != null) && (!localUser1.getLocalIkeaFamilyNumber().isEmpty())))
            updateReceipt(true);
          while (true)
          {
            if ((localUser1 == null) || (!localUser1.isLoggedIn()))
              break label527;
            ArrayList localArrayList1 = new ArrayList();
            localArrayList1.add(new ShoppingBagItem(paramRetailItemCommunication.getItemNo(), paramRetailItemCommunication.getQuantity().getQuantity(), paramRetailItemCommunication.getItemType()));
            ShoppingCartService.i(this.mCtx).processSyncSL(new SyncEventModel(localArrayList1, "event_add"));
            break;
            updateReceipt(false);
          }
          label527: if (this.mShoppingCart.size() == 1)
          {
            SLMeta.access$1002(this.mSlMeta, System.currentTimeMillis());
            SLMeta.access$902(this.mSlMeta, this.mSlMeta.mLastSyncedTime);
          }
        }
      }
      catch (IOException localIOException)
      {
        L.E(this, "exception saving ", localIOException);
        throw localIOException;
      }
    }
  }

  private void saveProductsAfterSync(final List<RetailItemCommunication> paramList, ShoppingCartModel paramShoppingCartModel, boolean paramBoolean)
    throws IOException
  {
    if (paramBoolean)
    {
      Iterator localIterator2 = this.mShoppingCart.getProductList().iterator();
      while (localIterator2.hasNext())
      {
        RetailItemCommunication localRetailItemCommunication2 = (RetailItemCommunication)localIterator2.next();
        if (!isExists(localRetailItemCommunication2, paramList))
          paramList.add(localRetailItemCommunication2);
      }
    }
    Iterator localIterator1 = paramList.iterator();
    while (localIterator1.hasNext())
    {
      RetailItemCommunication localRetailItemCommunication1 = (RetailItemCommunication)localIterator1.next();
      localRetailItemCommunication1.setLastUpDatedTime(System.currentTimeMillis());
      paramShoppingCartModel.addProductAtInit(localRetailItemCommunication1);
    }
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        Iterator localIterator = paramList.iterator();
        while (localIterator.hasNext())
        {
          RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)localIterator.next();
          try
          {
            ShoppingCart.this.mSLListDataPersister.save(localRetailItemCommunication);
          }
          catch (IOException localIOException)
          {
            localIOException.printStackTrace();
          }
        }
      }
    });
  }

  private void updateLocation(RetailItemCommChild paramRetailItemCommChild, String paramString)
  {
    if ((paramRetailItemCommChild != null) && (paramString != null) && (!paramString.isEmpty()));
    try
    {
      if ((paramString.length() == 6) && (Integer.parseInt(paramString) >= 0))
      {
        paramRetailItemCommChild.setAisle(paramString.substring(0, 2));
        paramRetailItemCommChild.setLocation(paramString.substring(2, 4));
      }
      if (paramString.length() == 3)
      {
        String str = paramString.substring(0, 2);
        if (Integer.parseInt(str) >= 0)
        {
          paramRetailItemCommChild.setAisle(str);
          paramRetailItemCommChild.setLocation(paramString.substring(2, 3));
        }
      }
      return;
    }
    catch (NumberFormatException localNumberFormatException)
    {
      localNumberFormatException.printStackTrace();
    }
  }

  public void addProduct(final RetailItemCommunication paramRetailItemCommunication, final ServiceCallback<ShoppingCartModel> paramServiceCallback)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        try
        {
          ShoppingCart.this.saveProduct(paramRetailItemCommunication);
          paramServiceCallback.callbackDone(ShoppingCart.this.mShoppingCart, null, null);
          ShoppingCart.this.notifyShoppingCartChanged();
          return;
        }
        catch (Exception localException)
        {
          L.E(this, "exception appending ", localException);
          paramServiceCallback.callbackDone(null, null, localException);
        }
      }
    });
  }

  public void changeFavoriteStore(final String paramString)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        Collection localCollection;
        try
        {
          localCollection = ShoppingCart.this.mShoppingCart.getProductList();
          Iterator localIterator1 = localCollection.iterator();
          while (localIterator1.hasNext())
            ((RetailItemCommunication)localIterator1.next()).setStockAvailability(null);
        }
        catch (Exception localException)
        {
          L.E(this, "exception while change Favorite Store and update shopping cart ", localException);
          return;
        }
        ShoppingCart.this.setLowOrOutofStockProducts(0);
        ShoppingCart.this.notifyShoppingCartChanged();
        int i = 0;
        Iterator localIterator2 = localCollection.iterator();
        while (localIterator2.hasNext())
        {
          RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)localIterator2.next();
          StockAvailabilityResponse localStockAvailabilityResponse = ProductService.i(ShoppingCart.this.mCtx).getProductStockInfo(paramString, localRetailItemCommunication);
          if ((localStockAvailabilityResponse != null) && (localStockAvailabilityResponse.isSuccessful()) && (localStockAvailabilityResponse.getStockAvailability() != null) && (!localStockAvailabilityResponse.getStockAvailability().isEmpty()))
          {
            localRetailItemCommunication.setStockAvailability(localStockAvailabilityResponse);
            ShoppingCart.i(ShoppingCart.this.mCtx).updateProductStockInfo(localRetailItemCommunication);
          }
          if (ShoppingCart.this.isLoworOutOfStock(localRetailItemCommunication))
            i++;
        }
        UsageTracker.i().stockCheckResult(ShoppingCart.this.mCtx, ShoppingCart.this.mShoppingCart, paramString);
        ShoppingCart.SLMeta.access$902(ShoppingCart.this.mSlMeta, System.currentTimeMillis());
        ShoppingCart.this.setLowOrOutofStockProducts(i);
        ShoppingCart.SLMeta.access$1102(ShoppingCart.this.mSlMeta, System.currentTimeMillis());
        ShoppingCart.this.notifyShoppingCartChanged();
        ShoppingCart.this.mSLMetaDataPersister.save(ShoppingCart.this.mSlMeta);
        Constant.i().setProductModified(true);
      }
    });
  }

  public ShoppingCartModel fetchShoppingCart()
  {
    if (this.mShoppingCart == null);
    try
    {
      loadCartFromDisk();
      return this.mShoppingCart;
    }
    catch (Exception localException)
    {
      while (true)
        L.E(this, "exception loading " + localException, localException);
    }
  }

  public void fetchShoppingCart(final ServiceCallback<ShoppingCartModel> paramServiceCallback)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        if (ShoppingCart.this.mShoppingCart == null)
          try
          {
            ShoppingCart.this.loadCartFromDisk();
            paramServiceCallback.callbackDone(ShoppingCart.this.mShoppingCart, null, null);
            return;
          }
          catch (Exception localException)
          {
            L.E(this, "exception loading " + localException, localException);
            paramServiceCallback.callbackDone(null, null, localException);
            return;
          }
        paramServiceCallback.callbackDone(ShoppingCart.this.mShoppingCart, null, null);
      }
    });
  }

  public long getCartLastUdpatedTime()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.mLastUdpateTime;
    return -1L;
  }

  public int getChildTotalQuantityInSL(String paramString)
  {
    int i = 0;
    Iterator localIterator1 = this.mShoppingCart.getProductList().iterator();
    while (localIterator1.hasNext())
    {
      RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)localIterator1.next();
      if ((localRetailItemCommunication.getRetailItemCommChildList() != null) && (localRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild() != null) && (localRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild().size() > 0))
      {
        Iterator localIterator2 = localRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild().iterator();
        while (localIterator2.hasNext())
        {
          RetailItemCommChild localRetailItemCommChild = (RetailItemCommChild)localIterator2.next();
          if (localRetailItemCommChild.getItemNo().equalsIgnoreCase(paramString))
            i += localRetailItemCommChild.getTotalQuantity();
        }
      }
    }
    return i;
  }

  public int getDiscontinuedProducts()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.discontinuedProducts;
    return 0;
  }

  public long getLastStockSyncedTime()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.mLastStockSyncedTime;
    return 0L;
  }

  public long getLastSyncedTime()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.mLastSyncedTime;
    return 0L;
  }

  public int getLowOrOutofStockProducts()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.lowOrOutofStockProducts;
    return 0;
  }

  public RetailItemCommunication getProduct(String paramString)
  {
    ShoppingCartModel localShoppingCartModel = this.mShoppingCart;
    RetailItemCommunication localRetailItemCommunication = null;
    if (localShoppingCartModel != null)
      localRetailItemCommunication = this.mShoppingCart.getProduct(paramString);
    return localRetailItemCommunication;
  }

  public Collection<RetailItemCommunication> getProductList()
  {
    return this.mShoppingCart.getProductList();
  }

  public List<RetailItemCommunication> getProductListWithDepartmentSelfServeSPR()
  {
    Collection localCollection = this.mShoppingCart.getProductList();
    ArrayList localArrayList1 = new ArrayList();
    String str;
    ArrayList localArrayList2;
    ArrayList localArrayList3;
    ArrayList localArrayList4;
    Iterator localIterator1;
    if (!localCollection.isEmpty())
    {
      if (this.mSlMeta.discontinuedProducts > 0)
      {
        RetailItemCommunication localRetailItemCommunication3 = new RetailItemCommunication();
        localRetailItemCommunication3.setViewType(RetailItemCommunication.SL_ITEM_TYPE.ALERTITEM);
        localRetailItemCommunication3.setDiscontinuedProducts(this.mSlMeta.discontinuedProducts);
        localRetailItemCommunication3.setTimeAdded(System.currentTimeMillis());
        localArrayList1.add(localRetailItemCommunication3);
      }
      if (this.mSlMeta.updatedPriceProducts > 0)
      {
        RetailItemCommunication localRetailItemCommunication4 = new RetailItemCommunication();
        localRetailItemCommunication4.setViewType(RetailItemCommunication.SL_ITEM_TYPE.ALERTITEM);
        localRetailItemCommunication4.setUpdatedPriceProducts(this.mSlMeta.updatedPriceProducts);
        localRetailItemCommunication4.setTimeAdded(System.currentTimeMillis());
        localArrayList1.add(localRetailItemCommunication4);
      }
      RetailItemCommunication localRetailItemCommunication5 = new RetailItemCommunication();
      localRetailItemCommunication5.setViewType(RetailItemCommunication.SL_ITEM_TYPE.STOREITEM);
      localRetailItemCommunication5.setTimeAdded(System.currentTimeMillis());
      localArrayList1.add(localRetailItemCommunication5);
      str = "";
      localArrayList2 = new ArrayList();
      localArrayList3 = new ArrayList();
      localArrayList4 = new ArrayList();
      localIterator1 = localCollection.iterator();
    }
    while (localIterator1.hasNext())
    {
      RetailItemCommunication localRetailItemCommunication10 = (RetailItemCommunication)localIterator1.next();
      localRetailItemCommunication10.setStoreDepartmentName("CONTACT STAFF");
      if ((localRetailItemCommunication10.getItemType().equalsIgnoreCase("SPR")) && (localRetailItemCommunication10.getRetailItemCommChildList() != null) && (localRetailItemCommunication10.getRetailItemCommChildList().getRetailItemCommChild() != null) && (!localRetailItemCommunication10.getRetailItemCommChildList().getRetailItemCommChild().isEmpty()))
      {
        localRetailItemCommunication10.setStoreDepartmentName("Self-Service");
        updateChildStockandLocation(localRetailItemCommunication10);
      }
      StockAvailability localStockAvailability;
      if ((!localRetailItemCommunication10.getItemType().equalsIgnoreCase("SPR")) && (localRetailItemCommunication10.getStockAvailability() != null) && (localRetailItemCommunication10.getStockAvailability().getStockAvailability() != null) && (!localRetailItemCommunication10.getStockAvailability().getStockAvailability().isEmpty()))
      {
        localStockAvailability = (StockAvailability)localRetailItemCommunication10.getStockAvailability().getStockAvailability().get(0);
        if ((localStockAvailability != null) && (localStockAvailability.getRetailItemAvailability() != null))
        {
          if ((localStockAvailability.getRetailItemAvailability().getSalesMethodCode() == null) || (!localStockAvailability.getRetailItemAvailability().getSalesMethodCode().equals("1")))
            break label535;
          if (!localStockAvailability.getRetailItemAvailability().getRecommendedSalesLocation().isEmpty())
          {
            localRetailItemCommunication10.setStoreDepartmentName("Self-Service");
            updateLocation(localRetailItemCommunication10, localStockAvailability.getRetailItemAvailability().getRecommendedSalesLocation());
          }
        }
      }
      while (true)
      {
        if (!localRetailItemCommunication10.getStoreDepartmentName().equals("Self-Service"))
          break label580;
        localArrayList2.add(localRetailItemCommunication10);
        break;
        RetailItemCommunication localRetailItemCommunication1 = new RetailItemCommunication();
        localRetailItemCommunication1.setViewType(RetailItemCommunication.SL_ITEM_TYPE.STOREITEM);
        localRetailItemCommunication1.setTimeAdded(System.currentTimeMillis());
        localArrayList1.add(localRetailItemCommunication1);
        RetailItemCommunication localRetailItemCommunication2 = new RetailItemCommunication();
        localRetailItemCommunication2.setViewType(RetailItemCommunication.SL_ITEM_TYPE.EMPTYLIST);
        localRetailItemCommunication2.setTimeAdded(System.currentTimeMillis());
        localArrayList1.add(localRetailItemCommunication2);
        return localArrayList1;
        label535: if ((!TextUtils.isEmpty(localStockAvailability.getRetailItemAvailability().getRecommendedSalesLocation())) && (isAlpha(localStockAvailability.getRetailItemAvailability().getRecommendedSalesLocation())))
          localRetailItemCommunication10.setStoreDepartmentName(localStockAvailability.getRetailItemAvailability().getRecommendedSalesLocation());
      }
      label580: if (localRetailItemCommunication10.getStoreDepartmentName().equals("CONTACT STAFF"))
        localArrayList3.add(localRetailItemCommunication10);
      else
        localArrayList4.add(localRetailItemCommunication10);
    }
    Collections.sort(localArrayList4, RICComparator.mDateDepartmentComparator);
    Collections.sort(localArrayList3, RICComparator.mDateDepartmentComparator);
    Collections.sort(localArrayList2, RICComparator.mDateDepartmentComparator);
    if (!localArrayList3.isEmpty())
    {
      RetailItemCommunication localRetailItemCommunication6 = new RetailItemCommunication();
      localRetailItemCommunication6.setViewType(RetailItemCommunication.SL_ITEM_TYPE.DEPARTMENT);
      localRetailItemCommunication6.setStoreDepartmentName("CONTACT STAFF");
      localRetailItemCommunication6.setTimeAdded(System.currentTimeMillis());
      localArrayList1.add(localRetailItemCommunication6);
      localArrayList1.addAll(localArrayList3);
    }
    if (!localArrayList4.isEmpty())
    {
      Iterator localIterator2 = localArrayList4.iterator();
      while (localIterator2.hasNext())
      {
        RetailItemCommunication localRetailItemCommunication8 = (RetailItemCommunication)localIterator2.next();
        if ((str.isEmpty()) || (!localRetailItemCommunication8.getStoreDepartmentName().equalsIgnoreCase(str)))
        {
          str = localRetailItemCommunication8.getStoreDepartmentName();
          RetailItemCommunication localRetailItemCommunication9 = new RetailItemCommunication();
          localRetailItemCommunication9.setViewType(RetailItemCommunication.SL_ITEM_TYPE.DEPARTMENT);
          localRetailItemCommunication9.setStoreDepartmentName(str);
          localRetailItemCommunication9.setTimeAdded(localRetailItemCommunication8.getTimeAdded());
          localArrayList1.add(localRetailItemCommunication9);
        }
        localArrayList1.add(localRetailItemCommunication8);
      }
    }
    if (!localArrayList2.isEmpty())
    {
      RetailItemCommunication localRetailItemCommunication7 = new RetailItemCommunication();
      localRetailItemCommunication7.setViewType(RetailItemCommunication.SL_ITEM_TYPE.DEPARTMENT);
      localRetailItemCommunication7.setStoreDepartmentName("Self-Service");
      localRetailItemCommunication7.setTimeAdded(System.currentTimeMillis());
      localArrayList1.add(localRetailItemCommunication7);
      localArrayList1.addAll(localArrayList2);
    }
    return new ArrayList(localArrayList1);
  }

  public int getQuantity(RetailItemCommunication paramRetailItemCommunication)
  {
    ShoppingCartModel localShoppingCartModel = this.mShoppingCart;
    int i = 0;
    if (localShoppingCartModel != null)
      i = this.mShoppingCart.getQuantityOfProduct(paramRetailItemCommunication);
    return i;
  }

  public Receipt getReceipt()
  {
    if (this.mShoppingCart != null)
      return this.mShoppingCart.getReceipt();
    return null;
  }

  public String getShoppingBagId()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.BagId;
    return "";
  }

  public int getShoppingItemCount()
  {
    if (this.mShoppingCart != null)
      return this.mShoppingCart.getTotalQuantity();
    return 0;
  }

  public String getShoppingListID()
  {
    if ((this.mSlMeta != null) && (this.mSlMeta.BagId != null))
      return this.mSlMeta.BagId;
    return "";
  }

  public double getSize(RetailItemCommunication paramRetailItemCommunication)
  {
    double d = 0.0D;
    if (this.mShoppingCart != null)
      d = this.mShoppingCart.getSizeOfProduct(paramRetailItemCommunication);
    return d;
  }

  public int getUpdatedPriceProducts()
  {
    if (this.mSlMeta != null)
      return this.mSlMeta.updatedPriceProducts;
    return 0;
  }

  public boolean hasCollectedItem()
  {
    if (this.mShoppingCart != null)
    {
      Iterator localIterator = this.mShoppingCart.getProductList().iterator();
      while (localIterator.hasNext())
        if (((RetailItemCommunication)localIterator.next()).isCollected())
          return true;
    }
    return false;
  }

  public boolean isAlpha(String paramString)
  {
    char[] arrayOfChar = paramString.toCharArray();
    int i = arrayOfChar.length;
    for (int j = 0; j < i; j++)
      if (!Character.isLetter(arrayOfChar[j]))
        return false;
    return true;
  }

  public boolean isEmpty()
  {
    return (this.mShoppingCart != null) && (this.mShoppingCart.isEmpty());
  }

  public boolean isExits(String paramString)
  {
    if ((this.mShoppingCart != null) && (paramString != null))
      return this.mShoppingCart.isProductExits(paramString);
    return false;
  }

  public boolean isProductCollected(String paramString)
  {
    if ((this.mShoppingCart != null) && (this.mShoppingCart.isProductExits(paramString)))
      return getProduct(paramString).isCollected();
    return false;
  }

  public void notifyShoppingCartAfterSync(final boolean paramBoolean1, final ShoppingCartModel paramShoppingCartModel, final boolean paramBoolean2)
  {
    try
    {
      Constant.i().setProductModified(true);
      this.mHandler.post(new Runnable()
      {
        public void run()
        {
          User localUser = UserService.i(ShoppingCart.this.mCtx).getUser();
          if ((ShoppingCart.this.mShoppingCart != null) && (paramBoolean1) && ((localUser == null) || (!localUser.isLoggedIn())))
          {
            ShoppingCart.this.mShoppingCart.reset();
            ShoppingCart.SLMeta.access$602(ShoppingCart.this.mSlMeta, 0);
            ShoppingCart.SLMeta.access$702(ShoppingCart.this.mSlMeta, 0);
            ShoppingCart.SLMeta.access$802(ShoppingCart.this.mSlMeta, 0);
            ShoppingCart.SLMeta.access$902(ShoppingCart.this.mSlMeta, 0L);
            ShoppingCart.SLMeta.access$1002(ShoppingCart.this.mSlMeta, 0L);
            ShoppingCart.SLMeta.access$1102(ShoppingCart.this.mSlMeta, 0L);
            ShoppingCart.SLMeta.access$202(ShoppingCart.this.mSlMeta, "");
            ShoppingCart.this.mSLListDataPersister.reset();
            ShoppingCart.this.mSLMetaDataPersister.reset();
            NotificationService.i(ShoppingCart.this.mCtx).setOONotificationDismissed(false);
            ShoppingCart.this.updateReceipt(false);
          }
          label352: 
          while (true)
          {
            int i = ShoppingCart.this.getShoppingItemCount();
            L.I(this, "BadgeEvent count " + i);
            ShoppingCart.this.mBus.post(new SLChangedEvent(ShoppingCart.this.mShoppingCart, i));
            return;
            ShoppingCart.access$002(ShoppingCart.this, paramShoppingCartModel);
            if (((localUser.getIkeaFamilyNumber() != null) && (!localUser.getIkeaFamilyNumber().isEmpty())) || ((localUser.getLocalIkeaFamilyNumber() != null) && (!localUser.getLocalIkeaFamilyNumber().isEmpty())))
              ShoppingCart.this.updateReceipt(true);
            while (true)
            {
              if (!paramBoolean2)
                break label352;
              StoreRef localStoreRef = AppConfigManager.i(ShoppingCart.this.mCtx).getAppConfigData().getFavStore();
              String str = "";
              if (localStoreRef != null)
                str = localStoreRef.getStoreNo();
              ShoppingCart.this.changeFavoriteStore(str);
              break;
              ShoppingCart.this.updateReceipt(false);
            }
          }
        }
      });
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void notifyShoppingCartChanged()
  {
    try
    {
      Constant.i().setProductModified(true);
      this.mHandler.post(new Runnable()
      {
        public void run()
        {
          if (ShoppingCart.this.mShoppingCart != null)
          {
            int i = ShoppingCart.this.getShoppingItemCount();
            L.I(this, "BadgeEvent count " + i);
            ShoppingCart.this.mBus.post(new SLChangedEvent(ShoppingCart.this.mShoppingCart, i));
          }
        }
      });
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void remove(RetailItemCommunication paramRetailItemCommunication)
  {
    try
    {
      removeProduct(paramRetailItemCommunication);
      notifyShoppingCartChanged();
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public void removeCollectedItems()
  {
    ArrayList localArrayList;
    if (this.mShoppingCart != null)
    {
      List localList = this.mShoppingCart.removeCollectedProducts();
      L.D(this, localList.size() + "Collected items removed from list");
      if (!localList.isEmpty())
        try
        {
          calculateStockAvailibility();
          User localUser = UserService.i(this.mCtx).getUser();
          if (((localUser.getIkeaFamilyNumber() != null) && (!localUser.getIkeaFamilyNumber().isEmpty())) || ((localUser.getLocalIkeaFamilyNumber() != null) && (!localUser.getLocalIkeaFamilyNumber().isEmpty())))
            updateReceipt(true);
          while (true)
          {
            this.mSLListDataPersister.remove(localList);
            if ((localUser == null) || (!localUser.isLoggedIn()))
              break label256;
            localArrayList = new ArrayList();
            for (int i = 0; i < localList.size(); i++)
              localArrayList.add(new ShoppingBagItem(((RetailItemCommunication)localList.get(i)).getItemNo(), ((RetailItemCommunication)localList.get(i)).getQuantity().getQuantity(), ((RetailItemCommunication)localList.get(i)).getItemType()));
            updateReceipt(false);
          }
        }
        catch (Exception localException)
        {
          L.E(this, "exception saving ", localException);
        }
    }
    return;
    ShoppingCartService.i(this.mCtx).processSyncSL(new SyncEventModel(localArrayList, "event_remove"));
    label256: notifyShoppingCartChanged();
  }

  public void reset()
  {
    if (this.mShoppingCart != null)
    {
      this.mShoppingCart.reset();
      SLMeta.access$602(this.mSlMeta, 0);
      SLMeta.access$702(this.mSlMeta, 0);
      SLMeta.access$802(this.mSlMeta, 0);
      SLMeta.access$902(this.mSlMeta, 0L);
      SLMeta.access$1002(this.mSlMeta, 0L);
      SLMeta.access$1102(this.mSlMeta, 0L);
      SLMeta.access$202(this.mSlMeta, "");
      this.mSLListDataPersister.reset();
      this.mSLMetaDataPersister.reset();
      NotificationService.i(this.mCtx).setOONotificationDismissed(false);
      updateReceipt(false);
    }
    notifyShoppingCartChanged();
  }

  public void resetCartAndSync()
  {
    Collection localCollection = this.mShoppingCart.getProductList();
    ArrayList localArrayList;
    if (this.mShoppingCart != null)
    {
      SLMeta.access$602(this.mSlMeta, 0);
      SLMeta.access$702(this.mSlMeta, 0);
      SLMeta.access$802(this.mSlMeta, 0);
      SLMeta.access$1102(this.mSlMeta, System.currentTimeMillis());
      this.mSLListDataPersister.reset();
      this.mSLMetaDataPersister.reset();
      updateReceipt(false);
      try
      {
        User localUser = UserService.i(this.mCtx).getUser();
        if ((localUser != null) && (localUser.isLoggedIn()))
        {
          localArrayList = new ArrayList();
          Iterator localIterator = localCollection.iterator();
          while (localIterator.hasNext())
          {
            RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)localIterator.next();
            localArrayList.add(new ShoppingBagItem(localRetailItemCommunication.getItemNo(), localRetailItemCommunication.getQuantity().getQuantity(), localRetailItemCommunication.getItemType()));
          }
        }
      }
      catch (Exception localException)
      {
        L.E(this, "exception saving ", localException);
      }
    }
    while (true)
    {
      this.mShoppingCart.reset();
      return;
      ShoppingCartService.i(this.mCtx).processSyncSL(new SyncEventModel(localArrayList, "event_remove"));
      notifyShoppingCartChanged();
    }
  }

  public void resetDiscontinuedProducts()
  {
    if (this.mSlMeta != null)
      SLMeta.access$702(this.mSlMeta, 0);
  }

  public void resetSyncAlerts()
  {
    if (this.mSlMeta != null)
    {
      SLMeta.access$702(this.mSlMeta, 0);
      SLMeta.access$602(this.mSlMeta, 0);
    }
  }

  public void resetSyncTime()
  {
    if (this.mShoppingCart != null)
    {
      SLMeta.access$602(this.mSlMeta, 0);
      SLMeta.access$702(this.mSlMeta, 0);
      SLMeta.access$802(this.mSlMeta, 0);
      SLMeta.access$902(this.mSlMeta, 0L);
      SLMeta.access$1002(this.mSlMeta, 0L);
      SLMeta.access$1102(this.mSlMeta, 0L);
    }
    try
    {
      this.mSLMetaDataPersister.save(this.mSlMeta);
      NotificationService.i(this.mCtx).setOONotificationDismissed(false);
      notifyShoppingCartChanged();
      return;
    }
    catch (IOException localIOException)
    {
      while (true)
        L.E(this, "exception saving meta ", localIOException);
    }
  }

  public void resetUpdatedPriceProducts()
  {
    if (this.mSlMeta != null)
      SLMeta.access$602(this.mSlMeta, 0);
  }

  public void setLowOrOutofStockProducts(int paramInt)
  {
    if (this.mSlMeta != null)
    {
      NotificationService.i(this.mCtx).setOONotificationDismissed(false);
      SLMeta.access$802(this.mSlMeta, paramInt);
    }
  }

  public String setShoppingBagId(String paramString)
  {
    if (this.mSlMeta != null)
      SLMeta.access$202(this.mSlMeta, paramString);
    try
    {
      this.mSLMetaDataPersister.save(this.mSlMeta);
      return null;
    }
    catch (Exception localException)
    {
      while (true)
        L.E(this, "exception saving ", localException);
    }
  }

  public boolean updateCartAfterStockCheck(int paramInt, boolean paramBoolean)
  {
    setLowOrOutofStockProducts(paramInt);
    if (this.mSlMeta != null)
    {
      NotificationService.i(this.mCtx).setOONotificationDismissed(false);
      SLMeta.access$902(this.mSlMeta, System.currentTimeMillis());
      SLMeta.access$1102(this.mSlMeta, this.mSlMeta.mLastStockSyncedTime);
    }
    if (paramBoolean)
      notifyShoppingCartChanged();
    try
    {
      this.mSLMetaDataPersister.save(this.mSlMeta);
      return true;
    }
    catch (IOException localIOException)
    {
      while (true)
        L.E(this, "exception saving meta ", localIOException);
    }
  }

  public boolean updateCartAfterSync(List<RetailItemCommunication> paramList, long paramLong, int paramInt1, int paramInt2, int paramInt3, String paramString, boolean paramBoolean1, boolean paramBoolean2)
  {
    User localUser = UserService.i(this.mCtx).getUser();
    if ((!paramBoolean1) || ((paramBoolean1) && (localUser != null) && (localUser.isLoggedIn())))
    {
      this.mSLListDataPersister.reset();
      this.mSLMetaDataPersister.reset();
      SLMeta.access$1002(this.mSlMeta, paramLong);
      SLMeta.access$902(this.mSlMeta, paramLong);
      SLMeta.access$1102(this.mSlMeta, paramLong);
      setLowOrOutofStockProducts(paramInt1);
      SLMeta.access$602(this.mSlMeta, paramInt2);
      SLMeta.access$702(this.mSlMeta, paramInt3);
      SLMeta.access$202(this.mSlMeta, paramString);
    }
    try
    {
      this.mSLMetaDataPersister.save(this.mSlMeta);
      ShoppingCartModel localShoppingCartModel = new ShoppingCartModel();
      saveProductsAfterSync(paramList, localShoppingCartModel, paramBoolean2);
      notifyShoppingCartAfterSync(paramBoolean1, localShoppingCartModel, paramBoolean2);
      return true;
    }
    catch (IOException localIOException)
    {
      while (true)
        L.E(this, "exception saving meta ", localIOException);
    }
  }

  public void updateChildCollectedStatus(final String paramString, final boolean paramBoolean)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        int i;
        do
          while (true)
          {
            RetailItemCommunication localRetailItemCommunication;
            int j;
            int k;
            List localList;
            try
            {
              Collection localCollection = ShoppingCart.this.mShoppingCart.getProductList();
              i = 0;
              Iterator localIterator1 = localCollection.iterator();
              if (!localIterator1.hasNext())
                break;
              localRetailItemCommunication = (RetailItemCommunication)localIterator1.next();
              j = 0;
              if ((localRetailItemCommunication == null) || (localRetailItemCommunication.getRetailItemCommChildList() == null) || (localRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild() == null) || (localRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild().size() <= 0))
                continue;
              k = 0;
              localList = localRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild();
              Iterator localIterator2 = localList.iterator();
              if (localIterator2.hasNext())
              {
                RetailItemCommChild localRetailItemCommChild = (RetailItemCommChild)localIterator2.next();
                if (localRetailItemCommChild.getItemNo().equalsIgnoreCase(paramString))
                {
                  localRetailItemCommChild.setCollected(paramBoolean);
                  k = 1;
                  i = 1;
                  if (!paramBoolean)
                    continue;
                  j++;
                  continue;
                }
                if (!localRetailItemCommChild.isCollected())
                  continue;
                j++;
                continue;
              }
              if ((j == localList.size()) && (!localRetailItemCommunication.isCollected()))
              {
                k = 1;
                i = 1;
                localRetailItemCommunication.setCollected(true);
                if (k == 0)
                  continue;
                localRetailItemCommunication.setLastUpDatedTime(System.currentTimeMillis());
                ShoppingCart.this.mShoppingCart.updateProduct(localRetailItemCommunication);
                ShoppingCart.this.mSLListDataPersister.save(localRetailItemCommunication);
                ShoppingCart.SLMeta.access$1102(ShoppingCart.this.mSlMeta, System.currentTimeMillis());
                ShoppingCart.this.mSLMetaDataPersister.save(ShoppingCart.this.mSlMeta);
                continue;
              }
            }
            catch (Exception localException)
            {
              L.E(this, "exception appending ", localException);
              return;
            }
            if ((j != localList.size()) && (localRetailItemCommunication.isCollected()))
            {
              k = 1;
              i = 1;
              localRetailItemCommunication.setCollected(false);
            }
          }
        while (i == 0);
        ShoppingCart.this.notifyShoppingCartChanged();
      }
    });
  }

  public void updateChildStockandLocation(RetailItemCommunication paramRetailItemCommunication)
  {
    if ((paramRetailItemCommunication != null) && (paramRetailItemCommunication.getRetailItemCommChildList() != null) && (paramRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild() != null))
    {
      List localList1 = paramRetailItemCommunication.getRetailItemCommChildList().getRetailItemCommChild();
      Iterator localIterator1 = localList1.iterator();
      while (true)
      {
        if (!localIterator1.hasNext())
          break label346;
        RetailItemCommChild localRetailItemCommChild = (RetailItemCommChild)localIterator1.next();
        StockAvailabilityResponse localStockAvailabilityResponse = paramRetailItemCommunication.getStockAvailability();
        if (paramRetailItemCommunication.getQuantity() == null)
          paramRetailItemCommunication.setQuantity(new Quantity(paramRetailItemCommunication.getItemUnitCode(), "1"));
        localRetailItemCommChild.setTotalQuantity(Integer.parseInt(paramRetailItemCommunication.getQuantity().getQuantity()) * localRetailItemCommChild.getQuantity());
        if ((localStockAvailabilityResponse != null) && (localStockAvailabilityResponse.getStockAvailability() != null) && (localStockAvailabilityResponse.getStockAvailability().size() == 1))
        {
          StockAvailability localStockAvailability = (StockAvailability)localStockAvailabilityResponse.getStockAvailability().get(0);
          if ((localStockAvailability != null) && (localStockAvailability.getRetailItemAvailability() != null) && (localStockAvailability.getRetailItemAvailability().getRetailItemCommChildAvailabilityList() != null))
          {
            List localList2 = localStockAvailability.getRetailItemAvailability().getRetailItemCommChildAvailabilityList().getRetailItemCommChildAvailability();
            if ((localList2 != null) && (!localList2.isEmpty()))
            {
              Iterator localIterator2 = localList2.iterator();
              if (localIterator2.hasNext())
              {
                RetailItemCommChildAvailability localRetailItemCommChildAvailability = (RetailItemCommChildAvailability)localIterator2.next();
                if (!localRetailItemCommChildAvailability.getItemNo().equals(localRetailItemCommChild.getItemNo()))
                  break;
                localRetailItemCommChild.setStockAvailability(localRetailItemCommChildAvailability);
                if ((localRetailItemCommChildAvailability.getSalesMethodCode() != null) && (localRetailItemCommChildAvailability.getSalesMethodCode().equals("1")))
                {
                  updateLocation(localRetailItemCommChild, localRetailItemCommChildAvailability.getRecommendedSalesLocation());
                  localRetailItemCommChild.setDepartmentName("Self-Service");
                }
                else if ((!localRetailItemCommChildAvailability.getRecommendedSalesLocation().isEmpty()) && (isAlpha(localRetailItemCommChildAvailability.getRecommendedSalesLocation())))
                {
                  localRetailItemCommChild.setDepartmentName(localRetailItemCommChildAvailability.getRecommendedSalesLocation());
                }
                else
                {
                  localRetailItemCommChild.setDepartmentName(paramRetailItemCommunication.getStoreDepartmentName());
                }
              }
            }
          }
        }
      }
      label346: Collections.sort(localList1, RICComparator.mSPRChildComparator);
      if ((localList1 != null) && (!localList1.isEmpty()))
      {
        paramRetailItemCommunication.setAisle(((RetailItemCommChild)localList1.get(0)).getAisle());
        paramRetailItemCommunication.setLocation(((RetailItemCommChild)localList1.get(0)).getLocation());
      }
    }
  }

  public void updateLocation(RetailItemCommunication paramRetailItemCommunication, String paramString)
  {
    if ((paramRetailItemCommunication != null) && (paramString != null) && (!paramString.isEmpty()));
    try
    {
      if ((paramString.length() == 6) && (Integer.parseInt(paramString) >= 0))
      {
        paramRetailItemCommunication.setAisle(paramString.substring(0, 2));
        paramRetailItemCommunication.setLocation(paramString.substring(2, 4));
      }
      if (paramString.length() == 3)
      {
        String str = paramString.substring(0, 2);
        if (Integer.parseInt(str) >= 0)
        {
          paramRetailItemCommunication.setAisle(str);
          paramRetailItemCommunication.setLocation(paramString.substring(2, 3));
        }
      }
      return;
    }
    catch (NumberFormatException localNumberFormatException)
    {
    }
  }

  public void updateProduct(final RetailItemCommunication paramRetailItemCommunication)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        try
        {
          if (ShoppingCart.this.mShoppingCart.getProduct(paramRetailItemCommunication.getItemNo()) != null)
          {
            paramRetailItemCommunication.setLastUpDatedTime(System.currentTimeMillis());
            ShoppingCart.this.mShoppingCart.updateProduct(paramRetailItemCommunication);
          }
          User localUser = UserService.i(ShoppingCart.this.mCtx).getUser();
          if (((localUser.getIkeaFamilyNumber() != null) && (!localUser.getIkeaFamilyNumber().isEmpty())) || ((localUser.getLocalIkeaFamilyNumber() != null) && (!localUser.getLocalIkeaFamilyNumber().isEmpty())))
            ShoppingCart.this.updateReceipt(true);
          while (true)
          {
            ShoppingCart.this.calculateStockAvailibility();
            ShoppingCart.this.mSLListDataPersister.save(paramRetailItemCommunication);
            ShoppingCart.SLMeta.access$1102(ShoppingCart.this.mSlMeta, System.currentTimeMillis());
            ShoppingCart.this.mSLMetaDataPersister.save(ShoppingCart.this.mSlMeta);
            ShoppingCart.this.notifyShoppingCartChanged();
            if ((localUser == null) || (!localUser.isLoggedIn()))
              break;
            ArrayList localArrayList = new ArrayList();
            localArrayList.add(new ShoppingBagItem(paramRetailItemCommunication.getItemNo(), paramRetailItemCommunication.getQuantity().getQuantity(), paramRetailItemCommunication.getItemType()));
            ShoppingCartService.i(ShoppingCart.this.mCtx).processSyncSL(new SyncEventModel(localArrayList, "event_update"));
            return;
            ShoppingCart.this.updateReceipt(false);
          }
        }
        catch (Exception localException)
        {
          L.E(this, "exception appending ", localException);
        }
      }
    });
  }

  public void updateProductCollectedStatus(final String paramString, final boolean paramBoolean)
  {
    this.mExecutorService.execute(new Runnable()
    {
      public void run()
      {
        try
        {
          RetailItemCommunication localRetailItemCommunication = ShoppingCart.this.mShoppingCart.getProduct(paramString);
          if (localRetailItemCommunication != null)
          {
            localRetailItemCommunication.setLastUpDatedTime(System.currentTimeMillis());
            localRetailItemCommunication.setCollected(paramBoolean);
            ShoppingCart.this.mShoppingCart.updateProduct(localRetailItemCommunication);
            ShoppingCart.this.mSLListDataPersister.save(localRetailItemCommunication);
            ShoppingCart.SLMeta.access$1102(ShoppingCart.this.mSlMeta, System.currentTimeMillis());
            ShoppingCart.this.mSLMetaDataPersister.save(ShoppingCart.this.mSlMeta);
            ShoppingCart.this.notifyShoppingCartChanged();
          }
          return;
        }
        catch (Exception localException)
        {
          L.E(this, "exception appending ", localException);
        }
      }
    });
  }

  public void updateProductStockInfo(RetailItemCommunication paramRetailItemCommunication)
  {
    if (this.mShoppingCart.getProduct(paramRetailItemCommunication.getItemNo()) != null)
    {
      paramRetailItemCommunication.setLastUpDatedTime(System.currentTimeMillis());
      this.mShoppingCart.updateProduct(paramRetailItemCommunication);
    }
    try
    {
      this.mSLListDataPersister.save(paramRetailItemCommunication);
      return;
    }
    catch (IOException localIOException)
    {
      L.E(this, "exception updating", localIOException);
    }
  }

  public void updateReceipt(boolean paramBoolean)
  {
    float f1 = 0.0F;
    float f2 = 0.0F;
    float f3 = 0.0F;
    float f4 = 0.0F;
    Iterator localIterator = this.mShoppingCart.getProductList().iterator();
    while (localIterator.hasNext())
    {
      RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)localIterator.next();
      if (localRetailItemCommunication.getDisplayPriceInfo() == null)
        BasePriceUtil.updateDisplayPriceInfo(this.mCtx, localRetailItemCommunication);
      DisplayPriceInfo localDisplayPriceInfo = localRetailItemCommunication.getDisplayPriceInfo();
      PriceGroup localPriceGroup1 = localDisplayPriceInfo.getRegPrice();
      if (localRetailItemCommunication.getQuantity() == null)
        localRetailItemCommunication.setQuantity(new Quantity(localRetailItemCommunication.getItemUnitCode(), "1"));
      double d = Double.parseDouble(localRetailItemCommunication.getQuantity().getQuantity());
      if (localPriceGroup1 != null)
        if (localDisplayPriceInfo.isDisplayFamilyPrice())
        {
          PriceGroup localPriceGroup2 = localDisplayPriceInfo.getFamilyPrice();
          f4 = (float)(f4 + d * (localPriceGroup1.getPriceValue() - localPriceGroup2.getPriceValue()));
          if (paramBoolean)
          {
            f1 = (float)(f1 + d * localPriceGroup2.getPriceValue());
            f2 = (float)(f2 + d * localPriceGroup2.getPriceExclusiveTax());
            f3 = (float)(f3 + d * localPriceGroup2.getIncludingTax());
          }
          else
          {
            f1 = (float)(f1 + d * localPriceGroup1.getPriceValue());
            f2 = (float)(f2 + d * localPriceGroup1.getPriceExclusiveTax());
            f3 = (float)(f3 + d * localPriceGroup1.getIncludingTax());
          }
        }
        else
        {
          f1 = (float)(f1 + d * localPriceGroup1.getPriceValue());
          f2 = (float)(f2 + d * localPriceGroup1.getPriceExclusiveTax());
          f3 = (float)(f3 + d * localPriceGroup1.getIncludingTax());
        }
    }
    Receipt localReceipt = new Receipt();
    localReceipt.setIkeaFamilySaving(f4);
    localReceipt.setTaxIncluded(f3);
    localReceipt.setTotal(f1);
    localReceipt.setTotalExcludingTax(f2);
    this.mShoppingCart.setReceipt(localReceipt);
  }

  private class SLMeta
    implements Persistable
  {
    private String BagId = "";
    private int discontinuedProducts = 0;
    private int lowOrOutofStockProducts = 0;
    private long mLastStockSyncedTime;
    private long mLastSyncedTime;
    private long mLastUdpateTime;
    private int updatedPriceProducts = 0;

    private SLMeta()
    {
    }

    public String getId()
    {
      return "slmeta";
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.cart.ShoppingCart
 * JD-Core Version:    0.6.2
 */