Search in sources :

Example 1 with StethoInterceptor

use of com.facebook.stetho.okhttp.StethoInterceptor in project Rutgers-Course-Tracker by tevjef.

the class RutgersCTModule method providesOkHttpClient.

@Provides
@Singleton
public OkHttpClient providesOkHttpClient(Context context) {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    client.networkInterceptors().add(new StethoInterceptor());
    File httpCacheDir = new File(context.getCacheDir(), context.getString(R.string.application_name));
    // 50 MiB
    long httpCacheSize = 50 * 1024 * 1024;
    Cache cache = new Cache(httpCacheDir, httpCacheSize);
    client.setCache(cache);
    if (BuildConfig.DEBUG) {
        try {
            cache.evictAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return client;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) StethoInterceptor(com.facebook.stetho.okhttp.StethoInterceptor) IOException(java.io.IOException) File(java.io.File) Cache(com.squareup.okhttp.Cache) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Aggregations

StethoInterceptor (com.facebook.stetho.okhttp.StethoInterceptor)1 Cache (com.squareup.okhttp.Cache)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 Provides (dagger.Provides)1 File (java.io.File)1 IOException (java.io.IOException)1 Singleton (javax.inject.Singleton)1