package com.ikea.kompis.stores;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.ikea.kompis.IkeaApplication;
import com.ikea.kompis.stores.event.FavButtonPressedEvent;
import com.ikea.kompis.stores.event.FavMarkerPositionChangeEvent;
import com.ikea.kompis.stores.event.HomeButtonPressedEvent;
import com.ikea.kompis.stores.event.StoreInfoSelectedEvent;
import com.ikea.kompis.stores.event.StoreMarkerSelectedEvent;
import com.ikea.kompis.stores.event.StoreSelectedEvent;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.stores.model.StoreLocation;
import com.ikea.shared.stores.model.StoreRef;
import com.ikea.shared.stores.model.StoreRefList;
import com.ikea.shared.user.event.FavStoreChangeEvent;
import com.ikea.shared.util.L;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import java.util.List;

public class MapWebViewFragment extends Fragment
{
  private boolean errorOnLoad = false;
  protected final Bus mBus = IkeaApplication.mBus;
  private EventHandler mEventHandler;
  private StoreRef mFavStore;
  private StoreRef mSelectedStore;
  private boolean mShowingCurrentLocation = false;
  protected StoreRefList mStoreRefList;
  private View rootView;
  private ImageView staticMapImageVIew;
  private LinearLayout storeMapReloadContainer;
  private ProgressBar storeMapSpinner;
  private WebView webView;

  private void initSelectedStore()
  {
    if ((this.mSelectedStore == null) && (this.mFavStore != null))
      this.mSelectedStore = this.mFavStore;
    if ((this.mSelectedStore == null) && (this.mFavStore == null) && (this.mStoreRefList != null) && (this.mStoreRefList.getStoreRef() != null) && (this.mStoreRefList.getStoreRef().size() > 0))
      this.mSelectedStore = ((StoreRef)this.mStoreRefList.getStoreRef().get(0));
  }

