Skip to content

Commit

Permalink
MONEYMONG-374 feat: UserPreferencesModule -> DataStoreModule 로 이관
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Jun 10, 2024
1 parent c564567 commit e5ed3e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import java.io.IOException
import javax.inject.Inject
import javax.inject.Named

class AgencyLocalDataSourceImpl @Inject constructor(
private val userDataStorePreferences: DataStore<Preferences>
): AgencyLocalDataSource {
@Named("user") private val userDataStorePreferences: DataStore<Preferences>
) : AgencyLocalDataSource {
override suspend fun saveAgencyId(agencyId: Int) {
userDataStorePreferences.edit { preferences ->
preferences[AGENCY_ID] = agencyId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import java.io.IOException
import javax.inject.Inject
import javax.inject.Named

class UserLocalDataSourceImpl @Inject constructor(
private val userDataStorePreferences: DataStore<Preferences>
): UserLocalDataSource {
@Named("user") private val userDataStorePreferences: DataStore<Preferences>
) : UserLocalDataSource {


override suspend fun saveUserId(userId: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.moneymong.moneymong.data.di

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import dagger.Module
import dagger.Provides
Expand All @@ -15,12 +17,22 @@ import javax.inject.Singleton
object DataStoreModule {

private const val LEDGER_DATASTORE_NAME = "LEDGER_PREFERENCES"
private val Context.ledgerDataStore by preferencesDataStore(name = LEDGER_DATASTORE_NAME)
private const val USER_DATASTORE_NAME = "USER_PREFERENCES"

private val Context.ledgerDataStore: DataStore<Preferences> by preferencesDataStore(name = LEDGER_DATASTORE_NAME)
private val Context.userDataStore: DataStore<Preferences> by preferencesDataStore(name = USER_DATASTORE_NAME)

@Provides
@Singleton
@Named("ledger")
fun provideLedgerDataStore(
fun provideLedgerPreferencesDataStore(
@ApplicationContext context: Context,
) = context.ledgerDataStore
): DataStore<Preferences> = context.ledgerDataStore

@Provides
@Singleton
@Named("user")
fun provideUserPreferencesDataStore(
@ApplicationContext context: Context
): DataStore<Preferences> = context.userDataStore
}

This file was deleted.

0 comments on commit e5ed3e4

Please sign in to comment.