Do some renaming

This commit is contained in:
Benoit Marty 2021-12-13 21:04:52 +01:00
parent c1ea653561
commit eac06d5401
4 changed files with 23 additions and 23 deletions

View File

@ -198,22 +198,22 @@ class MessageItemFactory @Inject constructor(
val voteCount = voteSummary?.total ?: 0 val voteCount = voteSummary?.total ?: 0
val votePercentage = voteSummary?.percentage ?: 0.0 val votePercentage = voteSummary?.percentage ?: 0.0
val optionId = option.id ?: "" val optionId = option.id ?: ""
val optionName = option.answer ?: "" val optionAnswer = option.answer ?: ""
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, optionName) PollOptionViewState.DisabledOptionWithInvisibleVotes(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, optionName, voteCount, votePercentage, isWinner) PollOptionViewState.DisabledOptionWithVisibleVotes(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, optionName, voteCount, votePercentage, isMyVote) PollOptionViewState.EnabledOptionWithVisibleVotes(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, optionName) PollOptionViewState.EnabledOptionWithInvisibleVotes(optionId, optionAnswer)
} }
) )
} }

View File

@ -66,17 +66,17 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
holder.optionsContainer.removeAllViews() holder.optionsContainer.removeAllViews()
optionViewStates?.forEachIndexed { index, option -> optionViewStates?.forEachIndexed { index, option ->
val tag = relatedEventId + option.id val tag = relatedEventId + option.optionId
val pollOptionItem: PollOptionItem = (cachedViews[tag] ?: PollOptionItem(holder.view.context)) val pollOptionItem: PollOptionItem = (cachedViews[tag] ?: PollOptionItem(holder.view.context))
.apply { .apply {
setTag(STUB_ID, tag) setTag(STUB_ID, tag)
render( render(
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.id, option.name) state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.optionId, option.optionAnswer)
) )
} }
pollOptionItem.setOnClickListener { pollOptionItem.setOnClickListener {
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.id)) callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.optionId))
} }
holder.optionsContainer.addView(pollOptionItem) holder.optionsContainer.addView(pollOptionItem)

View File

@ -44,7 +44,7 @@ class PollOptionItem @JvmOverloads constructor(
} }
fun render(state: PollOptionViewState) { fun render(state: PollOptionViewState) {
views.optionNameTextView.text = state.name views.optionNameTextView.text = state.optionAnswer
when (state) { when (state) {
is PollOptionViewState.DisabledOptionWithInvisibleVotes -> renderDisabledOptionWithInvisibleVotes() is PollOptionViewState.DisabledOptionWithInvisibleVotes -> renderDisabledOptionWithInvisibleVotes()

View File

@ -16,39 +16,39 @@
package im.vector.app.features.home.room.detail.timeline.item package im.vector.app.features.home.room.detail.timeline.item
sealed class PollOptionViewState(open val id: String, sealed class PollOptionViewState(open val optionId: String,
open val name: String) { open val optionAnswer: 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 id: String, data class DisabledOptionWithInvisibleVotes(override val optionId: String,
override val name: String override val optionAnswer: String
) : PollOptionViewState(id, name) ) : 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 id: String, data class EnabledOptionWithInvisibleVotes(override val optionId: String,
override val name: String override val optionAnswer: String
) : PollOptionViewState(id, name) ) : PollOptionViewState(optionId, optionAnswer)
/** /**
* Represents a poll that user already voted. * Represents a poll that user already voted.
*/ */
data class EnabledOptionWithVisibleVotes(override val id: String, data class EnabledOptionWithVisibleVotes(override val optionId: String,
override val name: String, override val optionAnswer: String,
val voteCount: Int, val voteCount: Int,
val votePercentage: Double, val votePercentage: Double,
val isSelected: Boolean val isSelected: Boolean
) : PollOptionViewState(id, name) ) : PollOptionViewState(optionId, optionAnswer)
/** /**
* Represents a poll that is ended. * Represents a poll that is ended.
*/ */
data class DisabledOptionWithVisibleVotes(override val id: String, data class DisabledOptionWithVisibleVotes(override val optionId: String,
override val name: String, override val optionAnswer: String,
val voteCount: Int, val voteCount: Int,
val votePercentage: Double, val votePercentage: Double,
val isWinner: Boolean val isWinner: Boolean
) : PollOptionViewState(id, name) ) : PollOptionViewState(optionId, optionAnswer)
} }