package com.ikea.kompis.setting;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.ikea.kompis.IkeaApplication;
import com.ikea.kompis.fte.FirstUserExperienceActivity;
import com.ikea.kompis.setting.event.ConfigSelectionDoneEvent;
import com.ikea.kompis.setting.event.CountryListCloseEvent;
import com.ikea.kompis.setting.event.ShowProgressEvent;
import com.ikea.kompis.user.event.LogoutDoneEvent;
import com.ikea.kompis.util.CustomPicker;
import com.ikea.kompis.util.CustomPicker.PickerModeEnum;
import com.ikea.kompis.util.CustomPicker.SelectionListener;
import com.ikea.kompis.util.CustomPopUp;
import com.ikea.kompis.util.CustomPopUp.CustomPopupClickListener;
import com.ikea.kompis.util.UiUtil;
import com.ikea.shared.AppConfigData;
import com.ikea.shared.AppConfigManager;
import com.ikea.shared.AppError;
import com.ikea.shared.analytics.UsageTracker;
import com.ikea.shared.browse.model.CatalogListBaseResponse;
import com.ikea.shared.browse.service.CatalogService;
import com.ikea.shared.cart.ShoppingCart;
import com.ikea.shared.config.model.Config;
import com.ikea.shared.config.model.Country;
import com.ikea.shared.config.model.KillSwitchConfig;
import com.ikea.shared.config.model.Language;
import com.ikea.shared.config.model.Languages;
import com.ikea.shared.config.model.Region;
import com.ikea.shared.config.model.RegionList;
import com.ikea.shared.config.service.ConfigService;
import com.ikea.shared.geofence.GeofenceService;
import com.ikea.shared.store.service.StoreCache;
import com.ikea.shared.user.model.User;
import com.ikea.shared.user.service.UserService;
import com.ikea.shared.util.Constant;
import com.ikea.shared.util.L;
import com.ikea.shared.util.ServiceCallback;
import com.squareup.otto.Bus;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.UnknownFormatConversionException;

