mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +03:00
Code review fixes.
This commit is contained in:
parent
f028f9836b
commit
e2bbc3f8ae
4 changed files with 20 additions and 20 deletions
|
@ -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)
|
||||
|
|
|
@ -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<PollItem.Holder>() {
|
||||
|
||||
@EpoxyAttribute
|
||||
var pollContent: MessagePollContent? = null
|
||||
var pollQuestion: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var pollResponseSummary: PollResponseData? = null
|
||||
|
@ -56,7 +55,7 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
|||
|
||||
renderSendState(holder.view, holder.questionTextView)
|
||||
|
||||
holder.questionTextView.text = pollContent?.pollCreationInfo?.question?.question
|
||||
holder.questionTextView.text = pollQuestion
|
||||
holder.totalVotesTextView.text = totalVotesText
|
||||
|
||||
val cachedViews = mutableMapOf<String, PollOptionItem>()
|
||||
|
@ -66,19 +65,18 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
|||
|
||||
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)
|
||||
|
|
|
@ -44,7 +44,6 @@ class PollOptionItem @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
fun render(state: PollOptionViewState) {
|
||||
|
||||
views.optionNameTextView.text = state.name
|
||||
|
||||
when (state) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue