Adds server side vote blocking for ended polls
This commit is contained in:
parent
2048b859c5
commit
e4ce4ab1ab
|
@ -44,8 +44,8 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var totalVotesText: String? = null
|
var totalVotesText: String? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var edited: Boolean = false
|
var edited: Boolean = false
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
lateinit var optionViewStates: List<PollOptionViewState>
|
lateinit var optionViewStates: List<PollOptionViewState>
|
||||||
|
@ -54,7 +54,6 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
||||||
|
|
||||||
override fun bind(holder: Holder) {
|
override fun bind(holder: Holder) {
|
||||||
super.bind(holder)
|
super.bind(holder)
|
||||||
val relatedEventId = eventId ?: return
|
|
||||||
|
|
||||||
renderSendState(holder.view, holder.questionTextView)
|
renderSendState(holder.view, holder.questionTextView)
|
||||||
|
|
||||||
|
@ -73,13 +72,21 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
||||||
optionViewStates.forEachIndexed { index, optionViewState ->
|
optionViewStates.forEachIndexed { index, optionViewState ->
|
||||||
views.getOrNull(index)?.let {
|
views.getOrNull(index)?.let {
|
||||||
it.render(optionViewState)
|
it.render(optionViewState)
|
||||||
it.setOnClickListener {
|
it.setOnClickListener { onPollItemClick(optionViewState) }
|
||||||
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, optionViewState.optionId))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
class Holder : AbsMessageItem.Holder(STUB_ID) {
|
||||||
val questionTextView by bind<TextView>(R.id.questionTextView)
|
val questionTextView by bind<TextView>(R.id.questionTextView)
|
||||||
val optionsContainer by bind<LinearLayout>(R.id.optionsContainer)
|
val optionsContainer by bind<LinearLayout>(R.id.optionsContainer)
|
||||||
|
|
Loading…
Reference in New Issue