  @SuppressLint({"SetJavaScriptEnabled"})
  private void setupWebViewMap(View paramView)
  {
    initSelectedStore();
    this.mShowingCurrentLocation = false;
    if (this.mSelectedStore != null)
    {
      this.storeMapSpinner.setVisibility(0);
      this.storeMapReloadContainer.setVisibility(8);
      this.webView = ((WebView)paramView.findViewById(2131624182));
      this.webView.getSettings().setJavaScriptEnabled(true);
      this.webView.setWebViewClient(new WebViewClient()
      {
        public void onPageFinished(WebView paramAnonymousWebView, String paramAnonymousString)
        {
          if (!MapWebViewFragment.this.errorOnLoad)
          {
            MapWebViewFragment.this.webView.setVisibility(0);
            MapWebViewFragment.this.storeMapSpinner.setVisibility(8);
            MapWebViewFragment.this.storeMapReloadContainer.setVisibility(8);
          }
        }

        public void onReceivedError(WebView paramAnonymousWebView, int paramAnonymousInt, String paramAnonymousString1, String paramAnonymousString2)
        {
          MapWebViewFragment.access$302(MapWebViewFragment.this, true);
          MapWebViewFragment.this.webView.setVisibility(8);
          MapWebViewFragment.this.storeMapSpinner.setVisibility(8);
          MapWebViewFragment.this.storeMapReloadContainer.setVisibility(8);
          MapWebViewFragment.this.showStaticMapInstead();
        }

        public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString)
        {
          paramAnonymousWebView.loadUrl(paramAnonymousString);
          return true;
        }
      });
      if ((this.mFavStore == null) || (!this.mSelectedStore.getStoreNo().equals(this.mFavStore.getStoreNo())))
        break label167;
      this.mBus.post(new FavMarkerPositionChangeEvent(true));
    }
    while (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase("cn"))
    {
      this.webView.setVisibility(8);
      this.storeMapSpinner.setVisibility(8);
      this.storeMapReloadContainer.setVisibility(8);
      showStaticMapInstead();
      return;
      label167: this.mBus.post(new FavMarkerPositionChangeEvent(false));
    }
    if (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase("kr"))
    {
      this.webView.loadUrl("http://www.google.co.kr/maps/?q=" + this.mSelectedStore.getStoreLocation().getLat() + "," + this.mSelectedStore.getStoreLocation().getLong() + "&hl=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode());
      return;
    }
    this.webView.loadUrl("http://www.google.com/maps?q=" + this.mSelectedStore.getStoreLocation().getLat() + "," + this.mSelectedStore.getStoreLocation().getLong() + "&hl=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode());
  }

  @SuppressLint({"SetJavaScriptEnabled"})
  private void showCurrentLocation(View paramView, final Location paramLocation)
  {
    initSelectedStore();
    this.mShowingCurrentLocation = true;
    if (paramLocation != null)
    {
      this.storeMapSpinner.setVisibility(0);
      this.storeMapReloadContainer.setVisibility(8);
      this.webView = ((WebView)paramView.findViewById(2131624182));
      this.webView.getSettings().setJavaScriptEnabled(true);
      this.webView.setWebViewClient(new WebViewClient()
      {
        public void onPageFinished(WebView paramAnonymousWebView, String paramAnonymousString)
        {
          if (!MapWebViewFragment.this.errorOnLoad)
          {
            MapWebViewFragment.this.webView.setVisibility(0);
            MapWebViewFragment.this.storeMapSpinner.setVisibility(8);
            MapWebViewFragment.this.storeMapReloadContainer.setVisibility(8);
          }
        }

        public void onReceivedError(WebView paramAnonymousWebView, int paramAnonymousInt, String paramAnonymousString1, String paramAnonymousString2)
        {
          MapWebViewFragment.access$302(MapWebViewFragment.this, true);
          MapWebViewFragment.this.webView.setVisibility(8);
          MapWebViewFragment.this.storeMapSpinner.setVisibility(8);
          MapWebViewFragment.this.storeMapReloadContainer.setVisibility(8);
          MapWebViewFragment.this.showStaticMapCurrentInstead(paramLocation);
        }

        public boolean shouldOverrideUrlLoading(WebView paramAnonymousWebView, String paramAnonymousString)
        {
          paramAnonymousWebView.loadUrl(paramAnonymousString);
          return true;
        }
      });
      this.mBus.post(new FavMarkerPositionChangeEvent(false));
      if (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase("cn"))
      {
        this.webView.setVisibility(8);
        this.storeMapSpinner.setVisibility(8);
        this.storeMapReloadContainer.setVisibility(8);
        showStaticMapInstead();
      }
    }
    else
    {
      return;
    }
    if (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase("kr"))
    {
      if (AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode().equalsIgnoreCase("ko"))
      {
        this.webView.loadUrl("http://www.google.co.kr/maps/?q=" + paramLocation.getLatitude() + "," + paramLocation.getLongitude() + "&hl=ko-kr");
        return;
      }
      this.webView.loadUrl("http://www.google.co.kr/maps/?q=" + paramLocation.getLatitude() + "," + paramLocation.getLongitude());
      return;
    }
    this.webView.loadUrl("http://www.google.com/maps?q=" + paramLocation.getLatitude() + "," + paramLocation.getLongitude() + "&hl=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode());
  }

  private void showStaticMapCurrentInstead(Location paramLocation)
  {
    int i = 2 * com.ikea.shared.util.UiUtil.screenHeight(getActivity()) / 3;
    int j = (int)com.ikea.shared.util.UiUtil.screenWidth(getActivity());
    if (i > 600)
      i = 600;
    if (j > 500)
      j = 500;
    if (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase("cn"));
    for (String str = "http://api.map.baidu.com/staticimage?center=" + paramLocation.getLongitude() + "," + paramLocation.getLatitude() + "&width=" + j + "&height=" + i + "&zoom=16" + "&markers=" + paramLocation.getLongitude() + "," + paramLocation.getLatitude() + "&markerStyles=l,,0xff0000" + "&language=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode(); ; str = "https://maps.googleapis.com/maps/api/staticmap?center=" + paramLocation.getLatitude() + "," + paramLocation.getLongitude() + "&zoom=14&size=" + j + "x" + i + "&markers=color:" + "red" + "%7Clabel:" + " " + "%7C" + paramLocation.getLatitude() + "," + paramLocation.getLongitude() + "&sensor=false" + "&language=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode() + "&region =" + AppConfigManager.i(getActivity()).getAppConfigData().getRegionCode())
    {
      L.I("Loading Image" + str);
      com.ikea.kompis.util.UiUtil.loadImageAsync(getActivity(), this.staticMapImageVIew, str);
      return;
    }
  }

  private void showStaticMapInstead()
  {
    int i = 2 * com.ikea.shared.util.UiUtil.screenHeight(getActivity()) / 3;
    int j = (int)com.ikea.shared.util.UiUtil.screenWidth(getActivity());
    if (i > 600)
      i = 600;
    if (j > 500)
      j = 500;
    String str1 = "yellow";
    if ((this.mFavStore != null) && (this.mSelectedStore.getStoreNo().equals(this.mFavStore.getStoreNo())))
      str1 = "blue";
    String str3;
    if (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase("cn"))
    {
      str3 = "&markerStyles=l,,0xfecd2f";
      if ((this.mFavStore != null) && (this.mSelectedStore.getStoreNo().equals(this.mFavStore.getStoreNo())))
        str3 = "&markerStyles=l,,0x407AB1";
    }
    for (String str2 = "http://api.map.baidu.com/staticimage?center=" + this.mSelectedStore.getStoreLocation().getLong() + "," + this.mSelectedStore.getStoreLocation().getLat() + "&width=" + j + "&height=" + i + "&zoom=16" + "&markers=" + this.mSelectedStore.getStoreLocation().getLong() + "," + this.mSelectedStore.getStoreLocation().getLat() + str3 + "&language=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode(); ; str2 = "https://maps.googleapis.com/maps/api/staticmap?center=" + this.mSelectedStore.getStoreLocation().getLat() + "," + this.mSelectedStore.getStoreLocation().getLong() + "&zoom=14&size=" + j + "x" + i + "&markers=color:" + str1 + "%7Clabel:" + this.mSelectedStore.getStoreName() + "%7C" + this.mSelectedStore.getStoreLocation().getLat() + "," + this.mSelectedStore.getStoreLocation().getLong() + "&sensor=false" + "&language=" + AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode() + "&region =" + AppConfigManager.i(getActivity()).getAppConfigData().getRegionCode())
    {
      L.I("Loading Image" + str2);
      com.ikea.kompis.util.UiUtil.loadImageAsync(getActivity(), this.staticMapImageVIew, str2);
      return;
    }
  }

  public void onActivityCreated(Bundle paramBundle)
  {
    super.onActivityCreated(paramBundle);
  }

  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    Bundle localBundle = getArguments();
    if (localBundle != null)
    {
      if (localBundle.containsKey("STORE_LIST_DATA"))
        this.mStoreRefList = ((StoreRefList)localBundle.getSerializable("STORE_LIST_DATA"));
      if (localBundle.containsKey("FAV_STORE_DATA"))
        this.mFavStore = ((StoreRef)localBundle.getSerializable("FAV_STORE_DATA"));
      if (localBundle.containsKey("SELECTED_STORE_DATA"))
        this.mSelectedStore = ((StoreRef)localBundle.getSerializable("SELECTED_STORE_DATA"));
    }
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    if (paramBundle != null)
    {
      if (paramBundle.containsKey("STORE_LIST_DATA"))
      {
        this.mStoreRefList = ((StoreRefList)paramBundle.getSerializable("STORE_LIST_DATA"));
        paramBundle.remove("STORE_LIST_DATA");
      }
      if (paramBundle.containsKey("FAV_STORE_DATA"))
      {
        this.mFavStore = ((StoreRef)paramBundle.getSerializable("FAV_STORE_DATA"));
        paramBundle.remove("FAV_STORE_DATA");
      }
      if (paramBundle.containsKey("SELECTED_STORE_DATA"))
      {
        this.mSelectedStore = ((StoreRef)paramBundle.getSerializable("SELECTED_STORE_DATA"));
        paramBundle.remove("SELECTED_STORE_DATA");
      }
    }
    this.mEventHandler = new EventHandler(null);
    this.rootView = paramLayoutInflater.inflate(2130903102, paramViewGroup, false);
    ((TextView)this.rootView.findViewById(2131624186)).setText(getString(2131165678));
    this.storeMapReloadContainer = ((LinearLayout)this.rootView.findViewById(2131624184));
    this.storeMapSpinner = ((ProgressBar)this.rootView.findViewById(2131624187));
    this.staticMapImageVIew = ((ImageView)this.rootView.findViewById(2131624181));
    ((ImageView)this.rootView.findViewById(2131624185)).setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        MapWebViewFragment.this.setupWebViewMap(MapWebViewFragment.this.rootView);
      }
    });
    setupWebViewMap(this.rootView);
    return this.rootView;
  }

