Move epoxy related poll functions back to MessageItemFactory.

This commit is contained in:
Onuray Sahin 2022-06-24 17:28:59 +03:00
parent 532bc18b1e
commit e63fa2d83f
3 changed files with 18 additions and 27 deletions

View File

@ -238,7 +238,7 @@ class MessageItemFactory @Inject constructor(
return PollItem_()
.attributes(attributes)
.eventId(informationData.eventId)
.pollQuestion(pollViewState.question)
.pollQuestion(createPollQuestion(informationData, pollViewState.question, callback))
.canVote(pollViewState.canVote)
.totalVotesText(pollViewState.totalVotes)
.optionViewStates(pollViewState.optionViewStates)
@ -248,6 +248,16 @@ class MessageItemFactory @Inject constructor(
.callback(callback)
}
private fun createPollQuestion(
informationData: MessageInformationData,
question: String,
callback: TimelineEventController.Callback?,
) = if (informationData.hasBeenEdited) {
annotateWithEdited(stringProvider, colorProvider, dimensionConverter, question, callback, informationData)
} else {
question
}.toEpoxyCharSequence()
private fun buildAudioMessageItem(
params: TimelineItemFactoryParams,
messageContent: MessageAudioContent,

View File

@ -17,17 +17,12 @@
package im.vector.app.features.home.room.detail.timeline.factory
import im.vector.app.R
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.factory.MessageItemFactoryHelper.annotateWithEdited
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
import im.vector.app.features.home.room.detail.timeline.item.PollResponseData
import im.vector.app.features.poll.PollViewState
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
import org.matrix.android.sdk.api.session.room.model.message.PollCreationInfo
@ -35,8 +30,6 @@ import javax.inject.Inject
class PollItemViewStateFactory @Inject constructor(
private val stringProvider: StringProvider,
private val colorProvider: ColorProvider,
private val dimensionConverter: DimensionConverter,
) {
fun create(
@ -46,8 +39,7 @@ class PollItemViewStateFactory @Inject constructor(
): PollViewState {
val pollCreationInfo = pollContent.getBestPollCreationInfo()
val questionText = pollCreationInfo?.question?.getBestQuestion().orEmpty()
val question = createPollQuestion(informationData, questionText, callback)
val question = pollCreationInfo?.question?.getBestQuestion().orEmpty()
val pollResponseSummary = informationData.pollResponseAggregatedSummary
val winnerVoteCount = pollResponseSummary?.winnerVoteCount
@ -72,7 +64,7 @@ class PollItemViewStateFactory @Inject constructor(
}
}
private fun createSendingPollViewState(question: EpoxyCharSequence, pollCreationInfo: PollCreationInfo?): PollViewState {
private fun createSendingPollViewState(question: String, pollCreationInfo: PollCreationInfo?): PollViewState {
return PollViewState(
question = question,
totalVotes = stringProvider.getString(R.string.poll_no_votes_cast),
@ -87,7 +79,7 @@ class PollItemViewStateFactory @Inject constructor(
}
private fun createEndedPollViewState(
question: EpoxyCharSequence,
question: String,
pollCreationInfo: PollCreationInfo?,
pollResponseSummary: PollResponseData?,
totalVotes: Int,
@ -111,7 +103,7 @@ class PollItemViewStateFactory @Inject constructor(
}
private fun createUndisclosedPollViewState(
question: EpoxyCharSequence,
question: String,
pollCreationInfo: PollCreationInfo?,
pollResponseSummary: PollResponseData?
): PollViewState {
@ -131,7 +123,7 @@ class PollItemViewStateFactory @Inject constructor(
}
private fun createVotedPollViewState(
question: EpoxyCharSequence,
question: String,
pollCreationInfo: PollCreationInfo?,
pollResponseSummary: PollResponseData?,
totalVotes: Int
@ -154,7 +146,7 @@ class PollItemViewStateFactory @Inject constructor(
)
}
private fun createReadyPollViewState(question: EpoxyCharSequence, pollCreationInfo: PollCreationInfo?, totalVotes: Int): PollViewState {
private fun createReadyPollViewState(question: String, pollCreationInfo: PollCreationInfo?, totalVotes: Int): PollViewState {
val totalVotesText = if (totalVotes == 0) {
stringProvider.getString(R.string.poll_no_votes_cast)
} else {
@ -172,14 +164,4 @@ class PollItemViewStateFactory @Inject constructor(
},
)
}
private fun createPollQuestion(
informationData: MessageInformationData,
question: String,
callback: TimelineEventController.Callback?,
) = if (informationData.hasBeenEdited) {
annotateWithEdited(stringProvider, colorProvider, dimensionConverter, question, callback, informationData)
} else {
question
}.toEpoxyCharSequence()
}

View File

@ -17,10 +17,9 @@
package im.vector.app.features.poll
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
data class PollViewState(
val question: EpoxyCharSequence,
val question: String,
val totalVotes: String,
val canVote: Boolean,
val optionViewStates: List<PollOptionViewState>?,