From 77db0a19dfd2c61a8da2516f2d1043724ec0d3d6 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Tue, 9 Jan 2024 22:15:40 +0900 Subject: [PATCH] =?UTF-8?q?[MOD]=20#303=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=8A=A4=ED=81=AC=EB=9E=A9=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/profile/ProfileActivity.kt | 10 +++++----- .../presentation/profile/ProfileViewModel.kt | 14 +++----------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt index c92d55148..21d30c6d7 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileActivity.kt @@ -36,7 +36,6 @@ class ProfileActivity : BindingActivity(R.layout.activit private fun initAdapter() { adapter = ProfileCourseAdapter(onScrapButtonClick = { courseId, scrapTF -> viewModel.postCourseScrap(courseId = courseId, scrapTF = scrapTF) - viewModel.saveScrapCourseData(courseId = courseId, scrapTF = scrapTF) }, onCourseItemClick = { courseId -> navigateToCourseDetail(courseId) }).also { adapter -> @@ -106,10 +105,11 @@ class ProfileActivity : BindingActivity(R.layout.activit } is UiStateV2.Success -> { - viewModel.scrapCourseData.value?.let { scrapCourseData -> - scrapCourseData.let { data -> - adapter.updateCourseItem(courseId = data.first, scrapTF = data.second) - } + state.data?.let { it -> + adapter.updateCourseItem( + courseId = it.publicCourseId.toInt(), + scrapTF = it.scrapTF + ) } } diff --git a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt index 08a9721f4..b518cc418 100644 --- a/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/runnect/runnect/presentation/profile/ProfileViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.runnect.runnect.data.dto.request.RequestPostCourseScrap +import com.runnect.runnect.data.dto.response.ResponsePostScrap import com.runnect.runnect.domain.entity.UserProfile import com.runnect.runnect.domain.repository.CourseRepository import com.runnect.runnect.domain.repository.UserRepository @@ -21,22 +22,14 @@ class ProfileViewModel @Inject constructor( ) : ViewModel() { - private val _courseScrapState = MutableLiveData>() - val courseScrapState: LiveData> + private val _courseScrapState = MutableLiveData>() + val courseScrapState: LiveData> get() = _courseScrapState private val _userProfileState = MutableLiveData>() val userProfileState: LiveData> get() = _userProfileState - private val _scrapCourseData = MutableLiveData>() - - val scrapCourseData: LiveData> - get() = _scrapCourseData - - fun saveScrapCourseData(courseId: Int, scrapTF: Boolean) { - _scrapCourseData.value = Pair(courseId, scrapTF) - } fun getUserProfile(userId: Int) { viewModelScope.launch { @@ -62,7 +55,6 @@ class ProfileViewModel @Inject constructor( fun postCourseScrap(courseId: Int, scrapTF: Boolean) { viewModelScope.launch { _courseScrapState.value = UiStateV2.Loading - courseRepository.postCourseScrap( RequestPostCourseScrap( publicCourseId = courseId, scrapTF = scrapTF.toString()