package com.ikea.kompis.campaign;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.ikea.kompis.WelcomeActivity;
import com.ikea.kompis.browse.event.BrowseProductEvent;
import com.ikea.kompis.campaign.event.WelcomeResumedEvent;
import com.ikea.kompis.fragments.TopLevelContentFragment;
import com.ikea.kompis.network.event.NetworkStatusEvent;
import com.ikea.kompis.scan.event.ScanEvent;
import com.ikea.kompis.stores.FavouriteStore;
import com.ikea.kompis.stores.event.FavouriteStoreEvent;
import com.ikea.kompis.stores.event.GoToStoreLocatorEvent;
import com.ikea.kompis.util.CenteredImageSpan;
import com.ikea.kompis.util.DateUtil;
import com.ikea.kompis.util.KillSwitchUtil;
import com.ikea.kompis.util.UiUtil;
import com.ikea.kompis.view.LeaveVerticalScrollForParentViewPager;
import com.ikea.kompis.view.WelcomeAlertLayout;
import com.ikea.shared.AppCache;
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.campaign.model.CampaignList;
import com.ikea.shared.campaign.model.CampaignResponse;
import com.ikea.shared.campaign.service.CampaignService;
import com.ikea.shared.config.model.Country;
import com.ikea.shared.config.model.KillSwitchConfig;
import com.ikea.shared.event.KillSwitchEvent;
import com.ikea.shared.location.event.StoreInOutEvent;
import com.ikea.shared.notification.NotificationService;
import com.ikea.shared.notification.StoreOpenInfo;
import com.ikea.shared.notification.WelcomeNotification;
import com.ikea.shared.shopping.event.SLChangedEvent;
import com.ikea.shared.shopping.event.ShoppingListRefreshEvent;
import com.ikea.shared.store.service.StoreCache;
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.Constant;
import com.ikea.shared.util.L;
import com.ikea.shared.util.ServiceCallback;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import com.viewpagerindicator.CirclePageIndicator;
import java.io.IOException;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UnknownFormatConversionException;

