code refactor

main
h4h13 2018-08-05 22:00:57 +05:30
parent 058b6bf32a
commit a15d00a80a
2 changed files with 7 additions and 7 deletions

View File

@ -31,7 +31,7 @@ public class KogouClient {
this(createDefaultOkHttpClientBuilder().build()); this(createDefaultOkHttpClientBuilder().build());
} }
public KogouClient(@NonNull Call.Factory client) { private KogouClient(@NonNull Call.Factory client) {
Retrofit restAdapter = new Retrofit.Builder() Retrofit restAdapter = new Retrofit.Builder()
.baseUrl(BASE_URL) .baseUrl(BASE_URL)
.callFactory(client) .callFactory(client)
@ -43,7 +43,7 @@ public class KogouClient {
} }
@Nullable @Nullable
public static Cache createDefaultCache(Context context) { private static Cache createDefaultCache(Context context) {
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/"); File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
if (cacheDir.mkdirs() || cacheDir.isDirectory()) { if (cacheDir.mkdirs() || cacheDir.isDirectory()) {
return new Cache(cacheDir, 1024 * 1024 * 10); return new Cache(cacheDir, 1024 * 1024 * 10);
@ -51,7 +51,7 @@ public class KogouClient {
return null; return null;
} }
public static Interceptor createCacheControlInterceptor() { private static Interceptor createCacheControlInterceptor() {
return chain -> { return chain -> {
Request modifiedRequest = chain.request().newBuilder() Request modifiedRequest = chain.request().newBuilder()
.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000)) .addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000))
@ -60,7 +60,7 @@ public class KogouClient {
}; };
} }
public static OkHttpClient.Builder createDefaultOkHttpClientBuilder() { private static OkHttpClient.Builder createDefaultOkHttpClientBuilder() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

View File

@ -17,7 +17,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class LastFMRestClient { public class LastFMRestClient {
public static final String BASE_URL = "http://ws.audioscrobbler.com/2.0/"; private static final String BASE_URL = "http://ws.audioscrobbler.com/2.0/";
private LastFMService apiService; private LastFMService apiService;
@ -37,7 +37,7 @@ public class LastFMRestClient {
} }
@Nullable @Nullable
public static Cache createDefaultCache(Context context) { private static Cache createDefaultCache(Context context) {
File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/"); File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/");
if (cacheDir.mkdirs() || cacheDir.isDirectory()) { if (cacheDir.mkdirs() || cacheDir.isDirectory()) {
return new Cache(cacheDir, 1024 * 1024 * 10); return new Cache(cacheDir, 1024 * 1024 * 10);
@ -45,7 +45,7 @@ public class LastFMRestClient {
return null; return null;
} }
public static Interceptor createCacheControlInterceptor() { private static Interceptor createCacheControlInterceptor() {
return chain -> { return chain -> {
Request modifiedRequest = chain.request().newBuilder() Request modifiedRequest = chain.request().newBuilder()
.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000)) .addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000))