diff --git a/app/src/main/java/com/sopt/now/compose/data/UserPreference.kt b/app/src/main/java/com/sopt/now/compose/data/UserPreference.kt index 3447c18..74afb8c 100644 --- a/app/src/main/java/com/sopt/now/compose/data/UserPreference.kt +++ b/app/src/main/java/com/sopt/now/compose/data/UserPreference.kt @@ -3,28 +3,32 @@ package com.sopt.now.compose.data import android.content.Context import androidx.core.content.edit +import com.sopt.now.compose.data.UserPreference.UserPreferenceKeys.KEY_USER_ID +import com.sopt.now.compose.data.UserPreference.UserPreferenceKeys.KEY_USER_NAME +import com.sopt.now.compose.data.UserPreference.UserPreferenceKeys.KEY_USER_PHONE +import com.sopt.now.compose.data.UserPreference.UserPreferenceKeys.PREF_USER_DATA class UserPreference(context: Context) { - private val sharedPreferences = context.applicationContext.getSharedPreferences("userData", Context.MODE_PRIVATE) + private val sharedPreferences = context.applicationContext.getSharedPreferences(PREF_USER_DATA, Context.MODE_PRIVATE) // 사용자 아이디 저장 fun saveUserId(userId: String) { sharedPreferences.edit { - putString("userId", userId) + putString(KEY_USER_ID, userId) } } // 사용자 아이디 가져오기 fun getUserId(): String? { - return sharedPreferences.getString("userId", null) + return sharedPreferences.getString(KEY_USER_ID, null) } // 사용자 데이터 저장 fun saveUserData(userData: UserData) { sharedPreferences.edit { - putString("userId", userData.userId) - putString("userName", userData.userName) - putString("userPhone", userData.userPhone) + putString(KEY_USER_ID, userData.userId) + putString(KEY_USER_NAME, userData.userName) + putString(KEY_USER_PHONE, userData.userPhone) } } @@ -42,4 +46,10 @@ class UserPreference(context: Context) { } } } + object UserPreferenceKeys { + const val PREF_USER_DATA = "userData" + const val KEY_USER_ID = "userId" + const val KEY_USER_NAME = "userName" + const val KEY_USER_PHONE = "userPhone" + } } \ No newline at end of file