mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +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 isMyVote = pollResponseSummary?.myVote == option.id
|
||||||
val voteCount = voteSummary?.total ?: 0
|
val voteCount = voteSummary?.total ?: 0
|
||||||
val votePercentage = voteSummary?.percentage ?: 0.0
|
val votePercentage = voteSummary?.percentage ?: 0.0
|
||||||
|
val optionId = option.id ?: ""
|
||||||
val optionName = option.answer ?: ""
|
val optionName = option.answer ?: ""
|
||||||
|
|
||||||
optionViewStates.add(
|
optionViewStates.add(
|
||||||
if (!isPollSent) {
|
if (!isPollSent) {
|
||||||
// Poll event is not send yet. Disable option.
|
// Poll event is not send yet. Disable option.
|
||||||
PollOptionViewState.DisabledOptionWithInvisibleVotes(optionName)
|
PollOptionViewState.DisabledOptionWithInvisibleVotes(optionId, optionName)
|
||||||
} else if (isEnded) {
|
} else if (isEnded) {
|
||||||
// Poll is ended. Disable option, show votes and mark the winner.
|
// Poll is ended. Disable option, show votes and mark the winner.
|
||||||
val isWinner = winnerVoteCount != 0 && voteCount == winnerVoteCount
|
val isWinner = winnerVoteCount != 0 && voteCount == winnerVoteCount
|
||||||
PollOptionViewState.DisabledOptionWithVisibleVotes(optionName, voteCount, votePercentage, isWinner)
|
PollOptionViewState.DisabledOptionWithVisibleVotes(optionId, optionName, voteCount, votePercentage, isWinner)
|
||||||
} else if (didUserVoted) {
|
} else if (didUserVoted) {
|
||||||
// User voted to the poll, but poll is not ended. Enable option, show votes and mark the user's selection.
|
// 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 {
|
} else {
|
||||||
// User didn't voted yet and poll is not ended yet. Enable options, hide votes.
|
// 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_()
|
return PollItem_()
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
.eventId(informationData.eventId)
|
.eventId(informationData.eventId)
|
||||||
|
.pollQuestion(pollContent.pollCreationInfo?.question?.question ?: "")
|
||||||
.pollResponseSummary(pollResponseSummary)
|
.pollResponseSummary(pollResponseSummary)
|
||||||
.pollSent(isPollSent)
|
.pollSent(isPollSent)
|
||||||
.pollContent(pollContent)
|
|
||||||
.totalVotesText(totalVotesText)
|
.totalVotesText(totalVotesText)
|
||||||
.optionViewStates(optionViewStates)
|
.optionViewStates(optionViewStates)
|
||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
|
|
|
@ -24,13 +24,12 @@ import com.airbnb.epoxy.EpoxyModelClass
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.features.home.room.detail.RoomDetailAction
|
import im.vector.app.features.home.room.detail.RoomDetailAction
|
||||||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
|
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)
|
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
|
||||||
abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var pollContent: MessagePollContent? = null
|
var pollQuestion: String? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var pollResponseSummary: PollResponseData? = null
|
var pollResponseSummary: PollResponseData? = null
|
||||||
|
@ -56,7 +55,7 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
||||||
|
|
||||||
renderSendState(holder.view, holder.questionTextView)
|
renderSendState(holder.view, holder.questionTextView)
|
||||||
|
|
||||||
holder.questionTextView.text = pollContent?.pollCreationInfo?.question?.question
|
holder.questionTextView.text = pollQuestion
|
||||||
holder.totalVotesTextView.text = totalVotesText
|
holder.totalVotesTextView.text = totalVotesText
|
||||||
|
|
||||||
val cachedViews = mutableMapOf<String, PollOptionItem>()
|
val cachedViews = mutableMapOf<String, PollOptionItem>()
|
||||||
|
@ -66,19 +65,18 @@ abstract class PollItem : AbsMessageItem<PollItem.Holder>() {
|
||||||
|
|
||||||
holder.optionsContainer.removeAllViews()
|
holder.optionsContainer.removeAllViews()
|
||||||
|
|
||||||
pollContent?.pollCreationInfo?.answers?.forEachIndexed { index, option ->
|
optionViewStates?.forEachIndexed { index, option ->
|
||||||
val optionName = option.answer ?: ""
|
|
||||||
val tag = relatedEventId + option.id
|
val tag = relatedEventId + option.id
|
||||||
|
|
||||||
val pollOptionItem: PollOptionItem = (cachedViews[tag] ?: PollOptionItem(holder.view.context))
|
val pollOptionItem: PollOptionItem = (cachedViews[tag] ?: PollOptionItem(holder.view.context))
|
||||||
.apply {
|
.apply {
|
||||||
setTag(STUB_ID, tag)
|
setTag(STUB_ID, tag)
|
||||||
render(
|
render(
|
||||||
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(optionName)
|
state = optionViewStates?.getOrNull(index) ?: PollOptionViewState.DisabledOptionWithInvisibleVotes(option.id, option.name)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pollOptionItem.setOnClickListener {
|
pollOptionItem.setOnClickListener {
|
||||||
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.id ?: ""))
|
callback?.onTimelineItemAction(RoomDetailAction.VoteToPoll(relatedEventId, option.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.optionsContainer.addView(pollOptionItem)
|
holder.optionsContainer.addView(pollOptionItem)
|
||||||
|
|
|
@ -44,7 +44,6 @@ class PollOptionItem @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun render(state: PollOptionViewState) {
|
fun render(state: PollOptionViewState) {
|
||||||
|
|
||||||
views.optionNameTextView.text = state.name
|
views.optionNameTextView.text = state.name
|
||||||
|
|
||||||
when (state) {
|
when (state) {
|
||||||
|
|
|
@ -16,33 +16,35 @@
|
||||||
|
|
||||||
package im.vector.app.features.home.room.detail.timeline.item
|
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.
|
* 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 voteCount: Int,
|
||||||
val votePercentage: Double,
|
val votePercentage: Double,
|
||||||
val isSelected: Boolean
|
val isSelected: Boolean
|
||||||
) : PollOptionViewState(name)
|
) : PollOptionViewState(id, name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a poll that is ended.
|
* 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 voteCount: Int,
|
||||||
val votePercentage: Double,
|
val votePercentage: Double,
|
||||||
val isWinner: Boolean
|
val isWinner: Boolean
|
||||||
) : PollOptionViewState(name)
|
) : PollOptionViewState(id, name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a poll that is sent but not voted by the user
|
* 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.
|
* 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