diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index f55395e3e5..b461cb31c8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -197,22 +197,23 @@ class MessageItemFactory @Inject constructor( val isMyVote = pollResponseSummary?.myVote == option.id val voteCount = voteSummary?.total ?: 0 val votePercentage = voteSummary?.percentage ?: 0.0 + val optionId = option.id ?: "" val optionName = option.answer ?: "" optionViewStates.add( if (!isPollSent) { // Poll event is not send yet. Disable option. - PollOptionViewState.DisabledOptionWithInvisibleVotes(optionName) + PollOptionViewState.DisabledOptionWithInvisibleVotes(optionId, optionName) } else if (isEnded) { // Poll is ended. Disable option, show votes and mark the winner. val isWinner = winnerVoteCount != 0 && voteCount == winnerVoteCount - PollOptionViewState.DisabledOptionWithVisibleVotes(optionName, voteCount, votePercentage, isWinner) + PollOptionViewState.DisabledOptionWithVisibleVotes(optionId, optionName, 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(optionName, voteCount, votePercentage, isMyVote) + PollOptionViewState.EnabledOptionWithVisibleVotes(optionId, optionName, voteCount, votePercentage, isMyVote) } else { // User didn't voted yet and poll is not ended yet. Enable options, hide votes. - PollOptionViewState.EnabledOptionWithInvisibleVotes(optionName) + PollOptionViewState.EnabledOptionWithInvisibleVotes(optionId, optionName) } ) } @@ -220,9 +221,9 @@ class MessageItemFactory @Inject constructor( return PollItem_() .attributes(attributes) .eventId(informationData.eventId) + .pollQuestion(pollContent.pollCreationInfo?.question?.question ?: "") .pollResponseSummary(pollResponseSummary) .pollSent(isPollSent) - .pollContent(pollContent) .totalVotesText(totalVotesText) .optionViewStates(optionViewStates) .highlighted(highlight) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt index 8d8ae9b343..0ebe5c8ffb 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollItem.kt @@ -24,13 +24,12 @@ import com.airbnb.epoxy.EpoxyModelClass import im.vector.app.R import im.vector.app.features.home.room.detail.RoomDetailAction import im.vector.app.features.home.room.detail.timeline.TimelineEventController -import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class PollItem : AbsMessageItem() { @EpoxyAttribute - var pollContent: MessagePollContent? = null + var pollQuestion: String? = null @EpoxyAttribute var pollResponseSummary: PollResponseData? = null @@ -56,7 +55,7 @@ abstract class PollItem : AbsMessageItem() { renderSendState(holder.view, holder.questionTextView) - holder.questionTextView.text = pollContent?.pollCreationInfo?.question?.question + holder.questionTextView.text = pollQuestion holder.totalVotesTextView.text = totalVotesText val cachedViews = mutableMapOf() @@ -66,19 +65,18 @@ abstract class PollItem : AbsMessageItem() { holder.optionsContainer.removeAllViews() - pollContent?.pollCreationInfo?.answers?.forEachIndexed { index, option -> - val optionName = option.answer ?: "" + optionViewStates?.forEachIndexed { index, option -> val tag = relatedEventId + option.id val pollOptionItem: PollOptionItem = (cachedViews[tag] ?: PollOptionItem(holder.view.context)) .apply { setTag(STUB_ID, tag) render( - state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(optionName) + state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.id, option.name) ) } pollOptionItem.setOnClickListener { - callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.id ?: "")) + callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.id)) } holder.optionsContainer.addView(pollOptionItem) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionItem.kt index 60ba8586c0..79a7d54843 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionItem.kt @@ -44,7 +44,6 @@ class PollOptionItem @JvmOverloads constructor( } fun render(state: PollOptionViewState) { - views.optionNameTextView.text = state.name when (state) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionViewState.kt index 72dda3df52..07ded7c5a8 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/PollOptionViewState.kt @@ -16,33 +16,35 @@ package im.vector.app.features.home.room.detail.timeline.item -sealed class PollOptionViewState(open val name: String) { +sealed class PollOptionViewState(open val id: String, open val name: String) { /** * Represents a poll that user already voted. */ - data class EnabledOptionWithVisibleVotes(override val name: String, + data class EnabledOptionWithVisibleVotes(override val id: String, + override val name: String, val voteCount: Int, val votePercentage: Double, val isSelected: Boolean - ) : PollOptionViewState(name) + ) : PollOptionViewState(id, name) /** * Represents a poll that is ended. */ - data class DisabledOptionWithVisibleVotes(override val name: String, + data class DisabledOptionWithVisibleVotes(override val id: String, + override val name: String, val voteCount: Int, val votePercentage: Double, val isWinner: Boolean - ) : PollOptionViewState(name) + ) : PollOptionViewState(id, name) /** * Represents a poll that is sent but not voted by the user */ - data class EnabledOptionWithInvisibleVotes(override val name: String) : PollOptionViewState(name) + data class EnabledOptionWithInvisibleVotes(override val id: String, override val name: String) : PollOptionViewState(id, name) /** * Represents a poll that is not sent to the server yet. */ - data class DisabledOptionWithInvisibleVotes(override val name: String) : PollOptionViewState(name) + data class DisabledOptionWithInvisibleVotes(override val id: String, override val name: String) : PollOptionViewState(id, name) }