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(
if (!isPollSent) {
// Poll event is not send yet. Disable option.
PollOptionViewState.DisabledOptionWithInvisibleVotes(optionId, optionAnswer)
PollOptionViewState.PollSending(optionId, optionAnswer)
} else if (isEnded) {
// Poll is ended. Disable option, show votes and mark the winner.
val isWinner = winnerVoteCount != 0 && voteCount == winnerVoteCount
PollOptionViewState.DisabledOptionWithVisibleVotes(optionId, optionAnswer, voteCount, votePercentage, isWinner)
PollOptionViewState.PollEnded(optionId, optionAnswer, voteCount, votePercentage, isWinner)
} else if (didUserVoted) {
// 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 {
// 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 {
setTag(STUB_ID, tag)
render(
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.optionId, option.optionAnswer)
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.PollSending(option.optionId, option.optionAnswer)
)
}
pollOptionItem.setOnClickListener {

View file

@ -47,35 +47,35 @@ class PollOptionItem @JvmOverloads constructor(
views.optionNameTextView.text = state.optionAnswer
when (state) {
is PollOptionViewState.DisabledOptionWithInvisibleVotes -> renderDisabledOptionWithInvisibleVotes()
is PollOptionViewState.DisabledOptionWithVisibleVotes -> renderDisabledOptionWithVisibleVotes(state)
is PollOptionViewState.EnabledOptionWithInvisibleVotes -> renderEnabledOptionWithInvisibleVotes()
is PollOptionViewState.EnabledOptionWithVisibleVotes -> renderEnabledOptionWithVisibleVotes(state)
is PollOptionViewState.PollSending -> renderPollSending()
is PollOptionViewState.PollEnded -> renderPollEnded(state)
is PollOptionViewState.PollReady -> renderPollReady()
is PollOptionViewState.PollVoted -> renderPollVoted(state)
}
}
private fun renderDisabledOptionWithInvisibleVotes() {
private fun renderPollSending() {
views.optionCheckImageView.isVisible = false
views.optionWinnerImageView.isVisible = false
hideVotes()
renderVoteSelection(false)
}
private fun renderDisabledOptionWithVisibleVotes(state: PollOptionViewState.DisabledOptionWithVisibleVotes) {
private fun renderPollEnded(state: PollOptionViewState.PollEnded) {
views.optionCheckImageView.isVisible = false
views.optionWinnerImageView.isVisible = state.isWinner
showVotes(state.voteCount, state.votePercentage)
renderVoteSelection(state.isWinner)
}
private fun renderEnabledOptionWithInvisibleVotes() {
private fun renderPollReady() {
views.optionCheckImageView.isVisible = true
views.optionWinnerImageView.isVisible = false
hideVotes()
renderVoteSelection(false)
}
private fun renderEnabledOptionWithVisibleVotes(state: PollOptionViewState.EnabledOptionWithVisibleVotes) {
private fun renderPollVoted(state: PollOptionViewState.PollVoted) {
views.optionCheckImageView.isVisible = true
views.optionWinnerImageView.isVisible = false
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.
*/
data class DisabledOptionWithInvisibleVotes(override val optionId: String,
override val optionAnswer: String
data class PollSending(override val optionId: String,
override val optionAnswer: String
) : PollOptionViewState(optionId, optionAnswer)
/**
* Represents a poll that is sent but not voted by the user
*/
data class EnabledOptionWithInvisibleVotes(override val optionId: String,
override val optionAnswer: String
data class PollReady(override val optionId: String,
override val optionAnswer: String
) : PollOptionViewState(optionId, optionAnswer)
/**
* Represents a poll that user already voted.
*/
data class EnabledOptionWithVisibleVotes(override val optionId: String,
override val optionAnswer: String,
val voteCount: Int,
val votePercentage: Double,
val isSelected: Boolean
data class PollVoted(override val optionId: String,
override val optionAnswer: String,
val voteCount: Int,
val votePercentage: Double,
val isSelected: Boolean
) : PollOptionViewState(optionId, optionAnswer)
/**
* Represents a poll that is ended.
*/
data class DisabledOptionWithVisibleVotes(override val optionId: String,
override val optionAnswer: String,
val voteCount: Int,
val votePercentage: Double,
val isWinner: Boolean
data class PollEnded(override val optionId: String,
override val optionAnswer: String,
val voteCount: Int,
val votePercentage: Double,
val isWinner: Boolean
) : PollOptionViewState(optionId, optionAnswer)
}