Skip to content

Commit

Permalink
[feat] UserCodeDataStore - userId 추가 (#30)
Browse files Browse the repository at this point in the history
[feat] userId 추가
  • Loading branch information
murjune authored Feb 3, 2024
1 parent 62bb831 commit 7a1ff40
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import javax.inject.Singleton
class DefaultUserCodeDataStore @Inject constructor(
private val preferences: SharedPreferences,
@ApplicationContext private val context: Context,
) : UserCodeDataStore() {
) : UserCodeDataStore {

override var userId: String
override var deviceId: String
get() {
initUserId()
initDeviceId()
return preferences.getString(DEVICE_ID, "").orEmpty()
}
set(value) {
Expand All @@ -27,7 +27,7 @@ class DefaultUserCodeDataStore @Inject constructor(
}
}

private fun initUserId() {
private fun initDeviceId() {
if (preferences.contains(DEVICE_ID).not()) {
userId = Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)
}
Expand All @@ -40,11 +40,22 @@ class DefaultUserCodeDataStore @Inject constructor(
putString(USER_CODE, value)
}
}
override var userId: String
get() = preferences.getString(USER_ID, "").orEmpty()
set(value) {
preferences.edit(commit = true) {
putString(USER_ID, value)
}
}

override fun hasUserCode(): Boolean {
return preferences.contains(USER_CODE)
}

override fun hasUserId(): Boolean {
return preferences.contains(USER_ID)
}

override fun clear() {
preferences.edit(commit = true) {
clear()
Expand All @@ -54,5 +65,6 @@ class DefaultUserCodeDataStore @Inject constructor(
private companion object {
const val DEVICE_ID = "DEVICE_ID"
const val USER_CODE = "USER_CODE"
const val USER_ID = "USER_ID"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.moya.funch.datastore

abstract class UserCodeDataStore {
interface UserCodeDataStore {

abstract var userId: String
abstract var userCode: String
var userId: String
var userCode: String
var deviceId: String

abstract fun hasUserCode(): Boolean
fun hasUserCode(): Boolean

abstract fun clear()
fun hasUserId(): Boolean

fun clear()
}

0 comments on commit 7a1ff40

Please sign in to comment.