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: 댓글방 에러핸들링 #439

Merged
merged 1 commit into from
Aug 22, 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
Expand Up @@ -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<Participants, DataError.Network> {
return participantRemoteDataSource.fetchParticipants(
override suspend fun fetchParticipants(offeringId: Long): Result<Participants, DataError.Network> =
participantRemoteDataSource.fetchParticipants(
offeringId,
).map { response ->
response.toDomain()
}
}

override suspend fun deleteParticipations(offeringId: Long): Result<Unit, DataError.Network> {
return participantRemoteDataSource.deleteParticipations(offeringId).map { Unit }
}
override suspend fun deleteParticipations(offeringId: Long): Result<Unit, DataError.Network> =
participantRemoteDataSource.deleteParticipations(offeringId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand Down Expand Up @@ -100,6 +102,7 @@ class CommentDetailActivity : AppCompatActivity(), OnUpdateStatusClickListener {
observeReportEvent()
observeExitOfferingEvent()
observeBackEvent()
observeErrorEvent()
}

private fun observeComments() {
Expand Down Expand Up @@ -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<DialogUpdateStatusBinding>(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -65,6 +65,9 @@ class CommentDetailViewModel(
private val _onBackPressedEvent = MutableSingleLiveData<Unit>()
val onBackPressedEvent: SingleLiveData<Unit> get() = _onBackPressedEvent

private val _errorEvent = MutableLiveData<String>()
val errorEvent: MutableLiveData<String> get() = _errorEvent

init {
startPolling()
updateCommentInfo()
Expand All @@ -76,7 +79,7 @@ class CommentDetailViewModel(
pollJob?.cancel()
pollJob =
viewModelScope.launch {
while (true) {
while (this.isActive) {
loadComments()
delay(1000)
}
Expand All @@ -93,9 +96,8 @@ class CommentDetailViewModel(
authRepository.saveRefresh()
updateCommentInfo()
}

else -> {
Log.e("error", "updateCommentInfo: ${result.error}")
errorEvent.value = result.error.name
}
}
}
Expand All @@ -118,7 +120,7 @@ class CommentDetailViewModel(
}

else -> {
Log.e("error", "updateOfferingStatus: ${result.error}")
errorEvent.value = result.error.name
}
}
}
Expand All @@ -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
}
}
}
Expand All @@ -170,9 +171,8 @@ class CommentDetailViewModel(
authRepository.saveRefresh()
postComment()
}

else -> {
Log.e("error", "postComment: ${result.error}")
errorEvent.value = result.error.name
}
}
}
Expand All @@ -196,9 +196,8 @@ class CommentDetailViewModel(
authRepository.saveRefresh()
loadParticipants()
}

else -> {
Log.e("error", "loadParticipants: ${result.error}")
errorEvent.value = result.error.name
}
}
}
Expand All @@ -215,9 +214,8 @@ class CommentDetailViewModel(
authRepository.saveRefresh()
loadMeetings()
}

else -> {
Log.e("error", "loadMeetings: ${result.error}")
errorEvent.value = result.error.name
}
}
}
Expand All @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
Loading