ImojiPagerAdapter.java 3.22 KB
package com.bitstrips.imoji.browser.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;
import com.bitstrips.imoji.browser.fragments.ImojiBrowserFragment;
import com.bitstrips.imoji.ui.fragments.FavouriteFragment;
import com.bitstrips.imoji.ui.fragments.SearchContainerFragment;
import com.bitstrips.imoji.ui.fragments.SearchResultFragment;
import java.lang.ref.WeakReference;
import java.util.List;

public class ImojiPagerAdapter
  extends FragmentStatePagerAdapter
{
  public static final int POSITION_FAVOURITE_FRAGMENT = 1;
  public static final int POSITION_SEARCH_FRAGMENT = 0;
  private static final String d = ImojiPagerAdapter.class.getCanonicalName();
  private List<String> a;
  private FragmentManager b;
  private WeakReference<SearchContainerFragment> c;
  
  public ImojiPagerAdapter(FragmentManager paramFragmentManager, List<String> paramList)
  {
    super(paramFragmentManager);
    this.b = paramFragmentManager;
    this.a = paramList;
  }
  
  public void destroyItem(ViewGroup paramViewGroup, int paramInt, Object paramObject)
  {
    if (paramInt != 0) {}
    for (;;)
    {
      FragmentTransaction localFragmentTransaction;
      try
      {
        Fragment localFragment = (Fragment)paramObject;
        localFragmentTransaction = this.b.beginTransaction();
        localFragmentTransaction.remove(localFragment);
        localFragmentTransaction.commitAllowingStateLoss();
        super.destroyItem(paramViewGroup, paramInt, paramObject);
        return;
      }
      catch (IllegalStateException localIllegalStateException)
      {
        new StringBuilder("Caught unexpected exception while destroying item: ").append(localIllegalStateException.getMessage());
        continue;
      }
      SearchResultFragment localSearchResultFragment = (SearchResultFragment)this.b.findFragmentByTag("fragments.SearchResultFragment");
      if (localSearchResultFragment != null)
      {
        localFragmentTransaction = this.b.beginTransaction();
        localFragmentTransaction.remove(localSearchResultFragment);
        localFragmentTransaction.commitAllowingStateLoss();
        this.b.popBackStack();
      }
    }
  }
  
  public int getCount()
  {
    return this.a.size() + 1;
  }
  
  public Fragment getItem(int paramInt)
  {
    if (paramInt == 0) {
      return getOrCreateSearchFragment();
    }
    if (paramInt == 1) {
      return FavouriteFragment.newInstance();
    }
    return ImojiBrowserFragment.newInstance((String)this.a.get(paramInt - 1));
  }
  
  public int getItemPosition(Object paramObject)
  {
    return -2;
  }
  
  public SearchContainerFragment getOrCreateSearchFragment()
  {
    if (!hasSearchFragment()) {
      this.c = new WeakReference(SearchContainerFragment.newInstance());
    }
    return (SearchContainerFragment)this.c.get();
  }
  
  public boolean hasSearchFragment()
  {
    return (this.c != null) && (this.c.get() != null);
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/browser/adapters/ImojiPagerAdapter.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */