-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add DataStoreModule & DataSourceModule
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
.../datastore/src/main/java/com/goalpanzi/mission_mate/core/datastore/di/DataSourceModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.goalpanzi.mission_mate.core.datastore.di | ||
|
||
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource | ||
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSourceImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class DataSourceModule { | ||
|
||
@Binds | ||
abstract fun bindAuthDataSource( | ||
authDataSource: AuthDataSourceImpl | ||
): AuthDataSource | ||
} |
29 changes: 29 additions & 0 deletions
29
core/datastore/src/main/java/com/goalpanzi/mission_mate/core/datastore/di/DataStoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.goalpanzi.mission_mate.core.datastore.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStoreFile | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
private const val AUTH_PREFERENCES = "auth_preferences" | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
object DataStoreModule { | ||
@Singleton | ||
@Provides | ||
fun provideAuthPreferencesDataStore( | ||
@ApplicationContext context: Context | ||
): DataStore<Preferences> { | ||
return PreferenceDataStoreFactory.create( | ||
produceFile = { context.preferencesDataStoreFile(AUTH_PREFERENCES) } | ||
) | ||
} | ||
} |