Skip to content

Commit

Permalink
Feature #38: UserDataStoreImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
0se0 committed Jun 26, 2024
1 parent 8c445dc commit be0ae27
Showing 1 changed file with 47 additions and 0 deletions.
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"
}
}

0 comments on commit be0ae27

Please sign in to comment.