StickerPreloader.java 2.96 KB
package com.bitstrips.imoji.ui;

import com.bitstrips.imoji.manager.StickerPacksManager;
import com.bitstrips.imoji.models.Sticker;
import com.bitstrips.imoji.models.StickerPack;
import com.bitstrips.imoji.models.StickerPacks;
import com.bitstrips.imoji.persistence.MediaCache;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.squareup.picasso.Callback;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class StickerPreloader
{
  private static final Object a = new Object();
  private final PreferenceUtils b;
  private final StickerPacksManager c;
  private final MediaCache d;
  private List<Sticker> e;
  private List<Sticker> f;
  private int g = 0;
  
  @Inject
  StickerPreloader(PreferenceUtils paramPreferenceUtils, StickerPacksManager paramStickerPacksManager, MediaCache paramMediaCache)
  {
    this.b = paramPreferenceUtils;
    this.c = paramStickerPacksManager;
    this.d = paramMediaCache;
  }
  
  private void a()
  {
    int i = 2;
    int j = this.g;
    this.g = (j + 1);
    if (j >= 3) {
      return;
    }
    synchronized (a)
    {
      if (this.e.size() == 0) {
        return;
      }
    }
    final Object localObject3 = this.e;
    if (this.e.size() < 2) {
      i = this.e.size();
    }
    this.f = new ArrayList(((List)localObject3).subList(0, i));
    Collections.reverse(this.f);
    this.e = new ArrayList(this.e.subList(this.f.size(), this.e.size()));
    i = this.f.size() - 1;
    while (i >= 0)
    {
      localObject3 = (Sticker)this.f.get(i);
      String str = ((Sticker)localObject3).getImageUrl();
      if ((str == null) || (str.contains("null"))) {
        break;
      }
      this.d.preload(str, new Callback()
      {
        public final void onError()
        {
          StickerPreloader.a(StickerPreloader.this, localObject3);
        }
        
        public final void onSuccess()
        {
          StickerPreloader.a(StickerPreloader.this, localObject3);
        }
      });
      i -= 1;
    }
  }
  
  public String getLastPreloadedAvatarId()
  {
    return this.b.getString(2131231263, null);
  }
  
  public void load()
  {
    Object localObject1 = this.b.getString(2131231175, null);
    Object localObject2 = this.c.getStickerPacks();
    this.g = 0;
    this.e = new ArrayList();
    this.b.putString(2131231263, (String)localObject1);
    if (localObject2 != null)
    {
      localObject1 = ((StickerPack)((StickerPacks)localObject2).get().get(0)).getStickers().iterator();
      while (((Iterator)localObject1).hasNext())
      {
        localObject2 = (Sticker)((Iterator)localObject1).next();
        if (((Sticker)localObject2).isSolomoji()) {
          this.e.add(localObject2);
        }
      }
    }
    a();
  }
}


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