generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
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.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/sopt/now/compose/data/local/UserDataStoreImpl.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,47 @@ | ||
package com.sopt.now.compose.data.local | ||
|
||
import android.content.SharedPreferences | ||
import androidx.core.content.edit | ||
import javax.inject.Inject | ||
|
||
class UserDataStoreImpl @Inject constructor( | ||
private val dataStore: SharedPreferences, | ||
) : UserDataStore { | ||
override var userId: String | ||
get() = dataStore.getString(USER_ID, "").orEmpty() | ||
set(value) = dataStore.edit { putString(USER_ID, value) } | ||
|
||
override var id: String | ||
get() = dataStore.getString(ID, "").orEmpty() | ||
set(value) = dataStore.edit { putString(ID, value) } | ||
|
||
override var password: String | ||
get() = dataStore.getString(PASSWORD, "").orEmpty() | ||
set(value) = dataStore.edit { putString(PASSWORD, value) } | ||
|
||
override var nickname: String | ||
get() = dataStore.getString(NICKNAME, "").orEmpty() | ||
set(value) = dataStore.edit { putString(NICKNAME, value) } | ||
|
||
override var phoneNumber: String | ||
get() = dataStore.getString(PHONE_NUMBER, "").orEmpty() | ||
set(value) = dataStore.edit { putString(PHONE_NUMBER, value) } | ||
|
||
override var isLoggedIn: Boolean | ||
get() = dataStore.getBoolean(IS_LOGGED_IN, false) | ||
set(value) = dataStore.edit { putBoolean(IS_LOGGED_IN, value) } | ||
|
||
|
||
override fun clearInfo() { | ||
dataStore.edit().clear().commit() | ||
} | ||
|
||
companion object { | ||
private const val USER_ID = "userId" | ||
private const val ID = "id" | ||
private const val PASSWORD = "password" | ||
private const val NICKNAME = "nickname" | ||
private const val PHONE_NUMBER = "phoneNumber" | ||
private const val IS_LOGGED_IN = "isLoggedIn" | ||
} | ||
} |