hm.java 2.49 KB
import android.content.Context;
import android.net.Uri;
import android.support.annotation.VisibleForTesting;
import com.bitstrips.imoji.persistence.MediaCache;
import com.bitstrips.imoji.util.WebUtils;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Request.Builder;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import com.squareup.picasso.Downloader;
import com.squareup.picasso.Downloader.Response;
import com.squareup.picasso.Downloader.ResponseException;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public final class hm
  implements Downloader
{
  private final OkHttpClient a;
  private final MediaCache b;
  private final Context c;
  
  public hm(MediaCache paramMediaCache, Context paramContext)
  {
    this(paramMediaCache, new OkHttpClient(), paramContext);
  }
  
  @VisibleForTesting
  private hm(MediaCache paramMediaCache, OkHttpClient paramOkHttpClient, Context paramContext)
  {
    paramOkHttpClient.setConnectTimeout(15L, TimeUnit.SECONDS);
    paramOkHttpClient.setReadTimeout(20L, TimeUnit.SECONDS);
    paramOkHttpClient.setWriteTimeout(20L, TimeUnit.SECONDS);
    this.a = paramOkHttpClient;
    this.b = paramMediaCache;
    this.c = paramContext;
  }
  
  public final Downloader.Response load(Uri paramUri, int paramInt)
    throws IOException
  {
    Object localObject = new Request.Builder().url(paramUri.toString()).addHeader("Bitmoji-User-Agent", WebUtils.getBitmojiUserAgent(this.c)).build();
    localObject = this.a.newCall((Request)localObject).execute();
    int i = ((Response)localObject).code();
    if (i >= 300)
    {
      ((Response)localObject).body().close();
      throw new Downloader.ResponseException(i + " " + ((Response)localObject).message(), paramInt, i);
    }
    localObject = ((Response)localObject).body();
    paramUri = this.b.storeMediaData(paramUri.toString(), ((ResponseBody)localObject).byteStream());
    if (paramUri == null) {
      return new Downloader.Response(((ResponseBody)localObject).byteStream(), false, ((ResponseBody)localObject).contentLength());
    }
    return new Downloader.Response(new FileInputStream(paramUri), false, ((ResponseBody)localObject).contentLength());
  }
  
  public final void shutdown()
  {
    this.b.shutdown();
  }
}


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