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
1 parent
6ab7a9e
commit 230598d
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/sopt/now/compose/data/UserPreference.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,48 @@ | ||
package com.sopt.now.compose.data | ||
|
||
import android.content.Context | ||
|
||
class UserPreference(context: Context) { | ||
private val sharedPreferences = context.getSharedPreferences("userData", Context.MODE_PRIVATE) | ||
|
||
// 사용자 아이디 저장 | ||
fun saveUserId(userId: String) { | ||
with(sharedPreferences.edit()){ | ||
putString("userId", userId) | ||
apply() | ||
} | ||
} | ||
|
||
// 사용자 데이터 가져오기 | ||
fun getUserId(): String? { | ||
with(sharedPreferences){ | ||
val userId = getString("userId", null) | ||
return userId | ||
} | ||
} | ||
|
||
// 사용자 데이터 저장 | ||
fun saveUserData(userData: UserData) { | ||
with(sharedPreferences.edit()){ | ||
putString("userId", userData.userId) | ||
putString("userName", userData.userName) | ||
putString("userPhone", userData.userPhone) | ||
apply() | ||
} | ||
} | ||
|
||
// 사용자 데이터 가져오기 | ||
fun getUserData(): UserData? { | ||
with(sharedPreferences){ | ||
val userId = getString("userId", null) | ||
val userName = getString("userName", null) | ||
val userPhone = getString("userPhone", null) | ||
|
||
return if (userId != null && userName != null && userPhone != null) { | ||
UserData(userId, userName, userPhone) | ||
} else { | ||
null | ||
} | ||
} | ||
} | ||
} |