Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
[feature/nunu/sharedpreference] SoptampDataStore 수정 (#60)
Browse files Browse the repository at this point in the history
* refactor: datastore inject 방식 변경

* refactor: App에서 사용 안하는 코드 삭제
  • Loading branch information
l2hyunwoo committed Jan 26, 2023
1 parent ae0eb67 commit 3a4900f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
8 changes: 0 additions & 8 deletions app/src/main/java/org/sopt/stamp/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin
import com.facebook.soloader.SoLoader
import dagger.hilt.android.HiltAndroidApp
import org.sopt.stamp.data.local.SoptampDataStoreModule

@HiltAndroidApp
class App : Application() {

private lateinit var dataStore: SoptampDataStoreModule
fun getDataStore(): SoptampDataStoreModule = dataStore
override fun onCreate() {
super.onCreate()
soptampApplication = this
dataStore = SoptampDataStoreModule(this)
initFlipper()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
Expand All @@ -36,7 +30,5 @@ class App : Application() {

companion object {
val networkFlipperPlugin = NetworkFlipperPlugin()
private lateinit var soptampApplication: App
fun getInstance(): App = soptampApplication
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import java.io.IOException
import javax.inject.Inject

class SoptampDataStoreModule(private val context: Context) {

class SoptampDataStore @Inject constructor(
@ApplicationContext private val context: Context
) {
private val Context.dataStore by preferencesDataStore(name = "pref")

/** USER_ID */
Expand Down Expand Up @@ -54,5 +57,4 @@ class SoptampDataStoreModule(private val context: Context) {
pref[PROFILE_MESSAGE] = profileMessage
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.sopt.stamp.App
import org.sopt.stamp.data.local.SoptampDataStore
import org.sopt.stamp.data.repository.RemoteUserRepository
import javax.inject.Inject

@HiltViewModel
class SoptampLoginViewModel @Inject constructor(
private val userRepository: RemoteUserRepository
private val userRepository: RemoteUserRepository,
private val dataStore: SoptampDataStore,
) : ViewModel(), LoginHandleAction {

private val _viewState = MutableStateFlow(SoptampLoginViewState.init())
Expand Down Expand Up @@ -43,8 +44,8 @@ class SoptampLoginViewModel @Inject constructor(
}
if (res.statusCode == 200) {
_singleEvent.trySend(SingleEvent.LoginSuccess)
res.userId?.let { App.getInstance().getDataStore().setUserId(it) }
res.profileMessage?.let { App.getInstance().getDataStore().setProfileMessage(it) }
res.userId?.let { dataStore.setUserId(it) }
res.profileMessage?.let { dataStore.setProfileMessage(it) }
}
}
}
Expand Down

0 comments on commit 3a4900f

Please sign in to comment.