Provide the prefs data store, also separate out the retrofit client into its own di module
This commit is contained in:
parent
87ac520896
commit
29893f9ee7
4 changed files with 55 additions and 16 deletions
|
@ -25,7 +25,7 @@ object PrefsDataStoreSerializer : Serializer<PrefsDataStore> {
|
||||||
override suspend fun writeTo(t: PrefsDataStore, output: OutputStream) = t.writeTo(output)
|
override suspend fun writeTo(t: PrefsDataStore, output: OutputStream) = t.writeTo(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
val Context.dataStore: DataStore<PrefsDataStore> by dataStore(
|
val Context.prefsDataStore: DataStore<PrefsDataStore> by dataStore(
|
||||||
fileName = "prefs_data_store.proto",
|
fileName = "prefs_data_store.proto",
|
||||||
serializer = PrefsDataStoreSerializer
|
serializer = PrefsDataStoreSerializer
|
||||||
)
|
)
|
|
@ -17,21 +17,6 @@ import javax.inject.Singleton
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
object AuthRepositoryModule {
|
object AuthRepositoryModule {
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
fun provideHttpClient(): Retrofit {
|
|
||||||
return Retrofit.Builder()
|
|
||||||
.baseUrl(BuildConfig.API_BASE_URL)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
|
||||||
.client(OkHttpClient.Builder()
|
|
||||||
.addInterceptor(HttpLoggingInterceptor().apply {
|
|
||||||
level = HttpLoggingInterceptor.Level.BODY
|
|
||||||
})
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideAuthRepository(httpClient: Retrofit): AuthRepository {
|
fun provideAuthRepository(httpClient: Retrofit): AuthRepository {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package ing.bikeshedengineer.debtpirate.di.modules
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import ing.bikeshedengineer.debtpirate.BuildConfig
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
object HttpClientModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideHttpClient(): Retrofit {
|
||||||
|
return Retrofit.Builder()
|
||||||
|
.baseUrl(BuildConfig.API_BASE_URL)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.client(OkHttpClient.Builder()
|
||||||
|
.addInterceptor(HttpLoggingInterceptor().apply {
|
||||||
|
level = HttpLoggingInterceptor.Level.BODY
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package ing.bikeshedengineer.debtpirate.di.modules
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import androidx.datastore.core.DataStore
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import ing.bikeshedengineer.debtpirate.PrefsDataStore
|
||||||
|
import ing.bikeshedengineer.debtpirate.data.pref.prefsDataStore
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
object PrefsDataStoreProvider {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun providePrefsDataStore(application: Application): DataStore<PrefsDataStore> {
|
||||||
|
return application.prefsDataStore
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue