From 9c6a270e4c6369c5254bea1cf32a17efea90b5cf Mon Sep 17 00:00:00 2001 From: wbham Date: Wed, 20 Sep 2023 19:14:46 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#187=20-=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 리뷰 삭제 버튼 클릭 시 확인 문구 한번 출력 --- .../cazait/ui/cafeinfo/CafeInfoViewModel.kt | 18 +++++++++-- .../cafeinfo/detail/CafeInfoReviewFragment.kt | 30 ++++++++++++++++++- .../cazait/ui/review/ReviewWriteFragment.kt | 23 ++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/cazait/ui/cafeinfo/CafeInfoViewModel.kt b/app/src/main/java/org/cazait/ui/cafeinfo/CafeInfoViewModel.kt index 0f4583a..e24a073 100644 --- a/app/src/main/java/org/cazait/ui/cafeinfo/CafeInfoViewModel.kt +++ b/app/src/main/java/org/cazait/ui/cafeinfo/CafeInfoViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import org.bmsk.data.repository.CafeRepository @@ -41,6 +42,10 @@ class CafeInfoViewModel @Inject constructor( val favoriteData: LiveData> get() = _favoriteData + private val _messageLiveData = MutableLiveData>() + val messageLiveData: LiveData> + get() = _messageLiveData + private val _showToast = MutableLiveData>() val showToast: LiveData> get() = _showToast @@ -66,7 +71,7 @@ class CafeInfoViewModel @Inject constructor( } } - fun getReviews(cafeId: String, sortBy: String?, nums:Int, score: Int?) { + fun getReviews(cafeId: String, sortBy: String?, nums: Int, score: Int?) { viewModelScope.launch { _listReviewData.value = Resource.Loading() cafeRepository.getReviews(cafeId, sortBy, nums, score).collect { @@ -75,6 +80,15 @@ class CafeInfoViewModel @Inject constructor( } } + fun deleteReviews(reviewId: String) { + viewModelScope.launch { + _messageLiveData.value = Resource.Loading() + cafeRepository.deleteReviewAuth(reviewId).collect { + _messageLiveData.value = it + } + } + } + fun postFavoriteCafeAuth() { viewModelScope.launch { Log.d("즐겨찾기 등록 전 상태", _isFavoriteCafe.value.toString()) @@ -112,7 +126,7 @@ class CafeInfoViewModel @Inject constructor( viewModelScope.launch { val cafeWithTimestamp = cafe.copy(timestamp = System.currentTimeMillis()) cafeRepository.insertRecentlyViewedCafe(cafeWithTimestamp) - Log.e("cafeId1",cafeWithTimestamp.cafeId) + Log.e("cafeId1", cafeWithTimestamp.cafeId) } } diff --git a/app/src/main/java/org/cazait/ui/cafeinfo/detail/CafeInfoReviewFragment.kt b/app/src/main/java/org/cazait/ui/cafeinfo/detail/CafeInfoReviewFragment.kt index 2dcd2c3..b0cc6b0 100644 --- a/app/src/main/java/org/cazait/ui/cafeinfo/detail/CafeInfoReviewFragment.kt +++ b/app/src/main/java/org/cazait/ui/cafeinfo/detail/CafeInfoReviewFragment.kt @@ -89,6 +89,7 @@ class CafeInfoReviewFragment( private fun observeViewModel() { observe(viewModel.listReviewData, ::handleCafeReview) + observe(viewModel.messageLiveData, ::handleDeleteReview) } private fun handleCafeReview(status: Resource) { @@ -120,6 +121,27 @@ class CafeInfoReviewFragment( } } + private fun handleDeleteReview(status: Resource){ + when(status){ + is Resource.Loading -> { + binding.lottieReview.toVisible() + binding.lottieReview.playAnimation() + } + + is Resource.Success -> status.data.let { + binding.lottieReview.pauseAnimation() + binding.lottieReview.toGone() + viewModel.showToastMessage(it) + } + + is Resource.Error -> { + binding.lottieReview.pauseAnimation() + binding.lottieReview.toGone() + viewModel.showToastMessage(status.message) + } + } + } + private fun navigateToReviewWriteFragment(cafe: Cafe, score: Float, content: String, reviewId:String?) { val parentFragment = parentFragment Log.d("CafeInfoReviewFragment의 부모 Fragment는 누구?", parentFragment.toString()) @@ -141,7 +163,13 @@ class CafeInfoReviewFragment( } override fun onDeleteClick(item: CafeReview) { - + AlertDialog.Builder(requireContext()) + .setMessage(resources.getString(R.string.review_delete_confirm)) + .setPositiveButton("확인") { dialog, which -> + viewModel.deleteReviews(item.reviewId) + dialog.dismiss() + } + .show() } override fun onReportClick(item: CafeReview) { diff --git a/app/src/main/java/org/cazait/ui/review/ReviewWriteFragment.kt b/app/src/main/java/org/cazait/ui/review/ReviewWriteFragment.kt index 38d98d8..e34d52f 100644 --- a/app/src/main/java/org/cazait/ui/review/ReviewWriteFragment.kt +++ b/app/src/main/java/org/cazait/ui/review/ReviewWriteFragment.kt @@ -41,6 +41,7 @@ class ReviewWriteFragment : BaseFragment){ + when(status){ + is Resource.Loading -> { + binding.lottieReviewWrite.toVisible() + binding.lottieReviewWrite.playAnimation() + } + + is Resource.Success -> status.data.let { + binding.lottieReviewWrite.pauseAnimation() + binding.lottieReviewWrite.toGone() + viewModel.showToastMessage(it) + findNavController().popBackStack() + } + + is Resource.Error -> { + binding.lottieReviewWrite.pauseAnimation() + binding.lottieReviewWrite.toGone() + viewModel.showToastMessage(status.message) + } + } + } + private fun setReviewSendBtn() { binding.btnSendReview.setOnClickListener { val reviewId = navArgs.reviewId diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be4e1e2..bfdbac7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -100,6 +100,7 @@ 수정 삭제 신고 + 정말로 삭제하시겠습니까? 아메리카노