Move epoxy related poll functions back to MessageItemFactory.
This commit is contained in:
parent
532bc18b1e
commit
e63fa2d83f
@ -238,7 +238,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
return PollItem_()
|
return PollItem_()
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
.eventId(informationData.eventId)
|
.eventId(informationData.eventId)
|
||||||
.pollQuestion(pollViewState.question)
|
.pollQuestion(createPollQuestion(informationData, pollViewState.question, callback))
|
||||||
.canVote(pollViewState.canVote)
|
.canVote(pollViewState.canVote)
|
||||||
.totalVotesText(pollViewState.totalVotes)
|
.totalVotesText(pollViewState.totalVotes)
|
||||||
.optionViewStates(pollViewState.optionViewStates)
|
.optionViewStates(pollViewState.optionViewStates)
|
||||||
@ -248,6 +248,16 @@ class MessageItemFactory @Inject constructor(
|
|||||||
.callback(callback)
|
.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(
|
private fun buildAudioMessageItem(
|
||||||
params: TimelineItemFactoryParams,
|
params: TimelineItemFactoryParams,
|
||||||
messageContent: MessageAudioContent,
|
messageContent: MessageAudioContent,
|
||||||
|
@ -17,17 +17,12 @@
|
|||||||
package im.vector.app.features.home.room.detail.timeline.factory
|
package im.vector.app.features.home.room.detail.timeline.factory
|
||||||
|
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.resources.ColorProvider
|
|
||||||
import im.vector.app.core.resources.StringProvider
|
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.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.MessageInformationData
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
|
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.home.room.detail.timeline.item.PollResponseData
|
||||||
import im.vector.app.features.poll.PollViewState
|
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.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
|
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.PollCreationInfo
|
import org.matrix.android.sdk.api.session.room.model.message.PollCreationInfo
|
||||||
@ -35,8 +30,6 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
class PollItemViewStateFactory @Inject constructor(
|
class PollItemViewStateFactory @Inject constructor(
|
||||||
private val stringProvider: StringProvider,
|
private val stringProvider: StringProvider,
|
||||||
private val colorProvider: ColorProvider,
|
|
||||||
private val dimensionConverter: DimensionConverter,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun create(
|
fun create(
|
||||||
@ -46,8 +39,7 @@ class PollItemViewStateFactory @Inject constructor(
|
|||||||
): PollViewState {
|
): PollViewState {
|
||||||
val pollCreationInfo = pollContent.getBestPollCreationInfo()
|
val pollCreationInfo = pollContent.getBestPollCreationInfo()
|
||||||
|
|
||||||
val questionText = pollCreationInfo?.question?.getBestQuestion().orEmpty()
|
val question = pollCreationInfo?.question?.getBestQuestion().orEmpty()
|
||||||
val question = createPollQuestion(informationData, questionText, callback)
|
|
||||||
|
|
||||||
val pollResponseSummary = informationData.pollResponseAggregatedSummary
|
val pollResponseSummary = informationData.pollResponseAggregatedSummary
|
||||||
val winnerVoteCount = pollResponseSummary?.winnerVoteCount
|
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(
|
return PollViewState(
|
||||||
question = question,
|
question = question,
|
||||||
totalVotes = stringProvider.getString(R.string.poll_no_votes_cast),
|
totalVotes = stringProvider.getString(R.string.poll_no_votes_cast),
|
||||||
@ -87,7 +79,7 @@ class PollItemViewStateFactory @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createEndedPollViewState(
|
private fun createEndedPollViewState(
|
||||||
question: EpoxyCharSequence,
|
question: String,
|
||||||
pollCreationInfo: PollCreationInfo?,
|
pollCreationInfo: PollCreationInfo?,
|
||||||
pollResponseSummary: PollResponseData?,
|
pollResponseSummary: PollResponseData?,
|
||||||
totalVotes: Int,
|
totalVotes: Int,
|
||||||
@ -111,7 +103,7 @@ class PollItemViewStateFactory @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createUndisclosedPollViewState(
|
private fun createUndisclosedPollViewState(
|
||||||
question: EpoxyCharSequence,
|
question: String,
|
||||||
pollCreationInfo: PollCreationInfo?,
|
pollCreationInfo: PollCreationInfo?,
|
||||||
pollResponseSummary: PollResponseData?
|
pollResponseSummary: PollResponseData?
|
||||||
): PollViewState {
|
): PollViewState {
|
||||||
@ -131,7 +123,7 @@ class PollItemViewStateFactory @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createVotedPollViewState(
|
private fun createVotedPollViewState(
|
||||||
question: EpoxyCharSequence,
|
question: String,
|
||||||
pollCreationInfo: PollCreationInfo?,
|
pollCreationInfo: PollCreationInfo?,
|
||||||
pollResponseSummary: PollResponseData?,
|
pollResponseSummary: PollResponseData?,
|
||||||
totalVotes: Int
|
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) {
|
val totalVotesText = if (totalVotes == 0) {
|
||||||
stringProvider.getString(R.string.poll_no_votes_cast)
|
stringProvider.getString(R.string.poll_no_votes_cast)
|
||||||
} else {
|
} 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()
|
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,9 @@
|
|||||||
package im.vector.app.features.poll
|
package im.vector.app.features.poll
|
||||||
|
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
|
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
|
||||||
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
|
|
||||||
|
|
||||||
data class PollViewState(
|
data class PollViewState(
|
||||||
val question: EpoxyCharSequence,
|
val question: String,
|
||||||
val totalVotes: String,
|
val totalVotes: String,
|
||||||
val canVote: Boolean,
|
val canVote: Boolean,
|
||||||
val optionViewStates: List<PollOptionViewState>?,
|
val optionViewStates: List<PollOptionViewState>?,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user