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 2327a0f2e2..0ce225b21c 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 @@ -44,8 +44,8 @@ abstract class PollItem : AbsMessageItem() { @EpoxyAttribute var totalVotesText: String? = null - @EpoxyAttribute - var edited: Boolean = false + @EpoxyAttribute + var edited: Boolean = false @EpoxyAttribute lateinit var optionViewStates: List @@ -54,7 +54,6 @@ abstract class PollItem : AbsMessageItem() { override fun bind(holder: Holder) { super.bind(holder) - val relatedEventId = eventId ?: return renderSendState(holder.view, holder.questionTextView) @@ -73,13 +72,21 @@ abstract class PollItem : AbsMessageItem() { optionViewStates.forEachIndexed { index, optionViewState -> views.getOrNull(index)?.let { it.render(optionViewState) - it.setOnClickListener { - callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId)) - } + it.setOnClickListener { onPollItemClick(optionViewState) } } } } + private fun onPollItemClick(optionViewState: PollOptionViewState) { + val relatedEventId = eventId + + if (isPollActive(optionViewState) && relatedEventId != null) { + callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId)) + } + } + + private fun isPollActive(optionViewState: PollOptionViewState) = optionViewState !is PollOptionViewState.PollEnded + class Holder : AbsMessageItem.Holder(STUB_ID) { val questionTextView by bind(R.id.questionTextView) val optionsContainer by bind(R.id.optionsContainer)