Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Module
- public class ApiModule {
- @Provides
- @Singleton
- Retrofit provideRetrofit(OkHttpClient okHttpClient) {
- return new Retrofit.Builder()
- .baseUrl(BASE_URL)
- .client(okHttpClient)
- .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
- .addConverterFactory(GsonConverterFactory.create())
- .build();
- }
- @Provides
- @Singleton
- OkHttpClient provideHttpClient(Context context) {
- HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
- interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
- OkHttpClient.Builder builder = new OkHttpClient.Builder()
- .addInterceptor(interceptor)
- .addInterceptor(chain -> {
- if (!Utils.isOnline(context)) {
- throw new NoInternetException();
- }
- return chain.proceed(chain.request());
- });
- return builder.build();
- }
- @Provides
- @Singleton
- FitAPI provideApi(Retrofit retrofit) {
- return retrofit.create(FitAPI.class);
- }
- @Provides
- @Singleton
- public ApiController provideApiController(FitAPI fitAPI) {
- return new ApiController(fitAPI);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement