Skip to content

Commit

Permalink
[MERGE] #437 -> develop
Browse files Browse the repository at this point in the history
[FIX/#437] Yello / index out of bounds 예외 처리
  • Loading branch information
Marchbreeze authored Apr 8, 2024
2 parents 4f3065e + d0c5928 commit 493fc40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.el.yello.util.manager.AmplitudeManager
import com.el.yello.util.extension.yelloSnackbar
import com.example.ui.base.BindingActivity
import com.example.ui.animation.FadeOutTransformation
import com.example.ui.extension.toast
import com.example.ui.state.UiState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -45,11 +46,22 @@ class VoteActivity : BindingActivity<ActivityVoteBinding>(R.layout.activity_vote
super.onCreate(savedInstanceState)
binding.vm = viewModel

setupIsIndexErrorOccurred()
setupCurrentNoteIndex()
setupPostVoteState()
setupVoteState()
}

private fun setupIsIndexErrorOccurred() {
viewModel.isIndexErrorOccurred.flowWithLifecycle(lifecycle)
.onEach { isErrorOccurred ->
if (isErrorOccurred) {
toast(getString(R.string.internet_connection_error_msg))
finish()
}
}.launchIn(lifecycleScope)
}

private fun setupVoteState() {
viewModel.voteState.flowWithLifecycle(lifecycle)
.onEach { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class VoteViewModel @Inject constructor(
private var _idempotencyKey: UUID? = null
val idempotencyKey: UUID get() = requireNotNull(_idempotencyKey)

private val _isIndexErrorOccurred = MutableStateFlow<Boolean>(false)
val isIndexErrorOccurred get() = _isIndexErrorOccurred.asStateFlow()

init {
getStoredVote()
}
Expand Down Expand Up @@ -264,10 +267,17 @@ class VoteViewModel @Inject constructor(
}

private fun initCurrentChoice() {
_currentChoice.value = Choice(
questionId = voteList[currentNoteIndex].questionId,
backgroundIndex = (backgroundIndex + currentNoteIndex) % 12 + 1,
)
try {
_currentChoice.value = Choice(
questionId = voteList[currentNoteIndex].questionId,
backgroundIndex = (backgroundIndex + currentNoteIndex) % 12 + 1,
)
} catch (e: IndexOutOfBoundsException) {
viewModelScope.launch {
voteRepository.clearStoredVote()
_isIndexErrorOccurred.emit(true)
}
}
}

private fun initVoteIndex() {
Expand Down

0 comments on commit 493fc40

Please sign in to comment.