From 245d18d53d98e1a5885c2922759413dee2bdea93 Mon Sep 17 00:00:00 2001 From: anastasizzz Date: Sun, 14 Jul 2024 23:56:55 +0300 Subject: [PATCH] #3 added DispatcherProvider --- .../musicroom/data/DispatcherProviderImpl.kt | 2 +- .../java/by/eapp/musicroom/di/AppModule.kt | 45 ++++++++++++++----- .../domain/{ => repo}/DispatcherProvider.kt | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-) rename android/app/src/main/java/by/eapp/musicroom/domain/{ => repo}/DispatcherProvider.kt (85%) diff --git a/android/app/src/main/java/by/eapp/musicroom/data/DispatcherProviderImpl.kt b/android/app/src/main/java/by/eapp/musicroom/data/DispatcherProviderImpl.kt index 35d762d..1ffab60 100644 --- a/android/app/src/main/java/by/eapp/musicroom/data/DispatcherProviderImpl.kt +++ b/android/app/src/main/java/by/eapp/musicroom/data/DispatcherProviderImpl.kt @@ -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 diff --git a/android/app/src/main/java/by/eapp/musicroom/di/AppModule.kt b/android/app/src/main/java/by/eapp/musicroom/di/AppModule.kt index ff51551..c468fef 100644 --- a/android/app/src/main/java/by/eapp/musicroom/di/AppModule.kt +++ b/android/app/src/main/java/by/eapp/musicroom/di/AppModule.kt @@ -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 @@ -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 { + return PreferenceDataStoreFactory.create( + corruptionHandler = ReplaceFileCorruptionHandler( + produceNewData = { emptyPreferences() } + ), + produceFile = { appContext.preferencesDataStoreFile("auth_datastore") } + ) } + @Provides @Singleton - fun provideDispatcherProvider(): DispatcherProvider = DispatcherProviderImpl() + fun provideJwtTokenManager(dataStore: DataStore): + JwtTokenManager = JwtTokenStorage(dataStore) + +} -} \ No newline at end of file diff --git a/android/app/src/main/java/by/eapp/musicroom/domain/DispatcherProvider.kt b/android/app/src/main/java/by/eapp/musicroom/domain/repo/DispatcherProvider.kt similarity index 85% rename from android/app/src/main/java/by/eapp/musicroom/domain/DispatcherProvider.kt rename to android/app/src/main/java/by/eapp/musicroom/domain/repo/DispatcherProvider.kt index afb7ee8..16611b6 100644 --- a/android/app/src/main/java/by/eapp/musicroom/domain/DispatcherProvider.kt +++ b/android/app/src/main/java/by/eapp/musicroom/domain/repo/DispatcherProvider.kt @@ -1,4 +1,4 @@ -package by.eapp.musicroom.domain +package by.eapp.musicroom.domain.repo import kotlinx.coroutines.CoroutineDispatcher