diff --git a/android/app/src/main/java/com/zzang/chongdae/data/repository/ParticipantRepositoryImpl.kt b/android/app/src/main/java/com/zzang/chongdae/data/repository/ParticipantRepositoryImpl.kt index 2a608e78..6abae202 100644 --- a/android/app/src/main/java/com/zzang/chongdae/data/repository/ParticipantRepositoryImpl.kt +++ b/android/app/src/main/java/com/zzang/chongdae/data/repository/ParticipantRepositoryImpl.kt @@ -10,15 +10,13 @@ import com.zzang.chongdae.domain.util.Result class ParticipantRepositoryImpl( private val participantRemoteDataSource: ParticipantRemoteDataSource, ) : ParticipantRepository { - override suspend fun fetchParticipants(offeringId: Long): Result { - return participantRemoteDataSource.fetchParticipants( + override suspend fun fetchParticipants(offeringId: Long): Result = + participantRemoteDataSource.fetchParticipants( offeringId, ).map { response -> response.toDomain() } - } - override suspend fun deleteParticipations(offeringId: Long): Result { - return participantRemoteDataSource.deleteParticipations(offeringId).map { Unit } - } + override suspend fun deleteParticipations(offeringId: Long): Result = + participantRemoteDataSource.deleteParticipations(offeringId) } diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailActivity.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailActivity.kt index 4fb36fe9..33d45c56 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailActivity.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailActivity.kt @@ -7,6 +7,7 @@ import android.net.Uri import android.os.Bundle import android.view.MotionEvent import android.view.inputmethod.InputMethodManager +import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GravityCompat @@ -25,6 +26,7 @@ import com.zzang.chongdae.presentation.view.commentdetail.adapter.participant.Pa class CommentDetailActivity : AppCompatActivity(), OnUpdateStatusClickListener { private var _binding: ActivityCommentDetailBinding? = null private val binding get() = _binding!! + private var toast: Toast? = null private val commentAdapter: CommentAdapter by lazy { CommentAdapter() } private val participantAdapter: ParticipantAdapter by lazy { ParticipantAdapter() } private val dialog: Dialog by lazy { Dialog(this) } @@ -100,6 +102,7 @@ class CommentDetailActivity : AppCompatActivity(), OnUpdateStatusClickListener { observeReportEvent() observeExitOfferingEvent() observeBackEvent() + observeErrorEvent() } private fun observeComments() { @@ -157,6 +160,19 @@ class CommentDetailActivity : AppCompatActivity(), OnUpdateStatusClickListener { } } + private fun observeErrorEvent() { + viewModel.errorEvent.observe(this) { + toast?.cancel() + toast = + Toast.makeText( + this, + it, + Toast.LENGTH_SHORT, + ) + toast?.show() + } + } + private fun showUpdateStatusDialog() { val dialogBinding = DataBindingUtil.inflate( diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailViewModel.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailViewModel.kt index 564c4a10..7902f70b 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailViewModel.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/commentdetail/CommentDetailViewModel.kt @@ -1,6 +1,5 @@ package com.zzang.chongdae.presentation.view.commentdetail -import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -25,6 +24,7 @@ import com.zzang.chongdae.presentation.view.commentdetail.model.participants.Par import com.zzang.chongdae.presentation.view.commentdetail.model.participants.ParticipantsUiModel.Companion.toUiModel import kotlinx.coroutines.Job import kotlinx.coroutines.delay +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch class CommentDetailViewModel( @@ -65,6 +65,9 @@ class CommentDetailViewModel( private val _onBackPressedEvent = MutableSingleLiveData() val onBackPressedEvent: SingleLiveData get() = _onBackPressedEvent + private val _errorEvent = MutableLiveData() + val errorEvent: MutableLiveData get() = _errorEvent + init { startPolling() updateCommentInfo() @@ -76,7 +79,7 @@ class CommentDetailViewModel( pollJob?.cancel() pollJob = viewModelScope.launch { - while (true) { + while (this.isActive) { loadComments() delay(1000) } @@ -93,9 +96,8 @@ class CommentDetailViewModel( authRepository.saveRefresh() updateCommentInfo() } - else -> { - Log.e("error", "updateCommentInfo: ${result.error}") + errorEvent.value = result.error.name } } } @@ -118,7 +120,7 @@ class CommentDetailViewModel( } else -> { - Log.e("error", "updateOfferingStatus: ${result.error}") + errorEvent.value = result.error.name } } } @@ -139,13 +141,12 @@ class CommentDetailViewModel( is Result.Error -> when (result.error) { DataError.Network.UNAUTHORIZED -> { - Log.d("error", "loadComments: ${result.error}") authRepository.saveRefresh() loadComments() } - else -> { - Log.e("error", "loadComments: ${result.error}") + pollJob?.cancel() + errorEvent.value = result.error.name } } } @@ -170,9 +171,8 @@ class CommentDetailViewModel( authRepository.saveRefresh() postComment() } - else -> { - Log.e("error", "postComment: ${result.error}") + errorEvent.value = result.error.name } } } @@ -196,9 +196,8 @@ class CommentDetailViewModel( authRepository.saveRefresh() loadParticipants() } - else -> { - Log.e("error", "loadParticipants: ${result.error}") + errorEvent.value = result.error.name } } } @@ -215,9 +214,8 @@ class CommentDetailViewModel( authRepository.saveRefresh() loadMeetings() } - else -> { - Log.e("error", "loadMeetings: ${result.error}") + errorEvent.value = result.error.name } } } @@ -231,16 +229,22 @@ class CommentDetailViewModel( fun exitOffering() { viewModelScope.launch { when (val result = participantRepository.deleteParticipations(offeringId)) { - is Result.Success -> _onExitOfferingEvent.setValue(Unit) + is Result.Success -> { + _onExitOfferingEvent.setValue(Unit) + pollJob?.cancel() + } is Result.Error -> when (result.error) { + DataError.Network.NULL -> { + _onExitOfferingEvent.setValue(Unit) + pollJob?.cancel() + } DataError.Network.UNAUTHORIZED -> { authRepository.saveRefresh() exitOffering() } - else -> { - Log.e("error", "exitOffering: ${result.error}") + _errorEvent.value = result.error.name } } } diff --git a/android/app/src/main/java/com/zzang/chongdae/presentation/view/offeringdetail/OfferingDetailFragment.kt b/android/app/src/main/java/com/zzang/chongdae/presentation/view/offeringdetail/OfferingDetailFragment.kt index 3ae8d1c0..1801288b 100644 --- a/android/app/src/main/java/com/zzang/chongdae/presentation/view/offeringdetail/OfferingDetailFragment.kt +++ b/android/app/src/main/java/com/zzang/chongdae/presentation/view/offeringdetail/OfferingDetailFragment.kt @@ -12,6 +12,7 @@ import androidx.core.os.bundleOf import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels +import androidx.navigation.fragment.findNavController import com.google.firebase.analytics.FirebaseAnalytics import com.zzang.chongdae.ChongdaeApp import com.zzang.chongdae.databinding.FragmentOfferingDetailBinding @@ -104,13 +105,13 @@ class OfferingDetailFragment : Fragment() { } private fun setUpMoveCommentDetailEventObserve() { - viewModel.commentDetailEvent.observe(this) { offeringTitle -> - + viewModel.commentDetailEvent.observe(this) { firebaseAnalyticsManager.logSelectContentEvent( id = "Offering_Item_ID: $offeringId", name = "participate_offering_event", contentType = "button", ) + findNavController().popBackStack() CommentDetailActivity.startActivity(requireContext(), offeringId) } }