Search in sources :

Example 1 with PerApplication

use of io.hefuyi.listener.injector.scope.PerApplication in project ListenerMusicPlayer by hefuyicoder.

the class NetworkModule method provideLastFMRetrofit.

@Provides
@Named("lastfm")
@PerApplication
Retrofit provideLastFMRetrofit() {
    String endpointUrl = Constants.BASE_API_URL_LASTFM;
    Gson gson = new GsonBuilder().create();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(FileUtil.getHttpCacheDir(ListenerApp.getContext()), Constants.HTTP_CACHE_SIZE)).connectTimeout(Constants.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(Constants.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS).build();
    //        OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(endpointUrl).client(client).addConverterFactory(gsonConverterFactory).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
    return retrofit;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Cache(okhttp3.Cache) Named(javax.inject.Named) PerApplication(io.hefuyi.listener.injector.scope.PerApplication) Provides(dagger.Provides)

Example 2 with PerApplication

use of io.hefuyi.listener.injector.scope.PerApplication in project ListenerMusicPlayer by hefuyicoder.

the class NetworkModule method provideKuGouRetrofit.

@Provides
@Named("kugou")
@PerApplication
Retrofit provideKuGouRetrofit() {
    String endpointUrl = Constants.BASE_API_URL_KUGOU;
    Gson gson = new GsonBuilder().create();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(FileUtil.getHttpCacheDir(ListenerApp.getContext()), Constants.HTTP_CACHE_SIZE)).connectTimeout(Constants.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(Constants.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS).build();
    //        OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(endpointUrl).client(client).addConverterFactory(gsonConverterFactory).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
    return retrofit;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Cache(okhttp3.Cache) Named(javax.inject.Named) PerApplication(io.hefuyi.listener.injector.scope.PerApplication) Provides(dagger.Provides)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Provides (dagger.Provides)2 PerApplication (io.hefuyi.listener.injector.scope.PerApplication)2 Named (javax.inject.Named)2 Cache (okhttp3.Cache)2 OkHttpClient (okhttp3.OkHttpClient)2 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)2 Retrofit (retrofit2.Retrofit)2 GsonConverterFactory (retrofit2.converter.gson.GsonConverterFactory)2