public class CountryFragment extends Fragment
{
  private static final String CONFIRMATION_POPUP = "CONFIRMATION_POPUP";
  private static final String FROM_FUE = "FROM_FUE";
  private static final String SELECTED_APPLY_LOCAL_PROCESS = "SELECTED_APPLY_LOCAL_PROCESS";
  private static final String SELECTED_COUNTRY_DATA = "SELECTED_COUNTRY_DATA";
  private static final String SELECTED_LANGUAGE_CODE = "SELECTED_LANGUAGE_CODE";
  private static final String SELECTED_LANGUAGE_NAME = "SELECTED_LANGUAGE_NAME";
  private static final String SELECTED_LANGUAGE_PICKER = "SELECTED_LANGUAGE_PICKER";
  private static final String SELECTED_PICKER_INDEX = "SELECTED_PICKER_INDEX";
  private static final String SELECTED_REGION_DATA = "SELECTED_REGION_DATA";
  private static final String SELECTED_REGION_PICKER = "SELECTED_REGION_PICKER";
  private static final String USER_INFO_POPUP = "USER_INFO_POPUP";
  private boolean isApplyLocalInProcess = false;
  private boolean isFromFUE = false;
  private boolean isTablet;
  private final ServiceCallback<Boolean> mApplyLocalCallback = new ServiceCallback()
  {
    public void done(Boolean paramAnonymousBoolean, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      if (CountryFragment.this.getActivity() != null)
      {
        CountryFragment.this.hideLoadingDialog();
        if (!paramAnonymousBoolean.booleanValue());
      }
      else
      {
        try
        {
          Constant.i().setNewCampaignNeeded(true);
          AppConfigManager.i(CountryFragment.this.getActivity()).updateSelectedConfig(CountryFragment.this.mSelectedCountry, CountryFragment.this.mSelectedRegion, CountryFragment.this.mSelectedLanagugeName, CountryFragment.this.mSelectedLanagugeCode);
          LocaleManager.i(CountryFragment.this.getActivity(), CountryFragment.this.mBus).saveCurrentStore();
          StoreCache.i(CountryFragment.this.getActivity()).updateInStoreStatus(false, "");
          GeofenceService.i(CountryFragment.this.getActivity()).registerAllStore();
          CatalogService.i(CountryFragment.this.getActivity()).getTopElementsAsyncNew("functional", new ServiceCallback()
          {
            public void done(CatalogListBaseResponse paramAnonymous2CatalogListBaseResponse, AppError paramAnonymous2AppError, Exception paramAnonymous2Exception)
            {
            }
          });
          if (UserService.i(CountryFragment.this.getActivity()).getUser() != null)
            UserService.i(CountryFragment.this.getActivity()).getUser().resetLocalIkeaFamilyNumber();
          CountryFragment.this.mHandler.post(new Runnable()
          {
            public void run()
            {
              if (CountryFragment.this.mHeaderView != null)
                CountryFragment.this.mHeaderView.setText(CountryFragment.this.getActivity().getString(2131165636));
            }
          });
          if ((UserService.i(CountryFragment.this.getActivity()).getUser() == null) || (!UserService.i(CountryFragment.this.getActivity()).getUser().isLoggedIn()));
        }
        catch (IOException localIOException1)
        {
          try
          {
            UserService.i(CountryFragment.this.getActivity()).logout();
            UsageTracker.i().countryChanged(CountryFragment.this.getActivity());
            Constant.i().setSearchString("");
            Constant.i().setTopSearchString("");
            CountryFragment.this.close(true);
            CountryFragment.this.mBus.post(new LogoutDoneEvent());
            return;
            localIOException1 = localIOException1;
            localIOException1.printStackTrace();
          }
          catch (IOException localIOException2)
          {
            localIOException2.printStackTrace();
            return;
          }
        }
        UsageTracker.i().countryChanged(CountryFragment.this.getActivity());
        ShoppingCart.i(CountryFragment.this.getActivity()).reset();
        Constant.i().setSearchString("");
        Constant.i().setTopSearchString("");
        CountryFragment.this.close(true);
        return;
      }
      UiUtil.showNetworkToast(CountryFragment.this.getActivity(), false);
    }
  };
  private final Bus mBus = IkeaApplication.mBus;
  private CustomPopUp mConfirmationPop;
  private List<Country> mCountryList;
  private CountryListAdapter mCountryListAdapter;
  private ListView mCountryListView;
  private Handler mHandler;
  private TextView mHeaderView;
  private final ServiceCallback<KillSwitchConfig> mKLServiceCallback = new ServiceCallback()
  {
    public void done(KillSwitchConfig paramAnonymousKillSwitchConfig, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      CountryFragment.this.hideLoadingDialog();
      if ((paramAnonymousKillSwitchConfig != null) && (paramAnonymousKillSwitchConfig.isSuccessful()))
      {
        String str = CountryFragment.this.mSelectedCountry.getCountrycode();
        if (CountryFragment.this.mSelectedRegion != null)
          str = CountryFragment.this.mSelectedRegion.getValue();
        CountryFragment.this.showLoadingDialog();
        LocaleManager.i(CountryFragment.this.getActivity(), CountryFragment.this.mBus).applyLocal(CountryFragment.this.mApplyLocalCallback, str, CountryFragment.this.mSelectedLanagugeCode);
        return;
      }
      UiUtil.showNetworkToast(CountryFragment.this.getActivity(), false);
    }
  };
  private CustomPicker mLanguagePicker;
  private CustomPicker mRegionPicker;
  private Country mSelectedCountry = null;
  private String mSelectedLanagugeCode;
  private String mSelectedLanagugeName;
  private Region mSelectedRegion = null;
  private CustomPopUp mUserInfoPop;

