Skip to content

Commit

Permalink
#3 added DispatcherProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
nastix123 committed Jul 14, 2024
1 parent 47d3085 commit 245d18d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package by.eapp.musicroom.data

import by.eapp.musicroom.domain.DispatcherProvider
import by.eapp.musicroom.domain.repo.DispatcherProvider
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

Expand Down
45 changes: 34 additions & 11 deletions android/app/src/main/java/by/eapp/musicroom/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package by.eapp.musicroom.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.preferencesDataStoreFile
import by.eapp.musicroom.data.DispatcherProviderImpl
import by.eapp.musicroom.data.StatusRepo
import by.eapp.musicroom.domain.DispatcherProvider
import by.eapp.musicroom.domain.repo.StatusRepository
import by.eapp.musicroom.network.RegistrationService
import by.eapp.musicroom.data.login.JwtTokenStorage
import by.eapp.musicroom.domain.repo.DispatcherProvider
import by.eapp.musicroom.domain.repo.login.JwtTokenManager
import by.eapp.musicroom.network.ApiService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -45,19 +53,34 @@ object AppModule {
@Provides
fun provideBaseUrl(): String = "https://localhost:8080/"

@Provides

@Singleton
fun provideApiService(retrofit: Retrofit): RegistrationService =
retrofit.create(RegistrationService::class.java)
@Provides
fun provideApiService(retrofit: Retrofit): ApiService = retrofit.create(ApiService::class.java)


@Provides
@Singleton
fun provideDispatcherProvider(): DispatcherProvider = DispatcherProviderImpl()

@Provides
fun provideStatusRepository(registrationService: RegistrationService): StatusRepository {
return StatusRepo(registrationService)
@Singleton
fun provideDataStore(
@ApplicationContext appContext: Context,
): DataStore<Preferences> {
return PreferenceDataStoreFactory.create(
corruptionHandler = ReplaceFileCorruptionHandler(
produceNewData = { emptyPreferences() }
),
produceFile = { appContext.preferencesDataStoreFile("auth_datastore") }
)
}


@Provides
@Singleton
fun provideDispatcherProvider(): DispatcherProvider = DispatcherProviderImpl()
fun provideJwtTokenManager(dataStore: DataStore<Preferences>):
JwtTokenManager = JwtTokenStorage(dataStore)

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package by.eapp.musicroom.domain
package by.eapp.musicroom.domain.repo

import kotlinx.coroutines.CoroutineDispatcher

Expand Down

0 comments on commit 245d18d

Please sign in to comment.