  public void onPause()
  {
    super.onPause();
    try
    {
      this.mBus.unregister(this.mEventHandler);
      return;
    }
    catch (Exception localException)
    {
      L.W("No event handler to unregister");
    }
  }

  public void onResume()
  {
    super.onResume();
    this.mBus.register(this.mEventHandler);
  }

  private class EventHandler
  {
    private EventHandler()
    {
    }

    @Subscribe
    public void handleFavButtonSelected(FavButtonPressedEvent paramFavButtonPressedEvent)
    {
      if ((MapWebViewFragment.this.getActivity() != null) && (MapWebViewFragment.this.mFavStore != null) && (MapWebViewFragment.this.mStoreRefList != null))
      {
        if ((MapWebViewFragment.this.mShowingCurrentLocation) || (MapWebViewFragment.this.mSelectedStore != MapWebViewFragment.this.mFavStore))
        {
          MapWebViewFragment.access$1202(MapWebViewFragment.this, MapWebViewFragment.this.mFavStore);
          MapWebViewFragment.this.mBus.post(new StoreMarkerSelectedEvent(MapWebViewFragment.this.mFavStore));
          MapWebViewFragment.this.setupWebViewMap(MapWebViewFragment.this.rootView);
        }
        return;
      }
      Toast.makeText(MapWebViewFragment.this.getActivity(), "No Favorite Yet", 0).show();
    }

