StickerCategoriesAdapter.java 7.41 KB
package com.bitstrips.imoji.browser.adapters;

import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.bitstrips.imoji.analytics.Action;
import com.bitstrips.imoji.analytics.Category;
import com.bitstrips.imoji.analytics.LegacyAnalyticsService;
import com.bitstrips.imoji.analytics.performance.AnalyticsLabelKey;
import com.bitstrips.imoji.analytics.performance.PerformanceTimer;
import com.bitstrips.imoji.analytics.performance.TimedMetric;
import com.bitstrips.imoji.browser.models.Header;
import com.bitstrips.imoji.browser.models.StickerCategory;
import com.bitstrips.imoji.browser.models.StickerCategory.EmptyStateType;
import com.bitstrips.imoji.browser.views.EmptyStateViewHolder;
import com.bitstrips.imoji.browser.views.HeaderViewHolder;
import com.bitstrips.imoji.browser.views.StickerViewHolder;
import com.bitstrips.imoji.browser.views.StickerViewHolder.OnStickerSelectedListener;
import com.bitstrips.imoji.models.Sticker;
import com.bitstrips.imoji.persistence.MediaCache;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class StickerCategoriesAdapter
  extends RecyclerView.Adapter
{
  private final String a;
  private final List<StickerCategory> b;
  private final StickerViewHolder.OnStickerSelectedListener c;
  private final MediaCache d;
  private final LegacyAnalyticsService e;
  private int f = 0;
  private boolean g = false;
  private HashMap<StickerCategory, Integer> h = new HashMap();
  
  public StickerCategoriesAdapter(@NonNull String paramString, List<StickerCategory> paramList, StickerViewHolder.OnStickerSelectedListener paramOnStickerSelectedListener, MediaCache paramMediaCache, LegacyAnalyticsService paramLegacyAnalyticsService)
  {
    this.a = paramString;
    this.b = paramList;
    this.c = paramOnStickerSelectedListener;
    this.d = paramMediaCache;
    this.e = paramLegacyAnalyticsService;
  }
  
  @Nullable
  private Pair<StickerCategory, Integer> a(int paramInt)
  {
    Iterator localIterator = this.b.iterator();
    int i = 0;
    while (localIterator.hasNext())
    {
      StickerCategory localStickerCategory = (StickerCategory)localIterator.next();
      int j = ((Integer)this.h.get(localStickerCategory)).intValue();
      if (paramInt >= j)
      {
        i = j;
      }
      else
      {
        j = i;
        if (localStickerCategory.hasHeader()) {
          j = i + 1;
        }
        return new Pair(localStickerCategory, Integer.valueOf(paramInt - j));
      }
    }
    return null;
  }
  
  public int getCategoryPosition(int paramInt)
  {
    Pair localPair = a(paramInt);
    if (localPair == null) {
      return 0;
    }
    return ((Integer)localPair.second).intValue();
  }
  
  public int getItemCount()
  {
    return this.f;
  }
  
  public long getItemId(int paramInt)
  {
    Pair localPair = a(paramInt);
    if (localPair == null) {
      return -1L;
    }
    StickerCategory localStickerCategory = (StickerCategory)localPair.first;
    paramInt = ((Integer)localPair.second).intValue();
    if (paramInt == -1) {
      return localStickerCategory.getHeader().getTitle().hashCode();
    }
    if (localStickerCategory.isEmpty())
    {
      switch (2.a[localStickerCategory.getEmptyStateType().ordinal()])
      {
      default: 
        return -1L;
      }
      return 3L;
    }
    return (localStickerCategory.getName() + ((Sticker)localStickerCategory.getStickers().get(paramInt)).getTemplateId()).hashCode();
  }
  
  public int getItemViewType(int paramInt)
  {
    Pair localPair = a(paramInt);
    if (localPair == null) {
      return -1;
    }
    StickerCategory localStickerCategory = (StickerCategory)localPair.first;
    if (((Integer)localPair.second).intValue() == -1) {
      return 1;
    }
    if (localStickerCategory.isEmpty())
    {
      switch (2.a[localStickerCategory.getEmptyStateType().ordinal()])
      {
      default: 
        return -1;
      }
      return 3;
    }
    return 2;
  }
  
  public int getSpanSize(int paramInt1, int paramInt2)
  {
    switch (getItemViewType(paramInt1))
    {
    default: 
      paramInt2 = 0;
    case 1: 
    case 3: 
      return paramInt2;
    }
    return 1;
  }
  
  public void init()
  {
    this.h = new HashMap(this.b.size());
    this.f = 0;
    Iterator localIterator = this.b.iterator();
    while (localIterator.hasNext())
    {
      StickerCategory localStickerCategory = (StickerCategory)localIterator.next();
      List localList = localStickerCategory.getStickers();
      if (localStickerCategory.hasHeader()) {
        this.f += 1;
      }
      if ((localList.isEmpty()) && (localStickerCategory.getEmptyStateType() != StickerCategory.EmptyStateType.IGNORE)) {
        this.f += 1;
      }
      int i = this.f;
      this.f = (localList.size() + i);
      this.h.put(localStickerCategory, Integer.valueOf(this.f));
    }
    setHasStableIds(true);
  }
  
  public boolean isItemImoji(int paramInt)
  {
    return getItemViewType(paramInt) == 2;
  }
  
  public void onBindViewHolder(RecyclerView.ViewHolder paramViewHolder, int paramInt)
  {
    Object localObject = a(paramInt);
    if (localObject == null) {}
    StickerCategory localStickerCategory;
    do
    {
      return;
      localStickerCategory = (StickerCategory)((Pair)localObject).first;
      paramInt = ((Integer)((Pair)localObject).second).intValue();
      if (paramInt == -1)
      {
        ((HeaderViewHolder)paramViewHolder).setHeader(localStickerCategory.getHeader());
        return;
      }
    } while (localStickerCategory.isEmpty());
    localObject = (Sticker)localStickerCategory.getStickers().get(paramInt);
    if (!this.g)
    {
      this.g = true;
      new Handler().postDelayed(new Runnable()
      {
        public final void run()
        {
          if (PerformanceTimer.stopTimer(TimedMetric.APP_START) == -1L) {
            return;
          }
          HashMap localHashMap = new HashMap(1);
          localHashMap.put(AnalyticsLabelKey.APP_STATE_KEY, "timeout");
          StickerCategoriesAdapter.a(StickerCategoriesAdapter.this).sendEvent(Category.PERFORMANCE, Action.PERCEIVED_OPEN, localHashMap);
        }
      }, 55000L);
    }
    ((StickerViewHolder)paramViewHolder).setSticker((Sticker)localObject, this.a).setCategoryName(localStickerCategory.getName());
  }
  
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt)
  {
    switch (paramInt)
    {
    default: 
      return null;
    case 1: 
      return new HeaderViewHolder(LayoutInflater.from(paramViewGroup.getContext()).inflate(2130903121, paramViewGroup, false));
    case 2: 
      return new StickerViewHolder(LayoutInflater.from(paramViewGroup.getContext()).inflate(2130903130, paramViewGroup, false), this.d, this.e, this.c);
    }
    return new EmptyStateViewHolder(LayoutInflater.from(paramViewGroup.getContext()).inflate(2130903083, paramViewGroup, false));
  }
  
  public void onViewRecycled(RecyclerView.ViewHolder paramViewHolder)
  {
    if ((paramViewHolder instanceof StickerViewHolder)) {
      ((StickerViewHolder)paramViewHolder).cancel();
    }
  }
}


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