Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 홈 화면 강아지 체중 dataStore에 저장 #86

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.project.meongcare.home.model.data.local

import android.content.Context
import androidx.datastore.preferences.core.doublePreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
Expand All @@ -20,6 +21,7 @@ class DogPreferences
) {
private val preferenceDogId = longPreferencesKey("dogId")
private val preferenceDogName = stringPreferencesKey("dogName")
private val preferenceDogWeight = doublePreferencesKey("dogWeight")

private suspend fun editDogId(dogId: Long) {
context.dogDataStore.edit { preferences ->
Expand All @@ -33,6 +35,12 @@ class DogPreferences
}
}

private suspend fun editDogWeight(dogWeight: Double) {
context.dogDataStore.edit { preferences ->
preferences[preferenceDogWeight] = dogWeight
}
}

fun setDogId(dogId: Long) {
CoroutineScope(Dispatchers.IO).launch {
editDogId(dogId)
Expand All @@ -45,6 +53,12 @@ class DogPreferences
}
}

fun setDogWeight(dogWeight: Double) {
CoroutineScope(Dispatchers.IO).launch {
editDogWeight(dogWeight)
}
}

val dogId: Flow<Long?> =
context.dogDataStore.data.map { preferences ->
preferences[preferenceDogId]
Expand All @@ -54,4 +68,9 @@ class DogPreferences
context.dogDataStore.data.map { preferences ->
preferences[preferenceDogName]
}

val dogWeight: Flow<Double?> =
context.dogDataStore.data.map { preferences ->
preferences[preferenceDogWeight]
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.home.view
package com.project.meongcare.home.model.data.local

interface DogProfileClickListener {
fun onDogProfileClick(pos: Int)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.meongcare.home.view
package com.project.meongcare.home.model.data.local

interface HorizonCalendarItemClickListener {
fun onItemClick(position: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.project.meongcare.R
import com.project.meongcare.databinding.ItemHomeDogProfileBinding
import com.project.meongcare.home.model.data.local.DogProfileClickListener
import com.project.meongcare.home.model.entities.DogProfile
import de.hdodenhof.circleimageview.CircleImageView

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.project.meongcare.MainActivity
import com.project.meongcare.R
import com.project.meongcare.databinding.FragmentHomeBinding
import com.project.meongcare.home.model.data.local.DogPreferences
import com.project.meongcare.home.model.data.local.DogProfileClickListener
import com.project.meongcare.home.model.data.local.HorizonCalendarItemClickListener
import com.project.meongcare.home.viewmodel.HomeViewModel
import com.project.meongcare.login.model.data.local.UserPreferences
import com.project.meongcare.onboarding.model.data.local.DateSubmitListener
Expand Down Expand Up @@ -182,6 +184,7 @@ class HomeFragment : Fragment(), DateSubmitListener, DogProfileClickListener, Ho
if (dogWeight != null) {
Log.d("homeDogWeight", dogWeight.weight.toString())
fragmentHomeBinding.textviewHomeWeight.text = dogWeight.weight.toString()
dogPreferences.setDogWeight(dogWeight.weight)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.project.meongcare.R
import com.project.meongcare.databinding.ItemToolbarCalendarWeekBinding
import com.project.meongcare.home.model.data.local.HorizonCalendarItemClickListener
import com.project.meongcare.toolbar.view.getDate
import com.project.meongcare.toolbar.view.getDay
import java.util.Date
Expand Down