package com.ikea.kompis.extendedcontent;

import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import com.ikea.ec.analytic.ECAnalyticInfo;
import com.ikea.kompis.BaseActivity;
import com.ikea.kompis.user.LoginActivity;
import com.ikea.kompis.util.CustomPopUp;
import com.ikea.kompis.util.CustomPopUp.CustomPopupClickListener;
import com.ikea.kompis.util.UiUtil;
import com.ikea.publishingplatform.model.PublishingPlatformResponse;
import com.ikea.publishingplatform.service.PublishingPlatformService;
import com.ikea.publishingplatform.service.PublishingPlatformServiceCallback;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.browse.model.ProductListing;
import com.ikea.shared.browse.service.CatalogService;
import com.ikea.shared.cart.ShoppingCart;
import com.ikea.shared.products.model.RetailItemCommunication;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.util.L;
import com.ikea.shared.util.NetworkUtil;
import com.ikea.shared.util.ServiceCallback;
import com.ikea.vmob.model.VmobProductDetail;
import com.ikea.vmob.service.VmobService;
import com.ikea.vmob.service.VmobServiceCallback;
import java.util.List;

public abstract class ECStuffActivity extends BaseActivity
  implements LoadingDialogEvent
{
  private ECAnalyticInfo mAnalyticInfo;
  protected Uri mLaunchedFromCatalogueURI;
  protected boolean mPopUpVisible = false;
  private PublishingPlatformServiceCallback<PublishingPlatformResponse> mPublishingPlatformServiceCallback = new PublishingPlatformServiceCallback()
  {
    public void done(PublishingPlatformResponse paramAnonymousPublishingPlatformResponse, com.ikea.publishingplatform.service.AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      ECStuffActivity.this.dismisLoadingContentDialog();
      ECStuffActivity.this.mVmobServiceCallback.markInvalid();
      if ((paramAnonymousPublishingPlatformResponse != null) && (paramAnonymousException == null) && (!paramAnonymousPublishingPlatformResponse.isError()))
      {
        if (!TextUtils.isEmpty(paramAnonymousPublishingPlatformResponse.getUrl()))
        {
          ECStuffActivity.this.trackInspirationTag(paramAnonymousPublishingPlatformResponse.getContentId());
          ECStuffActivity.this.launchWebView(paramAnonymousPublishingPlatformResponse);
          return;
        }
        ECStuffActivity.this.nonProductScan();
        ECStuffActivity.this.showErrorMessage();
        return;
      }
      ECStuffActivity.this.nonProductScan();
      ECStuffActivity.this.showErrorMessage();
    }
  };
  private ServiceCallback<ProductListing> mServiceCallback = new ServiceCallback()
  {
    public void done(ProductListing paramAnonymousProductListing, com.ikea.shared.AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      ECStuffActivity.this.dismisLoadingContentDialog();
      if ((paramAnonymousProductListing != null) && (paramAnonymousProductListing.isSuccessful()) && (paramAnonymousProductListing.getRetailItemComm() != null) && (!paramAnonymousProductListing.getRetailItemComm().isEmpty()))
      {
        ECStuffActivity.this.launchPipScreen(paramAnonymousProductListing);
        return;
      }
      ECStuffActivity.this.mVmobServiceCallback.markInvalid();
      ECStuffActivity.this.nonProductScan();
      ECStuffActivity.this.showErrorMessage();
    }
  };
  private VmobServiceCallback<VmobProductDetail> mVmobServiceCallback = new VmobServiceCallback()
  {
    public void done(VmobProductDetail paramAnonymousVmobProductDetail, com.ikea.vmob.service.AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      if (paramAnonymousVmobProductDetail != null)
      {
        ECStuffActivity.this.getProductInformation(paramAnonymousVmobProductDetail);
        return;
      }
      ECStuffActivity.this.nonProductScan();
      ECStuffActivity.this.showErrorMessage();
      ECStuffActivity.this.mVmobServiceCallback.markInvalid();
    }
  };
  protected ExtentedContentCostant.EC_ScanInformation scanInformation;
  protected String scanSource = ExtentedContentCostant.EC_ScanSource.EXTERNALAPP.toString();
  protected String scanType = ExtentedContentCostant.EC_ScanType.NFC.toString();
  private String storeId;
  private String storeName;

  private void handleAction(Intent paramIntent)
  {
    if ("android.nfc.action.NDEF_DISCOVERED".equals(paramIntent.getAction()))
      this.mLaunchedFromCatalogueURI = ((Uri)paramIntent.getExtras().getParcelable("LaunchedFromCatalogue"));
    if (this.mLaunchedFromCatalogueURI != null)
      handleECUris(paramIntent);
  }

  private void nonProductScan()
  {
    if (UiUtil.isLandscape(this));
    for (String str1 = "landscape"; ; str1 = "portrait")
    {
      String str2 = ExtentedContentCostant.EC_ScanInformation.NONCONTENTSCAN.toString();
      this.mAnalyticInfo = new ECAnalyticInfo("0", this.scanType, str1, str2, this.scanSource, this.storeName, this.storeId, "", "");
      UsageTracker.i().scanNonProduct(this, this.mAnalyticInfo);
      return;
    }
  }

  private void showWrongCountryMessage(VmobProductDetail paramVmobProductDetail)
  {
    String str1 = new ECCountryUtils().getCountryNameFromCode(this, paramVmobProductDetail.getMarket());
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = ("<b>" + str1 + "</b>");
    String str2 = getString(2131165763, arrayOfObject);
    WrongCountryMessageDialog localWrongCountryMessageDialog = new WrongCountryMessageDialog();
    Bundle localBundle = new Bundle();
    localBundle.putString("title", getString(2131165765));
    localBundle.putString("message", "");
    localBundle.putString("primarybtn", getString(2131165517));
    localBundle.putString("secondrybtn", "");
    localWrongCountryMessageDialog.setArguments(localBundle);
    localWrongCountryMessageDialog.setTitle(Html.fromHtml(str2));
    localWrongCountryMessageDialog.show(getFragmentManager(), WrongCountryMessageDialog.class.getName(), true, null);
  }

  private void trackExtendedContentUsages(RetailItemCommunication paramRetailItemCommunication)
  {
    if (UiUtil.isLandscape(this));
    for (String str1 = "landscape"; ; str1 = "portrait")
    {
      String str2 = ExtentedContentCostant.EC_ScanInformation.PRODUUCTSCAN.toString();
      this.mAnalyticInfo = new ECAnalyticInfo("0", this.scanType, str1, str2, this.scanSource, this.storeName, this.storeId, "", "product information page>prodview");
      UsageTracker.i().scanIformationalContent(this, this.mAnalyticInfo, paramRetailItemCommunication);
      return;
    }
  }

  protected void callVmobApi(String paramString)
  {
    if (NetworkUtil.isConnectionAvailable(this))
    {
      if (this.mVmobServiceCallback.isValid())
        return;
      showECContentLoadingDialog(this);
      this.mServiceCallback.markValid();
      this.mPublishingPlatformServiceCallback.markValid();
      this.mVmobServiceCallback.markValid();
      String str2 = "https://" + getResources().getString(2131165809) + getString(2131165786);
      VmobService.i(this).fetchTagDeatils(str2 + paramString, this.mVmobServiceCallback);
      return;
    }
    String str1 = getString(2131165474);
    showMessage(getString(2131165517), str1);
  }

  protected void getInpirationalContent(VmobProductDetail paramVmobProductDetail)
  {
    AppConfigData localAppConfigData = AppConfigManager.i(this).getAppConfigData();
    String str1 = localAppConfigData.getCountryCode();
    String str2 = localAppConfigData.getLanguageCode();
    PublishingPlatformService.i(this).fetchInspirationContent(paramVmobProductDetail.getContentId(), paramVmobProductDetail.getMarket(), str1 + "_" + str2, this.mPublishingPlatformServiceCallback);
  }

  protected void getProductInformation(VmobProductDetail paramVmobProductDetail)
  {
    if ((paramVmobProductDetail != null) && (paramVmobProductDetail.getMarket() != null))
    {
      if (!AppConfigManager.i(this).getAppConfigData().getCountryCode().equalsIgnoreCase(paramVmobProductDetail.getMarket()))
      {
        this.mVmobServiceCallback.markInvalid();
        dismisLoadingContentDialog();
        showWrongCountryMessage(paramVmobProductDetail);
        return;
      }
      if (paramVmobProductDetail.getType().equalsIgnoreCase("Informational"))
      {
        CatalogService.i(getApplicationContext()).searchItemAsync(paramVmobProductDetail.getProductId(), null, this.mServiceCallback);
        return;
      }
      getInpirationalContent(paramVmobProductDetail);
      return;
    }
    this.mVmobServiceCallback.markInvalid();
    showErrorMessage();
  }

  protected void handleECUris(Intent paramIntent)
  {
    if ((paramIntent != null) && (paramIntent.hasExtra("action")))
      this.scanType = paramIntent.getExtras().getString("action");
    if (!new ECCountryUtils().isECEnabledInCurrentStore(this))
      showWrongStoreMessage();
    while ((this.mLaunchedFromCatalogueURI == null) || (!this.mLaunchedFromCatalogueURI.toString().contains("https://in-store-experience.vmobapps.com/redirect/tag/")))
      return;
    callVmobApi(this.mLaunchedFromCatalogueURI.toString().replaceFirst("https://in-store-experience.vmobapps.com/redirect/tag/", ""));
  }

  protected void launchPipScreen(ProductListing paramProductListing)
  {
    RetailItemCommunication localRetailItemCommunication = (RetailItemCommunication)paramProductListing.getRetailItemComm().get(0);
    trackExtendedContentUsages(localRetailItemCommunication);
    this.mVmobServiceCallback.markInvalid();
    if (ShoppingCart.i(this).isProductCollected(localRetailItemCommunication.getItemNo()))
    {
      showCollectedPopUp(localRetailItemCommunication);
      return;
    }
    moveToNext(localRetailItemCommunication);
  }

  protected void moveToNext(RetailItemCommunication paramRetailItemCommunication)
  {
    if ((paramRetailItemCommunication != null) && (paramRetailItemCommunication.getItemNo() != null))
    {
      String str1 = paramRetailItemCommunication.getItemNo().trim();
      String str2 = paramRetailItemCommunication.getItemType().trim();
      String str3 = paramRetailItemCommunication.getGPRItemOrigin();
      boolean bool = ShoppingCart.i(this).isExits(str1);
      Intent localIntent = new Intent(this, ECProductDetailsActivity.class);
      if (localIntent != null)
      {
        localIntent.putExtra("PRODUCT_ID", str1);
        localIntent.putExtra("FROM_SCAN", true);
        localIntent.putExtra("PRODUCT_NAME", str2);
        localIntent.putExtra("GPR_ORIGIN", str3);
        localIntent.putExtra("FOR_MINI_PIP", bool);
      }
      startActivity(localIntent);
      overridePendingTransition(2130968587, 2130968584);
      return;
    }
    showErrorMessage();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    StoreRef localStoreRef = AppConfigManager.i(this).getAppConfigData().getFavStore();
    if (localStoreRef != null)
    {
      this.storeId = localStoreRef.getId();
      this.storeName = localStoreRef.getStoreName();
    }
  }

  public void onEvent()
  {
    dismisLoadingContentDialog();
    this.mLaunchedFromCatalogueURI = null;
    this.mServiceCallback.markInvalid();
    this.mPublishingPlatformServiceCallback.markInvalid();
    this.mVmobServiceCallback.markInvalid();
  }

  protected void onNewIntent(Intent paramIntent)
  {
    super.onNewIntent(paramIntent);
    if ((getIntent() != null) && ("android.nfc.action.NDEF_DISCOVERED".equals(getIntent().getAction())));
    for (this.scanType = ExtentedContentCostant.EC_ScanType.NFC.toString(); ((this instanceof ECWelcomeActivity)) || ((this instanceof ECLoginActivity)) || ((this instanceof LoginActivity)); this.scanType = ExtentedContentCostant.EC_ScanType.QRCODE.toString())
      return;
    handleAction(paramIntent);
  }

  protected void onStop()
  {
    onEvent();
    super.onStop();
  }

  protected void openShoppingList(RetailItemCommunication paramRetailItemCommunication)
  {
    String str = paramRetailItemCommunication.getItemNo().trim();
    Intent localIntent = new Intent(this, ECWelcomeActivity.class);
    localIntent.putExtra("SCAN_PRODUCT_ID", str);
    startActivity(localIntent);
    overridePendingTransition(2130968587, 2130968584);
  }

  protected void showCollectedPopUp(final RetailItemCommunication paramRetailItemCommunication)
  {
    WrongCountryMessageDialog localWrongCountryMessageDialog = new WrongCountryMessageDialog();
    Bundle localBundle = new Bundle();
    localBundle.putString("title", getString(2131165312));
    localBundle.putString("message", "");
    localBundle.putString("primarybtn", getString(2131165724));
    localBundle.putString("secondrybtn", getString(2131165282));
    localWrongCountryMessageDialog.setArguments(localBundle);
    localWrongCountryMessageDialog.show(getFragmentManager(), WrongCountryMessageDialog.class.getName(), true, new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        ECStuffActivity.this.openShoppingList(paramRetailItemCommunication);
      }
    });
  }

  protected void showMessage(String paramString1, String paramString2)
  {
    CustomPopUp localCustomPopUp = new CustomPopUp(this, paramString1, paramString2);
    this.mPopUpVisible = true;
    localCustomPopUp.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        return false;
      }

      public void onCancel()
      {
        L.I(this, " IkeaPopUp onCancel ");
        ECStuffActivity.this.mPopUpVisible = false;
      }

      public void onLinkClick()
      {
        L.I(this, " IkeaPopUp onLickClick ");
        ECStuffActivity.this.mPopUpVisible = false;
      }

      public void onPrimaryBtnClick()
      {
        ECStuffActivity.this.mPopUpVisible = false;
      }

      public void onSecondaryBtnClick()
      {
        L.I("");
      }
    });
  }

  protected void showMessage(String paramString1, String paramString2, CharSequence paramCharSequence)
  {
    ECCustomPopUp localECCustomPopUp = new ECCustomPopUp(this, paramString1, paramString2);
    localECCustomPopUp.setTitleDesc(paramCharSequence);
    this.mPopUpVisible = true;
    localECCustomPopUp.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        return false;
      }

      public void onCancel()
      {
        L.I(this, " IkeaPopUp onCancel ");
        ECStuffActivity.this.mPopUpVisible = false;
      }

      public void onLinkClick()
      {
        L.I(this, " IkeaPopUp onLickClick ");
        ECStuffActivity.this.mPopUpVisible = false;
      }

      public void onPrimaryBtnClick()
      {
        ECStuffActivity.this.mPopUpVisible = false;
      }

      public void onSecondaryBtnClick()
      {
        L.I("");
      }
    });
  }

  protected void trackInspirationTag(String paramString)
  {
    if (UiUtil.isLandscape(this));
    for (String str1 = "landscape"; ; str1 = "portrait")
    {
      String str2 = ExtentedContentCostant.EC_ScanInformation.INSPIRATIONALSCAN.toString();
      this.mAnalyticInfo = new ECAnalyticInfo("0", this.scanType, str1, str2, this.scanSource, this.storeName, this.storeId, "Inspirational page", "", paramString);
      UsageTracker.i().scanInspirationalContent(this, this.mAnalyticInfo);
      return;
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.extendedcontent.ECStuffActivity
 * JD-Core Version:    0.6.2
 */