public class WelcomeFragment extends TopLevelContentFragment
{
  private static final int[] IN_STORE_BG_IMAGE_LIST = { 2130837819, 2130837820, 2130837821 };
  private static final String KEY_SELECTED_CAMPAIGN = "KEY_SELECTED_CAMPAIGN";
  private static final int[] OUT_STORE_BG_IMAGE_LIST = { 2130837840, 2130837841, 2130837842 };
  private static final String SCROLL_X_KEY = "SCROLL_X_INDEX";
  private static final String SCROLL_Y_KEY = "SCROLL_Y_INDEX";
  private boolean isCampaignFetching = false;
  private CampaignPagerAdapter mAdapter;
  private LinearLayout mAlertHolder;
  private final ServiceCallback<CampaignResponse> mCampaignServiceCallback = new ServiceCallback()
  {
    public void done(CampaignResponse paramAnonymousCampaignResponse, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      WelcomeFragment.access$002(WelcomeFragment.this, false);
      Constant.i().setNewCampaignNeeded(false);
      if (WelcomeFragment.this.isAdded())
      {
        if ((paramAnonymousCampaignResponse == null) || (WelcomeFragment.this.getActivity() == null))
          break label170;
        if ((paramAnonymousCampaignResponse.getCampaignList() != null) && (paramAnonymousCampaignResponse.getCampaignList().getCampaign() != null) && (paramAnonymousCampaignResponse.getCampaignList().getCampaign().size() > 0))
        {
          WelcomeFragment.access$102(WelcomeFragment.this, new CampaignPagerAdapter(WelcomeFragment.this.getActivity(), paramAnonymousCampaignResponse.getCampaignList(), WelcomeFragment.this.mBus));
          WelcomeFragment.this.showCampaignView(false);
        }
      }
      else
      {
        return;
      }
      WelcomeFragment.this.showNoEventView();
      if (paramAnonymousAppError != null)
      {
        UsageTracker.i().formError(WelcomeFragment.this.getActivity(), "getallcampaigns", paramAnonymousAppError.getMessage());
        return;
      }
      UsageTracker.i().formError(WelcomeFragment.this.getActivity(), "getallcampaigns", WelcomeFragment.this.getString(2131165474));
      return;
      label170: WelcomeFragment.this.showNoNetworkEventView();
    }
  };
  private int mCurrentPage;
  private TextView mEmptyTitle;
  private TextView mGreeting;
  private CirclePageIndicator mIndicator;
  private LayoutInflater mInflater;
  private View mNoEventView;
  private View mNoNetworkCampaignsView;
  private final ServiceCallback<List<WelcomeNotification>> mNotificationCallback = new ServiceCallback()
  {
    public void done(List<WelcomeNotification> paramAnonymousList, AppError paramAnonymousAppError, Exception paramAnonymousException)
    {
      if (WelcomeFragment.this.getActivity() != null)
      {
        WelcomeFragment.this.mAlertHolder.removeAllViews();
        if ((paramAnonymousList != null) && (!paramAnonymousList.isEmpty()))
        {
          Iterator localIterator = paramAnonymousList.iterator();
          while (localIterator.hasNext())
          {
            WelcomeNotification localWelcomeNotification = (WelcomeNotification)localIterator.next();
            View localView = WelcomeFragment.this.mInflater.inflate(2130903169, WelcomeFragment.this.mAlertHolder, false);
            ((WelcomeAlertLayout)localView).updateWelcomeAlertView(localWelcomeNotification, WelcomeFragment.this.mBus);
            WelcomeFragment.this.mAlertHolder.addView(localView);
          }
        }
        WelcomeFragment.this.updateGreetingAndStoreInfo();
      }
    }
  };
  private ImageView mOffileIcon;
  private TextView mOfflineSubTitle;
  private TextView mOfflineTitle;
  private final View.OnClickListener mOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      switch (paramAnonymousView.getId())
      {
      case 2131624028:
      default:
        return;
      case 2131624085:
        WelcomeFragment.this.mBus.post(new ScanEvent(false, true, false));
        return;
      case 2131624026:
      case 2131624498:
        WelcomeFragment.this.mBus.post(new BrowseProductEvent(false, true));
        return;
      case 2131624023:
      case 2131624054:
      }
      WelcomeFragment.this.mBus.post(new GoToStoreLocatorEvent(false, true, false, false));
    }
  };
  private TextView mOpeningHour;
  private LeaveVerticalScrollForParentViewPager mPager;
  private int mPagerCurrentState;
  private TextView mPromotionsStore;
  private final Random mRandom = new Random();
  private ScrollView mScrollView;
  private int mScrollX = 0;
  private int mScrollY = -1;
  private boolean mShouldLoadInitialBGImage = true;
  private ImageView mStoreBg;
  private TextView mStoreName;
  private Timer mTimer;
  private User mUser;
  private boolean mUserInStore = false;
  private StoreRef mfavStore;

  private SpannableString getFormatedStoreName(StoreRef paramStoreRef)
  {
    String str1 = getResources().getString(2131165389) + " " + UiUtil.getFormatedStoreName(getActivity(), paramStoreRef.getStoreName());
    String str2 = str1 + " ";
    SpannableString localSpannableString = new SpannableString(str2.toUpperCase(Locale.getDefault()));
    localSpannableString.setSpan(new StyleSpan(1), 0, str1.length(), 33);
    if (UiUtil.isTablet(this.mParent));
    for (Drawable localDrawable = getResources().getDrawable(2130837791); ; localDrawable = getResources().getDrawable(2130837740))
    {
      int i = (int)getResources().getDimension(2131362089);
      if (localDrawable != null)
        localDrawable.setBounds(i, 0, i + localDrawable.getIntrinsicWidth(), localDrawable.getIntrinsicHeight());
      localSpannableString.setSpan(new CenteredImageSpan(localDrawable), -1 + str2.length(), str2.length(), 17);
      return localSpannableString;
    }
  }

  private String getGreetingMessage()
  {
    Object localObject = "";
    if (getActivity() == null)
      return localObject;
    while (true)
    {
      int i;
      try
      {
        Calendar localCalendar = Calendar.getInstance();
        localCalendar.setTimeInMillis(System.currentTimeMillis());
        i = localCalendar.get(11);
        if ((i >= 5) && (i < 12))
        {
          localObject = getResources().getString(2131165373);
        }
        else if ((i >= 12) && (i < 17))
        {
          localObject = getResources().getString(2131165370);
        }
        else
        {
          if ((i < 17) || (i >= 22))
            break label140;
          localObject = getResources().getString(2131165371);
          break label138;
          String str = getResources().getString(2131165374);
          localObject = str;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
      label138: label140: 
      do
      {
        return localObject;
        if (i >= 22)
          break;
      }
      while (i >= 5);
    }
  }

  private void setStoreBG(boolean paramBoolean1, boolean paramBoolean2)
  {
    boolean bool = NotificationService.i(this.mParent).wasInStore();
    int i;
    if ((!paramBoolean2) || (bool != paramBoolean1))
    {
      NotificationService.i(this.mParent).setWasInStore(paramBoolean1);
      i = NotificationService.i(this.mParent).getLastImageId();
      if (i < 0)
      {
        int j = AppCache.i(this.mParent).getLastUsedImageId();
        i = this.mRandom.nextInt(IN_STORE_BG_IMAGE_LIST.length);
        if (i == j)
          i = this.mRandom.nextInt(IN_STORE_BG_IMAGE_LIST.length);
        NotificationService.i(this.mParent).setLastImageId(i);
      }
    }
    try
    {
      AppCache.i(this.mParent).updateLastUsedImageId(i);
      if (paramBoolean1)
      {
        UiUtil.loadImageAsync(getActivity(), this.mStoreBg, IN_STORE_BG_IMAGE_LIST[i]);
        return;
      }
    }
    catch (IOException localIOException)
    {
      while (true)
        L.E(localIOException.getMessage());
      UiUtil.loadImageAsync(getActivity(), this.mStoreBg, OUT_STORE_BG_IMAGE_LIST[i]);
    }
  }

  private void showCampaignDisable()
  {
    this.mNoNetworkCampaignsView.setVisibility(0);
    this.mOffileIcon.setImageResource(2130837813);
    this.mOfflineTitle.setText(getString(2131165507));
    this.mOfflineSubTitle.setVisibility(4);
    this.mNoEventView.setVisibility(8);
    this.mPager.setVisibility(8);
    this.mIndicator.setVisibility(8);
  }

  private void showCampaignView(boolean paramBoolean)
  {
    this.mNoEventView.setVisibility(8);
    this.mNoNetworkCampaignsView.setVisibility(8);
    this.mPager.setAdapter(this.mAdapter);
    this.mIndicator.setViewPager(this.mPager);
    this.mPager.setCurrentItem(this.mCurrentPage);
    this.mPager.setVisibility(0);
    this.mIndicator.setVisibility(0);
    if (UiUtil.isTablet(getActivity()))
    {
      this.mIndicator.setVisibility(8);
      if ((!UiUtil.isLandscape(getActivity())) && (this.mAdapter.getCount() <= 2))
        this.mPager.setPagingEnabled(false);
      if ((UiUtil.isLandscape(getActivity())) && (this.mAdapter.getCount() <= 3))
        this.mPager.setPagingEnabled(false);
      this.mPager.setCurrentItem(this.mPagerCurrentState);
    }
    if ((paramBoolean) && (this.mScrollView != null))
      this.mScrollView.post(new Runnable()
      {
        public void run()
        {
          WelcomeFragment.this.mScrollView.scrollTo(WelcomeFragment.this.mScrollX, WelcomeFragment.this.mScrollY);
        }
      });
  }

  private void showNoEventView()
  {
    this.mNoEventView.setVisibility(0);
    this.mNoNetworkCampaignsView.setVisibility(8);
    this.mPager.setVisibility(8);
    this.mIndicator.setVisibility(8);
  }

  private void showNoNetworkEventView()
  {
    this.mNoNetworkCampaignsView.setVisibility(0);
    if ((StoreCache.i(getActivity()).isInStore()) && (AppConfigManager.i(getActivity()).getAppConfigData() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().getConfig() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().getConfig().ismWifiEnabled()))
      this.mOfflineSubTitle.setText(getString(2131165513));
    while (true)
    {
      this.mNoEventView.setVisibility(8);
      this.mPager.setVisibility(8);
      this.mIndicator.setVisibility(8);
      return;
      this.mOfflineSubTitle.setText(getString(2131165514));
    }
  }

  private void toggleCaapaigns(boolean paramBoolean)
  {
    if (paramBoolean)
    {
      this.mNoNetworkCampaignsView.setVisibility(8);
      if ((this.mAdapter != null) && (this.mAdapter.getCount() > 0))
        this.mNoEventView.setVisibility(8);
    }
    else
    {
      return;
    }
    this.mNoEventView.setVisibility(0);
  }

  private void updateGreetingAndStoreInfo()
  {
    this.mUserInStore = StoreCache.i(this.mParent).isInStore();
    setStoreBG(this.mUserInStore, true);
    StoreOpenInfo localStoreOpenInfo;
    int i;
    if (this.mUser.isLoggedIn())
    {
      String str8 = this.mUser.getFirstName();
      String str9 = getResources().getString(2131165384) + " " + str8 + ", " + getResources().getString(2131165733);
      if (!this.mUserInStore)
        str9 = getGreetingMessage() + " " + str8 + ",";
      SpannableString localSpannableString = new SpannableString(str9.toUpperCase());
      localSpannableString.setSpan(new StyleSpan(1), str9.indexOf(str8), str9.indexOf(str8) + str8.length(), 33);
      this.mGreeting.setText(localSpannableString);
      this.mfavStore = AppConfigManager.i(getActivity()).getAppConfigData().getFavStore();
      if (this.mfavStore != null)
      {
        this.mStoreName.setText(getFormatedStoreName(this.mfavStore));
        this.mEmptyTitle.setText(getResources().getString(2131165689) + " " + UiUtil.getFormatedStoreName(getActivity(), this.mfavStore.getStoreName()));
        TextView localTextView1 = this.mPromotionsStore;
        Resources localResources = getResources();
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = UiUtil.getFormatedStoreName(getActivity(), this.mfavStore.getStoreName());
        localTextView1.setText(localResources.getString(2131165506, arrayOfObject));
        localStoreOpenInfo = DateUtil.getStoreOpenInfo(this.mfavStore, getActivity());
        TextView localTextView2 = this.mOpeningHour;
        if (!UiUtil.isTablet(this.mParent))
          break label609;
        i = 2130837790;
        label370: localTextView2.setCompoundDrawablesWithIntrinsicBounds(i, 0, 0, 0);
        if (localStoreOpenInfo != null)
        {
          if (!localStoreOpenInfo.isOpen)
            break label617;
          String str7 = DateUtil.formatTime(localStoreOpenInfo.openUntil, this.mParent);
          this.mOpeningHour.setText(UiUtil.getSpannableBoldString(getActivity(), getResources().getString(2131165521) + " " + str7, str7));
        }
      }
    }
    while (true)
      if (!AppConfigManager.i(getActivity()).getAppConfigData().getKillSwitchConfig().isShowStoreInfo())
      {
        this.mOpeningHour.setVisibility(8);
        this.mStoreName.setVisibility(8);
        this.mPromotionsStore.setVisibility(8);
        return;
        String str1 = getGreetingMessage();
        String str2 = str1 + ", ";
        if (this.mUserInStore)
          if (!str1.equalsIgnoreCase(getResources().getString(2131165374)))
            break label578;
        label578: for (str2 = getResources().getString(2131165733); ; str2 = str2 + getResources().getString(2131165733))
        {
          this.mGreeting.setText(str2.toUpperCase());
          break;
        }
        label609: i = 2130837741;
        break label370;
        label617: String str3 = localStoreOpenInfo.openDay;
        if (str3 != null)
        {
          String str5 = DateUtil.formatTime(localStoreOpenInfo.opentime, this.mParent);
          try
          {
            String str6 = getString(2131165291, new Object[] { str3, str5 });
            this.mOpeningHour.setText(UiUtil.getSpannableBoldString(getActivity(), str6, str5));
          }
          catch (UnknownFormatConversionException localUnknownFormatConversionException)
          {
            localUnknownFormatConversionException.printStackTrace();
          }
          catch (Exception localException)
          {
            localException.printStackTrace();
          }
        }
        else
        {
          if (!TextUtils.isEmpty(localStoreOpenInfo.message));
          for (String str4 = localStoreOpenInfo.message; ; str4 = getString(2131165290))
          {
            this.mOpeningHour.setText(Html.fromHtml(str4));
            break;
          }
        }
      }
    this.mOpeningHour.setVisibility(0);
    this.mStoreName.setVisibility(0);
    this.mPromotionsStore.setVisibility(0);
  }

  private void updateNotificaions()
  {
    if (getActivity() != null)
      NotificationService.i(this.mParent).getNotificationAsync(this.mNotificationCallback);
  }

  @Subscribe
  public void handleFavouriteStoreEvent(FavouriteStoreEvent paramFavouriteStoreEvent)
  {
    this.mfavStore = paramFavouriteStoreEvent.mStore;
    boolean bool1 = AppConfigManager.i(getActivity()).getAppConfigData().getKillSwitchConfig().isShowCampaigns();
    boolean bool2 = AppConfigManager.i(this.mParent).getAppConfigData().getKillSwitchConfig().isShowStoreInfo();
    if ((this.mfavStore != null) && (bool2) && (bool1))
    {
      this.mCampaignServiceCallback.markValid();
      updateGreetingAndStoreInfo();
      CampaignService.i(this.mParent).getAllCampaignsAsync(this.mCampaignServiceCallback, this.mfavStore.getStoreNo());
    }
    while (true)
    {
      toggleCaapaigns(bool2);
      ((WelcomeActivity)getActivity()).refreshTray();
      return;
      timerStopForCampaign();
      showCampaignDisable();
    }
  }

  @Subscribe
  public void handleKillSwitchEvent(KillSwitchEvent paramKillSwitchEvent)
  {
    if (!KillSwitchUtil.isPrimaryServiceSameAsPrevious(paramKillSwitchEvent.oldKillSwitchConfig, paramKillSwitchEvent.newKillSwitchConfig))
    {
      L.I(this, "KillSwithConfig :event " + paramKillSwitchEvent);
      if (!AppConfigManager.i(this.mParent).getAppConfigData().getKillSwitchConfig().isShowStoreInfo())
        break label78;
      FavouriteStore.i(this.mParent).initCurrentLocation();
    }
    while (true)
    {
      ((WelcomeActivity)getActivity()).refreshTray();
      return;
      label78: updateGreetingAndStoreInfo();
      timerStopForCampaign();
      showCampaignDisable();
    }
  }

  @Subscribe
  public void handleNetworkStatusChange(NetworkStatusEvent paramNetworkStatusEvent)
  {
    boolean bool = AppConfigManager.i(this.mParent).getAppConfigData().getKillSwitchConfig().isShowStoreInfo();
    if ((paramNetworkStatusEvent.mConnected) && (bool))
    {
      timerStopForCampaign();
      timerStartForCampaign(0L);
    }
    while (true)
    {
      updateNotificaions();
      return;
      showNoNetworkEventView();
    }
  }

  @Subscribe
  public void handleSLItemAdd(SLChangedEvent paramSLChangedEvent)
  {
    updateNotificaions();
  }

  @Subscribe
  public void handleShoppingBagRefresh(ShoppingListRefreshEvent paramShoppingListRefreshEvent)
  {
    updateNotificaions();
  }

  protected boolean needTransparentActionBar()
  {
    return true;
  }

  public void onActivityCreated(@Nullable Bundle paramBundle)
  {
    super.onActivityCreated(paramBundle);
    if (paramBundle != null)
    {
      if (paramBundle.containsKey("SCROLL_Y_INDEX"))
      {
        this.mScrollX = paramBundle.getInt("SCROLL_X_INDEX");
        this.mScrollY = paramBundle.getInt("SCROLL_Y_INDEX");
      }
      if (paramBundle.containsKey("KEY_SELECTED_CAMPAIGN"))
        this.mPagerCurrentState = paramBundle.getInt("KEY_SELECTED_CAMPAIGN");
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.mUser = UserService.i(getActivity()).getUser();
    L.I("User :: " + this.mUser.toString());
    this.mfavStore = AppConfigManager.i(getActivity()).getAppConfigData().getFavStore();
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView = paramLayoutInflater.inflate(2130903055, paramViewGroup, false);
    this.mScrollView = ((ScrollView)localView.findViewById(2131624019));
    this.mNoEventView = localView.findViewById(2131624031);
    this.mNoNetworkCampaignsView = localView.findViewById(2131624032);
    this.mOfflineTitle = ((TextView)localView.findViewById(2131624056));
    this.mOfflineSubTitle = ((TextView)localView.findViewById(2131624057));
    this.mOffileIcon = ((ImageView)localView.findViewById(2131624055));
    this.mGreeting = ((TextView)localView.findViewById(2131624021));
    this.mStoreName = ((TextView)localView.findViewById(2131624023));
    this.mEmptyTitle = ((TextView)localView.findViewById(2131624053));
    this.mStoreName.setOnClickListener(this.mOnClickListener);
    this.mOpeningHour = ((TextView)localView.findViewById(2131624024));
    this.mAlertHolder = ((LinearLayout)localView.findViewById(2131624027));
    this.mPromotionsStore = ((TextView)localView.findViewById(2131624028));
    this.mPager = ((LeaveVerticalScrollForParentViewPager)localView.findViewById(2131624029));
    this.mIndicator = ((CirclePageIndicator)localView.findViewById(2131624030));
    this.mIndicator.setOnClickListener(null);
    this.mInflater = paramLayoutInflater;
    if ((getActivity() != null) && (AppConfigManager.i(getActivity()).getAppConfigData() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().getConfig() != null) && (AppConfigManager.i(getActivity()).getAppConfigData().getConfig().isBarCodeEnabled()))
    {
      localView.findViewById(2131624085).setOnClickListener(this.mOnClickListener);
      localView.findViewById(2131624498).setOnClickListener(this.mOnClickListener);
      localView.findViewById(2131624026).setVisibility(8);
      localView.findViewById(2131624025).setVisibility(0);
    }
    while (true)
    {
      localView.findViewById(2131624054).setOnClickListener(this.mOnClickListener);
      this.mStoreBg = ((ImageView)localView.findViewById(2131624020));
      this.mShouldLoadInitialBGImage = true;
      return localView;
      localView.findViewById(2131624025).setVisibility(8);
      localView.findViewById(2131624026).setVisibility(0);
      localView.findViewById(2131624026).setOnClickListener(this.mOnClickListener);
    }
  }

  public void onDestroy()
  {
    super.onDestroy();
    this.mPager = null;
    this.mIndicator = null;
    this.mAdapter = null;
    this.mStoreBg = null;
  }

  public void onPause()
  {
    super.onPause();
    timerStopForCampaign();
    if (this.mScrollView != null)
    {
      this.mScrollX = this.mScrollView.getScrollX();
      this.mScrollY = this.mScrollView.getScrollY();
    }
    this.mCurrentPage = this.mIndicator.getCurrentPage();
    this.mCampaignServiceCallback.markInvalid();
    this.mNotificationCallback.markInvalid();
    try
    {
      this.mBus.unregister(this);
      return;
    }
    catch (Exception localException)
    {
      L.W("No event handler to unregister");
    }
  }

  public void onResume()
  {
    boolean bool1 = true;
    super.onResume();
    if (this.mShouldLoadInitialBGImage)
    {
      setStoreBG(false, false);
      this.mShouldLoadInitialBGImage = false;
    }
    this.mBus.register(this);
    this.mBus.post(new WelcomeResumedEvent());
    this.mUserInStore = StoreCache.i(this.mParent).isInStore();
    this.mUser = UserService.i(this.mParent).getUser();
    StoreRef localStoreRef1 = AppConfigManager.i(getActivity()).getAppConfigData().getFavStore();
    boolean bool2 = AppConfigManager.i(getActivity()).getAppConfigData().getKillSwitchConfig().isShowCampaigns();
    boolean bool3 = AppConfigManager.i(this.mParent).getAppConfigData().getKillSwitchConfig().isShowStoreInfo();
    int i;
    if ((localStoreRef1 != null) && (this.mfavStore != null))
    {
      boolean bool5 = this.mfavStore.getStoreNo().equals(localStoreRef1.getStoreNo());
      i = 0;
      if (bool5)
      {
        if ((this.mfavStore == null) || (!bool2) || (!bool3))
          break label434;
        timerStartForCampaign(1800000L);
        updateGreetingAndStoreInfo();
        if (!UiUtil.isConnectionAvailable(getActivity()))
          break label427;
        this.mPromotionsStore.setVisibility(0);
        if ((this.mAdapter != null) && (i == 0) && (!Constant.i().isNewCampaignNeeded()))
          break label419;
        this.isCampaignFetching = bool1;
        this.mCampaignServiceCallback.markValid();
        this.mPager.setVisibility(0);
        this.mIndicator.setVisibility(0);
        CampaignService.i(this.mParent).getAllCampaignsAsync(this.mCampaignServiceCallback, this.mfavStore.getStoreNo());
        label273: this.mNotificationCallback.markValid();
        updateInOutStoreView(new StoreInOutEvent(this.mUserInStore, ""));
        if (UsageTracker.i().isBackPressed())
          UsageTracker.i().viewHomePage(getActivity(), false, false, false);
        if ((!UiUtil.isConnectionAvailable(getActivity())) || (!bool3))
          break label445;
      }
    }
    while (true)
    {
      toggleCaapaigns(bool1);
      return;
      if ((this.mfavStore == null) && (localStoreRef1 != null))
      {
        i = 1;
        this.mfavStore = localStoreRef1;
        break;
      }
      i = 0;
      if (localStoreRef1 == null)
        break;
      StoreRef localStoreRef2 = this.mfavStore;
      i = 0;
      if (localStoreRef2 == null)
        break;
      boolean bool4 = this.mfavStore.getStoreNo().equals(localStoreRef1.getStoreNo());
      i = 0;
      if (bool4)
        break;
      i = 1;
      this.mfavStore = localStoreRef1;
      break;
      label419: showCampaignView(bool1);
      break label273;
      label427: showNoNetworkEventView();
      break label273;
      label434: timerStopForCampaign();
      showCampaignDisable();
      break label273;
      label445: bool1 = false;
    }
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    if (this.mScrollView != null)
    {
      this.mScrollX = this.mScrollView.getScrollX();
      this.mScrollY = this.mScrollView.getScrollY();
    }
    paramBundle.putInt("SCROLL_X_INDEX", this.mScrollX);
    paramBundle.putInt("SCROLL_Y_INDEX", this.mScrollY);
    if (this.mPager != null)
      paramBundle.putInt("KEY_SELECTED_CAMPAIGN", this.mPager.getCurrentItem());
  }

  protected void slEvent(boolean paramBoolean)
  {
    if ((!paramBoolean) && (UsageTracker.i().isBackPressed()))
      UsageTracker.i().viewHomePage(getActivity(), false, false, false);
  }

  public void timerStartForCampaign(long paramLong)
  {
    this.mTimer = new Timer();
    TimerTask local4 = new TimerTask()
    {
      public void run()
      {
        WelcomeFragment.this.mHandler.post(new Runnable()
        {
          public void run()
          {
            if ((!WelcomeFragment.this.isCampaignFetching) && (AppConfigManager.i(WelcomeFragment.this.getActivity()).getAppConfigData().getKillSwitchConfig().isShowCampaigns()))
            {
              WelcomeFragment.this.mCampaignServiceCallback.markValid();
              if ((WelcomeFragment.this.mfavStore != null) && (!TextUtils.isEmpty(WelcomeFragment.this.mfavStore.getStoreNo())))
                CampaignService.i(WelcomeFragment.this.mParent).getAllCampaignsAsync(WelcomeFragment.this.mCampaignServiceCallback, WelcomeFragment.this.mfavStore.getStoreNo());
            }
          }
        });
      }
    };
    this.mTimer.schedule(local4, paramLong, 1800000L);
  }

  public void timerStopForCampaign()
  {
    this.mHandler.post(new Runnable()
    {
      public void run()
      {
        if (WelcomeFragment.this.mTimer != null)
        {
          WelcomeFragment.this.mTimer.cancel();
          WelcomeFragment.access$1702(WelcomeFragment.this, null);
        }
      }
    });
  }

  @Subscribe
  public void updateInOutStoreView(StoreInOutEvent paramStoreInOutEvent)
  {
    L.I("StoreInOutEvent capture  : " + paramStoreInOutEvent);
    updateNotificaions();
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.kompis.campaign.WelcomeFragment
 * JD-Core Version:    0.6.2
 */