-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApiModule.kt
More file actions
40 lines (35 loc) · 1.36 KB
/
ApiModule.kt
File metadata and controls
40 lines (35 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example.githubfirebaseissue.di.module
import com.example.githubfirebaseissue.api.ApiConstant
import com.example.githubfirebaseissue.api.GithubApi
import com.example.githubfirebaseissue.common.BaseSchedulerProvider
import com.example.githubfirebaseissue.common.RxScheduler
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
@InstallIn(SingletonComponent::class)
@Module(includes = [InterceptorModule::class, RepositoryModule::class])
abstract class ApiModule {
companion object {
@Provides
fun provideRetrofit(client: OkHttpClient): Retrofit {
return Retrofit.Builder()
.baseUrl(ApiConstant.GITHUB_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(client)
.build()
}
@Provides
fun provideApiInterface(retrofit: Retrofit): GithubApi {
return retrofit.create(GithubApi::class.java)
}
}
@Binds
abstract fun provideRxScheduler(scheduler: BaseSchedulerProvider): RxScheduler
}