package com.squareup.picasso;

import android.content.Context;
import android.net.Uri;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import static com.squareup.picasso.Utils.parseResponseSourceHeader;

/** A {@link Loader} which uses OkHttp to download images. */
public class OkHttpLoader implements Loader {
  static final String RESPONSE_SOURCE = "X-Android-Response-Source";

  private final OkHttpClient client;

  /**
   * Create new loader that uses OkHttp. This will install an image cache into your application
   * cache directory.
   */
  public OkHttpLoader(Context context) {
    this(new OkHttpClient());
    try {
      File cacheDir = Utils.createDefaultCacheDir(context);
      int maxSize = Utils.calculateDiskCacheSize(cacheDir);
      client.setResponseCache(new HttpResponseCache(cacheDir, maxSize));
    } catch (IOException ignored) {
    }
  }

  /**
   * Create a new loader that uses the specified OkHttp instance. A response cache will not be
   * automatically configured.
   */
  public OkHttpLoader(OkHttpClient client) {
    this.client = client;
  }

  @Override public Response load(Uri uri, boolean localCacheOnly) throws IOException {
    HttpURLConnection connection = client.open(new URL(uri.toString()));
    connection.setUseCaches(true);
    if (localCacheOnly) {
      connection.setRequestProperty("Cache-Control", "only-if-cached");
    }

    boolean fromCache = parseResponseSourceHeader(connection.getHeaderField(RESPONSE_SOURCE));

    return new Response(connection.getInputStream(), fromCache);
  }
}

@@ -556,28 +556,36 @@
  client;%0A%0A  
-/**%0A
+    /**%0A    
    * Create 
@@ -668,16 +668,20 @@
 ication%0A
+    
    * cac
@@ -693,27 +693,35 @@
 rectory.%0A   
-*/%0A
+    */%0A    
   public OkH
@@ -730,16 +730,22 @@
 pLoader(
+final 
 Context 
@@ -751,24 +751,28 @@
  context) %7B%0A
+    
     this(new
@@ -772,159 +772,1115 @@
 his(
-new OkHttpClient());%0A    try %7B%0A      File cacheDir = Utils.createDefaultCacheDir(context);%0A      int maxSize = Utils.calculateDiskCacheSize(cacheDir);%0A
+Utils.createDefaultCacheDir(context));%0A      %7D%0A%0A    /**%0A     * Create new loader that uses OkHttp. This will install an image cache into your application%0A     * cache directory.%0A     *%0A     * @param cacheDir The directory in which the cache should be stored%0A     */%0A    public OkHttpLoader(final File cacheDir) %7B%0A        this(cacheDir, Utils.calculateDiskCacheSize(cacheDir));%0A    %7D%0A%0A    /**%0A     * Create new loader that uses OkHttp. This will install an image cache into your application%0A     * cache directory.%0A     *%0A     * @param maxSize The size limit for the cache.%0A     */%0A    public OkHttpLoader(final Context context, final int maxSize) %7B%0A        this(Utils.createDefaultCacheDir(context), maxSize);%0A    %7D%0A%0A    /**%0A     * Create new loader that uses OkHttp. This will install an image cache into your application%0A     * cache directory.%0A     *%0A     * @param cacheDir The directory in which the cache should be stored%0A     * @param maxSize The size limit for the cache.%0A     */%0A    public OkHttpLoader(final File cacheDir, final int maxSize) %7B%0A        this(new OkHttpClient());%0A        try %7B%0A      
     
@@ -1944,24 +1944,28 @@
  maxSize));%0A
+    
     %7D catch 
@@ -1992,18 +1992,24 @@
 ) %7B%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%0A  /

Add constructors which allow for configuration of cache location and size