    @Subscribe
    public void handleFavStoreChanged(FavStoreChangeEvent paramFavStoreChangeEvent)
    {
      if (MapWebViewFragment.this.getActivity() != null)
      {
        MapWebViewFragment.access$1102(MapWebViewFragment.this, paramFavStoreChangeEvent.favStore);
        MapWebViewFragment.access$1202(MapWebViewFragment.this, MapWebViewFragment.this.mFavStore);
        MapWebViewFragment.this.setupWebViewMap(MapWebViewFragment.this.rootView);
      }
    }

    @Subscribe
    public void handleHomeButtonSelected(HomeButtonPressedEvent paramHomeButtonPressedEvent)
    {
      Location localLocation = paramHomeButtonPressedEvent.currentLocation;
      if ((MapWebViewFragment.this.getActivity() != null) && (localLocation != null) && (localLocation.getLatitude() > -2147483648.0D) && (localLocation.getLongitude() > -2147483648.0D))
      {
        if (!MapWebViewFragment.this.mShowingCurrentLocation)
          MapWebViewFragment.this.showCurrentLocation(MapWebViewFragment.this.rootView, localLocation);
        return;
      }
      Toast.makeText(MapWebViewFragment.this.getActivity(), "Location not Found", 0).show();
    }

    @Subscribe
    public void handleStoreSelected(StoreInfoSelectedEvent paramStoreInfoSelectedEvent)
    {
      if (MapWebViewFragment.this.getActivity() != null)
      {
        StoreRef localStoreRef = paramStoreInfoSelectedEvent.store;
        if ((MapWebViewFragment.this.mShowingCurrentLocation) || ((localStoreRef != null) && (localStoreRef.getStoreLocation() != null) && ((MapWebViewFragment.this.mSelectedStore == null) || (!MapWebViewFragment.this.mSelectedStore.getStoreNo().equalsIgnoreCase(localStoreRef.getStoreNo())))))
        {
          MapWebViewFragment.access$1202(MapWebViewFragment.this, localStoreRef);
          MapWebViewFragment.this.setupWebViewMap(MapWebViewFragment.this.rootView);
        }
      }
    }

    @Subscribe
    public void handleStoreSelected(StoreSelectedEvent paramStoreSelectedEvent)
    {
      if (MapWebViewFragment.this.getActivity() != null)
      {
        StoreRef localStoreRef = paramStoreSelectedEvent.store;
        if ((MapWebViewFragment.this.mShowingCurrentLocation) || ((localStoreRef != null) && (localStoreRef.getStoreLocation() != null) && ((MapWebViewFragment.this.mSelectedStore == null) || (!MapWebViewFragment.this.mSelectedStore.getStoreNo().equalsIgnoreCase(localStoreRef.getStoreNo())))))
        {
          MapWebViewFragment.access$1202(MapWebViewFragment.this, localStoreRef);
          MapWebViewFragment.this.setupWebViewMap(MapWebViewFragment.this.rootView);
        }
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.stores.MapWebViewFragment
 * JD-Core Version:    0.6.2
 */