RecentStickersManager.java 2.88 KB
package com.bitstrips.imoji.manager;

import com.bitstrips.imoji.models.Sticker;
import com.bitstrips.imoji.search.SearchIndex;
import com.bitstrips.imoji.search.SearchIndex.OnIndexCompleteListener;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class RecentStickersManager
  implements SearchIndex.OnIndexCompleteListener
{
  private static final Type b = new TypeToken() {}.getType();
  private Gson a;
  private Map<String, List<Sticker>> c;
  private final PreferenceUtils d;
  private final SearchIndex e;
  
  @Inject
  public RecentStickersManager(PreferenceUtils paramPreferenceUtils, SearchIndex paramSearchIndex)
  {
    this.d = paramPreferenceUtils;
    this.e = paramSearchIndex;
    this.a = new GsonBuilder().enableComplexMapKeySerialization().create();
    paramSearchIndex = (Map)this.a.fromJson(this.d.getString(2131231313, null), b);
    paramPreferenceUtils = paramSearchIndex;
    if (paramSearchIndex == null) {
      paramPreferenceUtils = new HashMap();
    }
    this.c = paramPreferenceUtils;
    this.e.addOnIndexCompleteListener(this);
  }
  
  private String a()
  {
    return this.d.getString(2131231176, "");
  }
  
  private void a(List<Sticker> paramList)
  {
    this.c.put(a(), paramList);
    this.d.putString(2131231313, this.a.toJson(this.c, b));
  }
  
  public void addRecentSticker(Sticker paramSticker)
  {
    List localList = getRecentStickers();
    localList.remove(paramSticker);
    localList.add(0, paramSticker);
    a(localList.subList(0, Math.min(localList.size(), 6)));
  }
  
  public List<Sticker> getRecentStickers()
  {
    if (!this.c.containsKey(a())) {
      return new ArrayList();
    }
    return (List)this.c.get(a());
  }
  
  public void onIndexComplete(SearchIndex paramSearchIndex)
  {
    Object localObject = getRecentStickers();
    if (((List)localObject).isEmpty()) {
      return;
    }
    ArrayList localArrayList = new ArrayList(((List)localObject).size());
    localObject = ((List)localObject).iterator();
    while (((Iterator)localObject).hasNext())
    {
      Sticker localSticker = paramSearchIndex.getStickerForComicId(((Sticker)((Iterator)localObject).next()).getComicId());
      if (localSticker != null) {
        localArrayList.add(localSticker);
      }
    }
    this.c.put(a(), localArrayList);
    a(localArrayList);
  }
  
  public static abstract interface Callback
  {
    public abstract void success();
  }
}


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