  private void applyChangeLocale()
  {
    try
    {
      startApplyLocal();
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  private void close(boolean paramBoolean)
  {
    this.mBus.post(new CountryListCloseEvent(paramBoolean));
  }

  private Locale getDeviceLangauge()
  {
    Locale localLocale = Resources.getSystem().getConfiguration().locale;
    L.I("Device locale is " + localLocale.getLanguage());
    return localLocale;
  }

  private String getLanguageName(String paramString)
  {
    String str = "";
    List localList = this.mSelectedCountry.getLanguages().getLanguage();
    for (int i = 0; ; i++)
      if (i < localList.size())
      {
        if (paramString.equalsIgnoreCase(((Language)localList.get(i)).getmValue()))
          str = ((Language)localList.get(i)).getName();
      }
      else
        return str;
  }

  public static CountryFragment getNewInstance(boolean paramBoolean)
  {
    CountryFragment localCountryFragment = new CountryFragment();
    Bundle localBundle = new Bundle();
    localBundle.putBoolean("FROM_FUE", paramBoolean);
    localCountryFragment.setArguments(localBundle);
    return localCountryFragment;
  }

  private String getSelectedUserCountry()
  {
    return AppConfigManager.i(getActivity()).getAppConfigData().getCountryName();
  }

  private String getSelectedUserLanguages()
  {
    return AppConfigManager.i(getActivity()).getAppConfigData().getLanguageName();
  }

  private String getSelectedUserRegion()
  {
    return AppConfigManager.i(getActivity()).getAppConfigData().getRegionName();
  }

  private String getUserInfoMessage()
  {
    try
    {
      User localUser = UserService.i(getActivity()).getUser();
      boolean bool = ShoppingCart.i(getActivity()).isEmpty();
      if ((localUser != null) && (localUser.isLoggedIn()))
      {
        if (bool)
          return getString(2131165719);
        return getString(2131165720);
      }
      if (!bool)
      {
        String str = getString(2131165721);
        return str;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return "";
  }

  private void handleRegionForCountry()
  {
    if ((this.mSelectedCountry.getRegions() != null) && (this.mSelectedCountry.getRegions().getRegions() != null) && (!this.mSelectedCountry.getRegions().getRegions().isEmpty()))
    {
      showRegionPicker(-1);
      return;
    }
    this.mSelectedRegion = null;
    if (isDeviceLocaleSupported(this.mSelectedCountry.getLanguages().getLanguage()))
    {
      this.mSelectedLanagugeCode = Resources.getSystem().getConfiguration().locale.getLanguage().toLowerCase(Locale.US);
      this.mSelectedLanagugeName = getLanguageName(this.mSelectedLanagugeCode);
      applyChangeLocale();
      return;
    }
    if (isSelectedLangSupport(this.mSelectedCountry))
    {
      this.mSelectedLanagugeCode = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode();
      this.mSelectedLanagugeName = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageName();
      applyChangeLocale();
      return;
    }
    showConfirmationPop();
  }

  private void hideLoadingDialog()
  {
    this.isApplyLocalInProcess = false;
    this.mBus.post(new ShowProgressEvent(false));
    this.mCountryListView.setClickable(true);
  }

  private void initInfoPop()
  {
    if (this.mSelectedCountry.getCountryName().equalsIgnoreCase(getSelectedUserCountry()))
      if (this.mSelectedRegion != null)
      {
        if (this.mSelectedRegion.getName().equalsIgnoreCase(getSelectedUserRegion()))
          close(false);
      }
      else
      {
        close(false);
        return;
      }
    if (getUserInfoMessage().isEmpty())
    {
      handleRegionForCountry();
      return;
    }
    showUserInfoPop();
  }

  private boolean isDeviceLocaleSupported(List<Language> paramList)
  {
    Locale localLocale = Resources.getSystem().getConfiguration().locale;
    if ((localLocale != null) && (paramList != null) && (!paramList.isEmpty()))
    {
      L.I("Device locale is " + localLocale.getLanguage());
      for (int i = 0; i < paramList.size(); i++)
        if (((Language)paramList.get(i)).getValue().equalsIgnoreCase(localLocale.getLanguage()))
          return true;
    }
    return false;
  }

  private boolean isSelectedLangSupport(Country paramCountry)
  {
    try
    {
      AppConfigData localAppConfigData = AppConfigManager.i(getActivity()).getAppConfigData();
      boolean bool1 = false;
      if (localAppConfigData != null)
      {
        bool1 = false;
        if (paramCountry != null)
        {
          String str = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode();
          List localList1 = paramCountry.getLanguages().getLanguage();
          List localList2 = null;
          if (localList1 != null)
          {
            boolean bool2 = paramCountry.getLanguages().getLanguage().isEmpty();
            localList2 = null;
            if (!bool2)
              localList2 = paramCountry.getLanguages().getLanguage();
          }
          bool1 = false;
          if (str != null)
          {
            bool1 = false;
            if (localList2 != null)
            {
              boolean bool3 = localList2.isEmpty();
              bool1 = false;
              if (!bool3)
              {
                Iterator localIterator = localList2.iterator();
                boolean bool5;
                do
                {
                  Language localLanguage;
                  do
                  {
                    boolean bool4 = localIterator.hasNext();
                    bool1 = false;
                    if (!bool4)
                      break;
                    localLanguage = (Language)localIterator.next();
                  }
                  while (localLanguage == null);
                  bool5 = str.equalsIgnoreCase(localLanguage.getValue());
                }
                while (!bool5);
                bool1 = true;
              }
            }
          }
        }
      }
      return bool1;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return false;
  }

  private void setUpHeader(View paramView1, View paramView2)
  {
    if (this.isFromFUE)
    {
      paramView2.setVisibility(0);
      ((TextView)paramView1.findViewById(2131623960)).setText(2131165636);
      ((ImageView)paramView1.findViewById(2131624017)).setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          ((FirstUserExperienceActivity)CountryFragment.this.getActivity()).goBack();
        }
      });
      return;
    }
    paramView2.setVisibility(4);
  }

  private void showConfirmationPop()
  {
    this.mConfirmationPop = new CustomPopUp(getActivity(), getString(2131165251), getString(2131165282), getString(2131165299), "", "");
    this.mConfirmationPop.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        return false;
      }

      public void onCancel()
      {
        L.I("");
      }

      public void onLinkClick()
      {
        L.I("");
      }

      public void onPrimaryBtnClick()
      {
        if ((CountryFragment.this.mSelectedCountry.getLanguages().getLanguage().size() > 1) && (!CountryFragment.this.isDeviceLocaleSupported(CountryFragment.this.mSelectedCountry.getLanguages().getLanguage())))
        {
          CountryFragment.this.showLanguagePicker(-1);
          return;
        }
        if (CountryFragment.this.isDeviceLocaleSupported(CountryFragment.this.mSelectedCountry.getLanguages().getLanguage()))
        {
          CountryFragment.access$502(CountryFragment.this, CountryFragment.this.getDeviceLangauge().getLanguage());
          CountryFragment.access$702(CountryFragment.this, CountryFragment.this.getLanguageName(CountryFragment.this.mSelectedLanagugeCode));
        }
        while (true)
        {
          CountryFragment.this.applyChangeLocale();
          return;
          CountryFragment.access$502(CountryFragment.this, ((Language)CountryFragment.this.mSelectedCountry.getLanguages().getLanguage().get(0)).getValue());
          CountryFragment.access$702(CountryFragment.this, ((Language)CountryFragment.this.mSelectedCountry.getLanguages().getLanguage().get(0)).getName());
        }
      }

      public void onSecondaryBtnClick()
      {
        L.I("");
      }
    });
  }

  private void showLanguagePicker(int paramInt)
  {
    int i = paramInt;
    final List localList = this.mSelectedCountry.getLanguages().getLanguage();
    String[] arrayOfString = new String[localList.size()];
    for (int j = 0; j < localList.size(); j++)
      arrayOfString[j] = ((Language)localList.get(j)).getName();
    if (i == -1)
      i = 0;
    this.mLanguagePicker = new CustomPicker(getActivity(), CustomPicker.PickerModeEnum.NORMAL, false);
    this.mLanguagePicker.setDisplayValue(arrayOfString);
    this.mLanguagePicker.setTitle(getResources().getString(2131165640));
    this.mLanguagePicker.setSubTitle(getResources().getString(2131165639));
    this.mLanguagePicker.toggleCrossIcon(true);
    this.mLanguagePicker.showPicker(i, new CustomPicker.SelectionListener()
    {
      public void onCancel()
      {
        CountryFragment.this.showConfirmationPop();
      }

      public void onSelection(int paramAnonymousInt)
      {
        if (!UiUtil.isConnectionAvailable(CountryFragment.this.getActivity()))
        {
          UiUtil.showNetworkToast(CountryFragment.this.getActivity(), true);
          return;
        }
        try
        {
          CountryFragment.access$502(CountryFragment.this, ((Language)localList.get(paramAnonymousInt)).getValue());
          CountryFragment.access$702(CountryFragment.this, ((Language)localList.get(paramAnonymousInt)).getName());
          CountryFragment.this.applyChangeLocale();
          return;
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
        }
      }
    });
  }

  private void showLoadingDialog()
  {
    this.isApplyLocalInProcess = true;
    this.mBus.post(new ShowProgressEvent(true));
    this.mCountryListView.setClickable(false);
  }

  private void showRegionPicker(int paramInt)
  {
    int i = paramInt;
    final ArrayList localArrayList = new ArrayList();
    if ((this.mSelectedCountry.getRegions() != null) && (this.mSelectedCountry.getRegions().getRegions() != null) && (!this.mSelectedCountry.getRegions().getRegions().isEmpty()))
    {
      List localList = this.mSelectedCountry.getRegions().getRegions();
      for (int m = 0; m < localList.size(); m++)
        if (((Region)localList.get(m)).isEnabled())
          localArrayList.add(localList.get(m));
    }
    if (localArrayList != null)
    {
      if (!localArrayList.isEmpty())
        break label245;
      this.mSelectedRegion = null;
      if (isDeviceLocaleSupported(this.mSelectedCountry.getLanguages().getLanguage()))
      {
        this.mSelectedLanagugeCode = Locale.getDefault().getLanguage().toLowerCase(Locale.US);
        this.mSelectedLanagugeName = Locale.getDefault().getDisplayLanguage().toLowerCase(Locale.US);
        applyChangeLocale();
      }
    }
    else
    {
      return;
    }
    if (isSelectedLangSupport(this.mSelectedCountry))
    {
      this.mSelectedLanagugeCode = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode();
      this.mSelectedLanagugeName = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageName();
      applyChangeLocale();
      return;
    }
    showConfirmationPop();
    return;
    label245: if (localArrayList.size() == 1)
    {
      this.mSelectedRegion = ((Region)localArrayList.get(0));
      if (isDeviceLocaleSupported(this.mSelectedCountry.getLanguages().getLanguage()))
      {
        this.mSelectedLanagugeCode = Locale.getDefault().getLanguage().toLowerCase(Locale.US);
        this.mSelectedLanagugeName = Locale.getDefault().getDisplayLanguage().toLowerCase(Locale.US);
        applyChangeLocale();
        return;
      }
      if (isSelectedLangSupport(this.mSelectedCountry))
      {
        this.mSelectedLanagugeCode = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageCode();
        this.mSelectedLanagugeName = AppConfigManager.i(getActivity()).getAppConfigData().getLanguageName();
        applyChangeLocale();
        return;
      }
      showConfirmationPop();
      return;
    }
    String[] arrayOfString = new String[localArrayList.size()];
    for (int j = 0; j < localArrayList.size(); j++)
      arrayOfString[j] = ((Region)localArrayList.get(j)).getName();
    String str;
    if ((i == -1) && (AppConfigManager.i(getActivity()).getAppConfigData() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().getCountryCode().equalsIgnoreCase(this.mSelectedCountry.getCountrycode())))
      str = AppConfigManager.i(getActivity()).getAppConfigData().getRegionName();
    for (int k = 0; ; k++)
      if (k < arrayOfString.length)
      {
        if (str.equalsIgnoreCase(arrayOfString[k]))
          i = k;
      }
      else
      {
        this.mRegionPicker = new CustomPicker(getActivity(), CustomPicker.PickerModeEnum.NORMAL, false);
        this.mRegionPicker.setDisplayValue(arrayOfString);
        this.mRegionPicker.setTitle(getResources().getString(2131165642));
        this.mRegionPicker.setSubTitle(getResources().getString(2131165546));
        this.mRegionPicker.setEnableCrossIcon(true);
        this.mRegionPicker.showPicker(i, new CustomPicker.SelectionListener()
        {
          public void onCancel()
          {
          }

          public void onSelection(int paramAnonymousInt)
          {
            if (!UiUtil.isConnectionAvailable(CountryFragment.this.getActivity()))
            {
              UiUtil.showNetworkToast(CountryFragment.this.getActivity(), true);
              return;
            }
            CountryFragment.access$202(CountryFragment.this, (Region)localArrayList.get(paramAnonymousInt));
            CountryFragment.this.mSelectedCountry.setSectedRegion(CountryFragment.this.mSelectedRegion);
            if ((CountryFragment.this.mSelectedCountry.getLanguages().getLanguage().size() > 1) && (!CountryFragment.this.isDeviceLocaleSupported(CountryFragment.this.mSelectedCountry.getLanguages().getLanguage())))
            {
              CountryFragment.this.showLanguagePicker(-1);
              return;
            }
            if (CountryFragment.this.isDeviceLocaleSupported(CountryFragment.this.mSelectedCountry.getLanguages().getLanguage()))
            {
              CountryFragment.access$502(CountryFragment.this, CountryFragment.this.getDeviceLangauge().getLanguage());
              CountryFragment.access$702(CountryFragment.this, CountryFragment.this.getLanguageName(CountryFragment.this.mSelectedLanagugeCode));
            }
            while (true)
            {
              CountryFragment.this.applyChangeLocale();
              return;
              CountryFragment.access$502(CountryFragment.this, ((Language)CountryFragment.this.mSelectedCountry.getLanguages().getLanguage().get(0)).getValue());
              CountryFragment.access$702(CountryFragment.this, ((Language)CountryFragment.this.mSelectedCountry.getLanguages().getLanguage().get(0)).getName());
            }
          }
        });
        return;
      }
  }

  private void showUserInfoPop()
  {
    this.mUserInfoPop = new CustomPopUp(getActivity(), getString(2131165295), getString(2131165282), getUserInfoMessage(), "", "");
    this.mUserInfoPop.show(new CustomPopUp.CustomPopupClickListener()
    {
      public boolean onBackKeyPressed()
      {
        return false;
      }

      public void onCancel()
      {
        L.I("");
      }

      public void onLinkClick()
      {
        L.I("");
      }

      public void onPrimaryBtnClick()
      {
        CountryFragment.this.handleRegionForCountry();
      }

      public void onSecondaryBtnClick()
      {
        CountryFragment.this.close(false);
      }
    });
  }

  private void startApplyLocal()
  {
    showLoadingDialog();
    this.mApplyLocalCallback.markValid();
    this.mKLServiceCallback.markValid();
    ConfigService.i(getActivity()).getConfigurationKSAsync(this.mKLServiceCallback, this.mSelectedCountry.getCountrycode(), this.mSelectedLanagugeCode);
  }

  public void getCountryAndRefreshCountryList(List<Country> paramList)
  {
    this.mCountryList = paramList;
    if (this.mCountryListAdapter != null)
      this.mCountryListAdapter.updateCountry(paramList);
  }

  public void onActivityCreated(@Nullable Bundle paramBundle)
  {
    super.onActivityCreated(paramBundle);
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_COUNTRY_DATA")))
      this.mSelectedCountry = ((Country)paramBundle.getSerializable("SELECTED_COUNTRY_DATA"));
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_REGION_DATA")))
      this.mSelectedRegion = ((Region)paramBundle.getSerializable("SELECTED_REGION_DATA"));
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_LANGUAGE_CODE")))
      this.mSelectedLanagugeCode = paramBundle.getString("SELECTED_LANGUAGE_CODE");
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_LANGUAGE_NAME")))
      this.mSelectedLanagugeName = paramBundle.getString("SELECTED_LANGUAGE_NAME");
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_REGION_PICKER")) && (paramBundle.getBoolean("SELECTED_REGION_PICKER")))
      showRegionPicker(paramBundle.getInt("SELECTED_PICKER_INDEX"));
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_LANGUAGE_PICKER")) && (paramBundle.getBoolean("SELECTED_LANGUAGE_PICKER")))
      showLanguagePicker(paramBundle.getInt("SELECTED_PICKER_INDEX"));
    if ((paramBundle != null) && (paramBundle.containsKey("CONFIRMATION_POPUP")) && (paramBundle.getBoolean("CONFIRMATION_POPUP")))
      showConfirmationPop();
    if ((paramBundle != null) && (paramBundle.containsKey("SELECTED_APPLY_LOCAL_PROCESS")))
      this.isApplyLocalInProcess = paramBundle.getBoolean("SELECTED_APPLY_LOCAL_PROCESS");
    if ((paramBundle != null) && (paramBundle.containsKey("USER_INFO_POPUP")) && (paramBundle.getBoolean("USER_INFO_POPUP")))
      showUserInfoPop();
  }

  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    Bundle localBundle = getArguments();
    if ((localBundle != null) && (localBundle.containsKey("FROM_FUE")))
      this.isFromFUE = localBundle.getBoolean("FROM_FUE");
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.isTablet = UiUtil.isTablet(getActivity());
    if ((ConfigService.i(getActivity()) != null) && (ConfigService.i(getActivity()).getCachedConfig() != null))
      this.mCountryList = ConfigService.i(getActivity()).getCachedConfig().getCountry();
    this.mHandler = new Handler();
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView1 = paramLayoutInflater.inflate(2130903070, paramViewGroup, false);
    this.mCountryListView = ((ListView)localView1.findViewById(2131624073));
    View localView2 = localView1.findViewById(2131623959);
    this.mHeaderView = ((TextView)localView1.findViewById(2131624072));
    if (this.isTablet)
    {
      this.mHeaderView.setVisibility(0);
      if (this.isFromFUE)
        localView2.setVisibility(8);
    }
    while (true)
    {
      this.mCountryListAdapter = new CountryListAdapter(getActivity(), this.mCountryList);
      this.mCountryListView.setAdapter(this.mCountryListAdapter);
      this.mCountryListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
      {
        public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
        {
          if ((CountryFragment.this.isTablet) && (CountryFragment.this.mHeaderView != null))
            CountryFragment.this.mHeaderView.setText(CountryFragment.this.getActivity().getString(2131165636));
          if (!UiUtil.isConnectionAvailable(CountryFragment.this.getActivity()))
            UiUtil.showNetworkToast(CountryFragment.this.getActivity(), true);
          while ((paramAnonymousInt < 0) || (paramAnonymousInt >= CountryFragment.this.mCountryListView.getCount()))
            return;
          CountryFragment.access$102(CountryFragment.this, CountryFragment.this.mCountryListAdapter.getItem(paramAnonymousInt));
          if (CountryFragment.this.isFromFUE)
          {
            CountryFragment.this.mBus.post(new ConfigSelectionDoneEvent(CountryFragment.this.mSelectedCountry, paramAnonymousInt));
            return;
          }
          CountryFragment.this.initInfoPop();
        }
      });
      return localView1;
      localView2.setVisibility(4);
      continue;
      this.mHeaderView.setVisibility(8);
      setUpHeader(localView1, localView2);
    }
  }

  public void onPause()
  {
    super.onPause();
    this.mApplyLocalCallback.markInvalid();
    this.mKLServiceCallback.markInvalid();
    try
    {
      this.mBus.unregister(this);
      return;
    }
    catch (Exception localException)
    {
      L.W("No event handler to unregister");
    }
  }

  public void onResume()
  {
    super.onResume();
    this.mApplyLocalCallback.markValid();
    this.mKLServiceCallback.markValid();
    if (this.isApplyLocalInProcess)
      startApplyLocal();
    this.mBus.register(this);
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    if (this.mConfirmationPop != null)
      paramBundle.putBoolean("CONFIRMATION_POPUP", this.mConfirmationPop.isShowing());
    if (this.mUserInfoPop != null)
      paramBundle.putBoolean("USER_INFO_POPUP", this.mUserInfoPop.isShowing());
    if (this.mRegionPicker != null)
    {
      paramBundle.putBoolean("SELECTED_REGION_PICKER", this.mRegionPicker.isPickerVisible());
      paramBundle.putInt("SELECTED_PICKER_INDEX", this.mRegionPicker.getCurrentSelectedValue());
    }
    if (this.mLanguagePicker != null)
    {
      paramBundle.putBoolean("SELECTED_LANGUAGE_PICKER", this.mLanguagePicker.isPickerVisible());
      paramBundle.putInt("SELECTED_PICKER_INDEX", this.mLanguagePicker.getCurrentSelectedValue());
    }
    paramBundle.putString("SELECTED_LANGUAGE_CODE", this.mSelectedLanagugeCode);
    paramBundle.putString("SELECTED_LANGUAGE_NAME", this.mSelectedLanagugeName);
    paramBundle.putSerializable("SELECTED_COUNTRY_DATA", this.mSelectedCountry);
    paramBundle.putSerializable("SELECTED_REGION_DATA", this.mSelectedRegion);
    paramBundle.putBoolean("SELECTED_APPLY_LOCAL_PROCESS", this.isApplyLocalInProcess);
    this.mApplyLocalCallback.markInvalid();
    this.mKLServiceCallback.markInvalid();
  }

  public void refreshCountryList()
  {
    if (this.mCountryListAdapter != null)
      this.mCountryListAdapter.notifyDataSetChanged();
  }

  public void setSelectedCountry(int paramInt)
  {
    if (this.mCountryListAdapter != null)
      this.mCountryListAdapter.notifyDataSetChanged();
    if (this.mCountryListView != null)
      this.mCountryListView.setSelection(paramInt);
  }

  public void stopApplyLocale()
  {
    if (this.mApplyLocalCallback != null)
      this.mApplyLocalCallback.markInvalid();
    if (this.mKLServiceCallback != null)
      this.mKLServiceCallback.markInvalid();
  }

  public class CountryListAdapter extends BaseAdapter
  {
    private final Context mContext;
    private List<Country> mCountryList;
    private final LayoutInflater mInflater;

    public CountryListAdapter(List<Country> arg2)
    {
      Object localObject1;
      this.mContext = localObject1;
      this.mInflater = ((LayoutInflater)localObject1.getSystemService("layout_inflater"));
      Object localObject2;
      this.mCountryList = localObject2;
    }

    public int getCount()
    {
      if (this.mCountryList != null)
        return this.mCountryList.size();
      return 0;
    }

    public Country getItem(int paramInt)
    {
      return (Country)this.mCountryList.get(paramInt);
    }

    public long getItemId(int paramInt)
    {
      return paramInt;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      View localView = paramView;
      ViewHolder localViewHolder;
      if (localView == null)
      {
        localViewHolder = new ViewHolder();
        localView = this.mInflater.inflate(2130903069, paramViewGroup, false);
        localViewHolder.countryName = ((TextView)localView.findViewById(2131624070));
        localViewHolder.countryLangInfo = ((TextView)localView.findViewById(2131624071));
        localView.setTag(localViewHolder);
      }
      while (true)
      {
        localViewHolder.countryName.setText(getItem(paramInt).getCountryName());
        String str1;
        Object localObject;
        if ((CountryFragment.this.getSelectedUserCountry() != null) && (CountryFragment.this.getSelectedUserCountry().equalsIgnoreCase(getItem(paramInt).getCountryName())))
        {
          localViewHolder.countryName.setSelected(true);
          if (CountryFragment.this.isSelectedLangSupport(getItem(paramInt)))
          {
            str1 = CountryFragment.this.getSelectedUserLanguages();
            localObject = "";
          }
        }
        else
        {
          try
          {
            String str2 = this.mContext.getString(2131165363, new Object[] { str1 });
            localObject = str2;
            SpannableString localSpannableString = new SpannableString((CharSequence)localObject);
            int i = ((String)localObject).indexOf(str1);
            localSpannableString.setSpan(new ForegroundColorSpan(this.mContext.getResources().getColor(2131492870)), i, i + str1.length(), 0);
            localViewHolder.countryLangInfo.setText(localSpannableString);
            localViewHolder.countryLangInfo.setVisibility(0);
            return localView;
            localViewHolder = (ViewHolder)localView.getTag();
            continue;
            localViewHolder.countryName.setSelected(false);
          }
          catch (UnknownFormatConversionException localUnknownFormatConversionException)
          {
            while (true)
              localUnknownFormatConversionException.printStackTrace();
          }
          catch (Exception localException)
          {
            while (true)
              localException.printStackTrace();
          }
        }
      }
      localViewHolder.countryLangInfo.setVisibility(4);
      return localView;
    }

    public void updateCountry(List<Country> paramList)
    {
      this.mCountryList = paramList;
      notifyDataSetChanged();
    }

    public class ViewHolder
    {
      public TextView countryLangInfo;
      public TextView countryName;

      public ViewHolder()
      {
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.setting.CountryFragment
 * JD-Core Version:    0.6.2
 */