SearchIndex.java 3.59 KB
package com.bitstrips.imoji.search;

import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.bitstrips.imoji.manager.StickerPacksManager.OnStickerPacksChangedListener;
import com.bitstrips.imoji.models.Sticker;
import com.bitstrips.imoji.models.StickerPacks;
import hn;
import hn.a;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import javax.inject.Singleton;

@Singleton
public class SearchIndex
  implements StickerPacksManager.OnStickerPacksChangedListener, hn.a
{
  private Map<String, List<Sticker>> a = new HashMap();
  private Map<String, List<Sticker>> b = new HashMap();
  private Map<String, Sticker> c = new HashMap();
  private WeakHashMap<OnIndexCompleteListener, Void> d = new WeakHashMap();
  private AsyncTask e = null;
  
  public void addOnIndexCompleteListener(OnIndexCompleteListener paramOnIndexCompleteListener)
  {
    this.d.put(paramOnIndexCompleteListener, null);
  }
  
  public void flush()
  {
    this.a = new HashMap();
    this.b = new HashMap();
  }
  
  @Nullable
  public Sticker getStickerForComicId(@NonNull String paramString)
  {
    return (Sticker)this.c.get(paramString);
  }
  
  @NonNull
  public List<Sticker> getStickersForSupertag(String paramString)
  {
    List localList = (List)this.b.get(paramString);
    paramString = localList;
    if (localList == null) {
      paramString = new ArrayList();
    }
    return paramString;
  }
  
  @NonNull
  public List<Sticker> getStickersForTag(String paramString)
  {
    List localList = (List)this.a.get(paramString);
    paramString = localList;
    if (localList == null) {
      paramString = new ArrayList();
    }
    return paramString;
  }
  
  @NonNull
  public List<Sticker> getStickersForTags(List<String> paramList)
  {
    LinkedHashSet localLinkedHashSet = new LinkedHashSet();
    paramList = paramList.iterator();
    while (paramList.hasNext()) {
      localLinkedHashSet.addAll(getStickersForTag((String)paramList.next()));
    }
    return new ArrayList(localLinkedHashSet);
  }
  
  public Collection<String> getTags()
  {
    return this.a.keySet();
  }
  
  public boolean hasResults()
  {
    return !this.a.isEmpty();
  }
  
  public void index(StickerPacks paramStickerPacks)
  {
    if (this.e != null) {
      this.e.cancel(true);
    }
    this.e = new hn(this).execute(new StickerPacks[] { paramStickerPacks });
  }
  
  public void onIndexTaskComplete(Map<String, List<Sticker>> paramMap1, Map<String, List<Sticker>> paramMap2, Map<String, Sticker> paramMap)
  {
    this.a = paramMap1;
    this.b = paramMap2;
    this.c = paramMap;
    this.e = null;
    paramMap1 = this.d.keySet().iterator();
    while (paramMap1.hasNext()) {
      ((OnIndexCompleteListener)paramMap1.next()).onIndexComplete(this);
    }
  }
  
  public void onStickerPacksChanged(StickerPacks paramStickerPacks)
  {
    if (paramStickerPacks == null)
    {
      flush();
      return;
    }
    index(paramStickerPacks);
  }
  
  public void removeOnIndexCompleteListener(OnIndexCompleteListener paramOnIndexCompleteListener)
  {
    this.d.remove(paramOnIndexCompleteListener);
  }
  
  public static abstract interface OnIndexCompleteListener
  {
    public abstract void onIndexComplete(SearchIndex paramSearchIndex);
  }
}


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