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 votePercentage = voteSummary?.percentage ?: 0.0
val optionId = option.id ?: ""
val optionName = option.answer ?: ""
val optionAnswer = option.answer ?: ""
optionViewStates.add(
if (!isPollSent) {
// Poll event is not send yet. Disable option.
PollOptionViewState.DisabledOptionWithInvisibleVotes(optionId, optionName)
PollOptionViewState.DisabledOptionWithInvisibleVotes(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, optionName, voteCount, votePercentage, isWinner)
PollOptionViewState.DisabledOptionWithVisibleVotes(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, optionName, voteCount, votePercentage, isMyVote)
PollOptionViewState.EnabledOptionWithVisibleVotes(optionId, optionAnswer, voteCount, votePercentage, isMyVote)
} else {
// 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()
optionViewStates?.forEachIndexed { index, option ->
val tag = relatedEventId + option.id
val tag = relatedEventId + option.optionId
val pollOptionItem: PollOptionItem = (cachedViews[tag] ?: PollOptionItem(holder.view.context))
.apply {
setTag(STUB_ID, tag)
render(
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.id, option.name)
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.optionId, option.optionAnswer)
)
}
pollOptionItem.setOnClickListener {
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.id))
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.optionId))
}
holder.optionsContainer.addView(pollOptionItem)

View File

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

View File

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