From ad1c2fb64caf34081abe572db794096d1d20186e Mon Sep 17 00:00:00 2001 From: Alex Gotev Date: Fri, 10 Feb 2017 16:17:44 +0100 Subject: [PATCH] Update README.md --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index 54ea6aa..58b564a 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,52 @@ debugCompile "com.facebook.stetho:stetho-okhttp3:${stethoVersion}" releaseCompile "net.igenius:stetho-no-op:1.1" ``` +```java +public class App extends Application { + + private static OkHttpClient httpClient; + + @Override + public void onCreate() { + super.onCreate(); + + if (BuildConfig.DEBUG) { + Stetho.initialize( + newInitializerBuilder(this) + .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) + .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) + .build()); + } + } + + /** + * Gets the instance of the application's HTTP client. + * @return OkHttp client instance, ready to make requests + */ + public static OkHttpClient getHttpClient(final Context context) { + if (httpClient == null) { + OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder() + .followRedirects(true) + .followSslRedirects(true) + .retryOnConnectionFailure(true) + .cache(null) + .connectTimeout(5, TimeUnit.SECONDS) + .writeTimeout(10, TimeUnit.SECONDS) + .readTimeout(10, TimeUnit.SECONDS); + + if (BuildConfig.DEBUG) { + clientBuilder.addNetworkInterceptor(new StethoInterceptor()); + } + + httpClient = clientBuilder.build(); + } + + return httpClient; + } + +} +``` + ## License Copyright (C) 2017 iGenius Srl