From be0ae278233c0061cd716d7a474f3495b5a58cc0 Mon Sep 17 00:00:00 2001 From: 0se0 <030ggong@gmail.com> Date: Wed, 26 Jun 2024 13:44:03 +0900 Subject: [PATCH] Feature #38: UserDataStoreImpl --- .../compose/data/local/UserDataStoreImpl.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/compose/data/local/UserDataStoreImpl.kt diff --git a/app/src/main/java/com/sopt/now/compose/data/local/UserDataStoreImpl.kt b/app/src/main/java/com/sopt/now/compose/data/local/UserDataStoreImpl.kt new file mode 100644 index 0000000..1f17cc7 --- /dev/null +++ b/app/src/main/java/com/sopt/now/compose/data/local/UserDataStoreImpl.kt @@ -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" + } +} \ No newline at end of file