Do some renaming

This commit is contained in:
Benoit Marty 2021-12-13 21:08:52 +01:00
parent eac06d5401
commit 10b39ccd28
4 changed files with 27 additions and 27 deletions

View File

@ -203,17 +203,17 @@ class MessageItemFactory @Inject constructor(
optionViewStates.add( optionViewStates.add(
if (!isPollSent) { if (!isPollSent) {
// Poll event is not send yet. Disable option. // Poll event is not send yet. Disable option.
PollOptionViewState.DisabledOptionWithInvisibleVotes(optionId, optionAnswer) PollOptionViewState.PollSending(optionId, optionAnswer)
} else if (isEnded) { } else if (isEnded) {
// Poll is ended. Disable option, show votes and mark the winner. // Poll is ended. Disable option, show votes and mark the winner.
val isWinner = winnerVoteCount != 0 && voteCount == winnerVoteCount val isWinner = winnerVoteCount != 0 && voteCount == winnerVoteCount
PollOptionViewState.DisabledOptionWithVisibleVotes(optionId, optionAnswer, voteCount, votePercentage, isWinner) PollOptionViewState.PollEnded(optionId, optionAnswer, voteCount, votePercentage, isWinner)
} else if (didUserVoted) { } else if (didUserVoted) {
// User voted to the poll, but poll is not ended. Enable option, show votes and mark the user's selection. // User voted to the poll, but poll is not ended. Enable option, show votes and mark the user's selection.
PollOptionViewState.EnabledOptionWithVisibleVotes(optionId, optionAnswer, voteCount, votePercentage, isMyVote) PollOptionViewState.PollVoted(optionId, optionAnswer, voteCount, votePercentage, isMyVote)
} else { } else {
// User didn't voted yet and poll is not ended yet. Enable options, hide votes. // User didn't voted yet and poll is not ended yet. Enable options, hide votes.
PollOptionViewState.EnabledOptionWithInvisibleVotes(optionId, optionAnswer) PollOptionViewState.PollReady(optionId, optionAnswer)
} }
) )
} }

View File

@ -72,7 +72,7 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
.apply { .apply {
setTag(STUB_ID, tag) setTag(STUB_ID, tag)
render( render(
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.optionId, option.optionAnswer) state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.PollSending(option.optionId, option.optionAnswer)
) )
} }
pollOptionItem.setOnClickListener { pollOptionItem.setOnClickListener {

View File

@ -47,35 +47,35 @@ class PollOptionItem @JvmOverloads constructor(
views.optionNameTextView.text = state.optionAnswer views.optionNameTextView.text = state.optionAnswer
when (state) { when (state) {
is PollOptionViewState.DisabledOptionWithInvisibleVotes -> renderDisabledOptionWithInvisibleVotes() is PollOptionViewState.PollSending -> renderPollSending()
is PollOptionViewState.DisabledOptionWithVisibleVotes -> renderDisabledOptionWithVisibleVotes(state) is PollOptionViewState.PollEnded -> renderPollEnded(state)
is PollOptionViewState.EnabledOptionWithInvisibleVotes -> renderEnabledOptionWithInvisibleVotes() is PollOptionViewState.PollReady -> renderPollReady()
is PollOptionViewState.EnabledOptionWithVisibleVotes -> renderEnabledOptionWithVisibleVotes(state) is PollOptionViewState.PollVoted -> renderPollVoted(state)
} }
} }
private fun renderDisabledOptionWithInvisibleVotes() { private fun renderPollSending() {
views.optionCheckImageView.isVisible = false views.optionCheckImageView.isVisible = false
views.optionWinnerImageView.isVisible = false views.optionWinnerImageView.isVisible = false
hideVotes() hideVotes()
renderVoteSelection(false) renderVoteSelection(false)
} }
private fun renderDisabledOptionWithVisibleVotes(state: PollOptionViewState.DisabledOptionWithVisibleVotes) { private fun renderPollEnded(state: PollOptionViewState.PollEnded) {
views.optionCheckImageView.isVisible = false views.optionCheckImageView.isVisible = false
views.optionWinnerImageView.isVisible = state.isWinner views.optionWinnerImageView.isVisible = state.isWinner
showVotes(state.voteCount, state.votePercentage) showVotes(state.voteCount, state.votePercentage)
renderVoteSelection(state.isWinner) renderVoteSelection(state.isWinner)
} }
private fun renderEnabledOptionWithInvisibleVotes() { private fun renderPollReady() {
views.optionCheckImageView.isVisible = true views.optionCheckImageView.isVisible = true
views.optionWinnerImageView.isVisible = false views.optionWinnerImageView.isVisible = false
hideVotes() hideVotes()
renderVoteSelection(false) renderVoteSelection(false)
} }
private fun renderEnabledOptionWithVisibleVotes(state: PollOptionViewState.EnabledOptionWithVisibleVotes) { private fun renderPollVoted(state: PollOptionViewState.PollVoted) {
views.optionCheckImageView.isVisible = true views.optionCheckImageView.isVisible = true
views.optionWinnerImageView.isVisible = false views.optionWinnerImageView.isVisible = false
showVotes(state.voteCount, state.votePercentage) showVotes(state.voteCount, state.votePercentage)

View File

@ -21,34 +21,34 @@ sealed class PollOptionViewState(open val optionId: String,
/** /**
* Represents a poll that is not sent to the server yet. * Represents a poll that is not sent to the server yet.
*/ */
data class DisabledOptionWithInvisibleVotes(override val optionId: String, data class PollSending(override val optionId: String,
override val optionAnswer: String override val optionAnswer: String
) : PollOptionViewState(optionId, optionAnswer) ) : PollOptionViewState(optionId, optionAnswer)
/** /**
* Represents a poll that is sent but not voted by the user * Represents a poll that is sent but not voted by the user
*/ */
data class EnabledOptionWithInvisibleVotes(override val optionId: String, data class PollReady(override val optionId: String,
override val optionAnswer: String override val optionAnswer: String
) : PollOptionViewState(optionId, optionAnswer) ) : PollOptionViewState(optionId, optionAnswer)
/** /**
* Represents a poll that user already voted. * Represents a poll that user already voted.
*/ */
data class EnabledOptionWithVisibleVotes(override val optionId: String, data class PollVoted(override val optionId: String,
override val optionAnswer: String, override val optionAnswer: String,
val voteCount: Int, val voteCount: Int,
val votePercentage: Double, val votePercentage: Double,
val isSelected: Boolean val isSelected: Boolean
) : PollOptionViewState(optionId, optionAnswer) ) : PollOptionViewState(optionId, optionAnswer)
/** /**
* Represents a poll that is ended. * Represents a poll that is ended.
*/ */
data class DisabledOptionWithVisibleVotes(override val optionId: String, data class PollEnded(override val optionId: String,
override val optionAnswer: String, override val optionAnswer: String,
val voteCount: Int, val voteCount: Int,
val votePercentage: Double, val votePercentage: Double,
val isWinner: Boolean val isWinner: Boolean
) : PollOptionViewState(optionId, optionAnswer) ) : PollOptionViewState(optionId, optionAnswer)
} }