Skip to content

Commit

Permalink
feat: UserInfo 를 저장할 수 있다.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed May 1, 2024
1 parent 3fc1dd0 commit 3e6b178
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.festago.festago.data.datasource.userinfo

import com.festago.festago.data.model.UserInfoEntity

interface UserInfoDataSource {
var userInfo: UserInfoEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.festago.festago.data.datasource.userinfo

import android.content.Context
import android.content.SharedPreferences
import com.festago.festago.data.model.UserInfoEntity
import com.festago.festago.data.util.getObject
import com.festago.festago.data.util.putObject
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class UserInfoLocalDataSource @Inject constructor(
@ApplicationContext context: Context,
) : UserInfoDataSource {

private val sharedPreference: SharedPreferences by lazy {
context.getSharedPreferences(USER_INFO_PREF, Context.MODE_PRIVATE)
}

override var userInfo: UserInfoEntity?
get() = sharedPreference.getObject<UserInfoEntity>(USER_ID_KEY, null)
set(value) {
sharedPreference.putObject<UserInfoEntity>(USER_ID_KEY, value)
}

companion object {
private const val USER_INFO_PREF = "user_info_pref"
private const val USER_ID_KEY = "user_info_key"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.festago.festago.data.model

data class UserInfoEntity(
val nickname: String,
val profileImageUrl: String,
)

0 comments on commit 3e6b178

Please sign in to comment.