From b75787a4f48c022792ab1bac0e62c33524dd041d Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Fri, 3 Feb 2023 10:31:36 +0100 Subject: [PATCH] Adding creation date field --- .../polls/detail/ui/RoomPollDetail.kt | 1 + .../detail/ui/RoomPollDetailController.kt | 7 ++++- .../polls/detail/ui/RoomPollDetailItem.kt | 8 +++-- .../polls/detail/ui/RoomPollDetailMapper.kt | 13 +++++++-- .../src/main/res/layout/item_poll_detail.xml | 29 +++++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 vector/src/main/res/layout/item_poll_detail.xml diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetail.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetail.kt index 91d52ca08d..7857a30eeb 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetail.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetail.kt @@ -19,6 +19,7 @@ package im.vector.app.features.roomprofile.polls.detail.ui import im.vector.app.features.poll.PollItemViewState data class RoomPollDetail( + val creationTimestamp: Long, val isEnded: Boolean, val endedPollEventId: String?, val pollItemViewState: PollItemViewState, diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailController.kt index d2c5dfb8b1..7a246f812b 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailController.kt @@ -17,10 +17,14 @@ package im.vector.app.features.roomprofile.polls.detail.ui import com.airbnb.epoxy.TypedEpoxyController +import im.vector.app.core.date.DateFormatKind +import im.vector.app.core.date.VectorDateFormatter import java.util.UUID import javax.inject.Inject -class RoomPollDetailController @Inject constructor() : TypedEpoxyController() { +class RoomPollDetailController @Inject constructor( + val dateFormatter: VectorDateFormatter, +) : TypedEpoxyController() { interface Callback { fun vote(pollEventId: String, optionId: String) @@ -37,6 +41,7 @@ class RoomPollDetailController @Inject constructor() : TypedEpoxyController(R.layout.item_timeline_event_poll) { +abstract class RoomPollDetailItem : VectorEpoxyModel(R.layout.item_poll_detail) { + + @EpoxyAttribute + lateinit var formattedDate: String @EpoxyAttribute var question: String? = null @@ -53,7 +56,7 @@ abstract class RoomPollDetailItem : VectorEpoxyModel( override fun bind(holder: Holder) { super.bind(holder) - + holder.date.text = formattedDate holder.questionTextView.text = question holder.votesStatusTextView.text = votesStatus holder.optionsContainer.removeAllViews() @@ -77,6 +80,7 @@ abstract class RoomPollDetailItem : VectorEpoxyModel( } class Holder : VectorEpoxyHolder() { + val date by bind(R.id.pollDetailDate) val questionTextView by bind(R.id.questionTextView) val optionsContainer by bind(R.id.optionsContainer) val votesStatusTextView by bind(R.id.optionsVotesStatusTextView) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailMapper.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailMapper.kt index 7818703716..4c4fffc654 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailMapper.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailMapper.kt @@ -39,14 +39,21 @@ class RoomPollDetailMapper @Inject constructor( val result = runCatching { val content = timelineEvent.getVectorLastMessageContent() val pollResponseData = pollResponseDataFactory.create(timelineEvent) - return if (eventId.isNotEmpty() && content is MessagePollContent) { + val creationTimestamp = timelineEvent.root.originServerTs ?: 0 + return if (eventId.isNotEmpty() && creationTimestamp > 0 && content is MessagePollContent) { val isPollEnded = pollResponseData?.isClosed.orFalse() val endedPollEventId = getEndedPollEventId( isPollEnded, startPollEventId = eventId, roomId = timelineEvent.roomId, ) - convertToRoomPollDetail(content, pollResponseData, isPollEnded, endedPollEventId) + convertToRoomPollDetail( + creationTimestamp = creationTimestamp, + content = content, + pollResponseData = pollResponseData, + isPollEnded = isPollEnded, + endedPollEventId = endedPollEventId, + ) } else { Timber.w("missing mandatory info about poll event with id=$eventId") null @@ -60,6 +67,7 @@ class RoomPollDetailMapper @Inject constructor( } private fun convertToRoomPollDetail( + creationTimestamp: Long, content: MessagePollContent, pollResponseData: PollResponseData?, isPollEnded: Boolean, @@ -72,6 +80,7 @@ class RoomPollDetailMapper @Inject constructor( isSent = true, ) return RoomPollDetail( + creationTimestamp = creationTimestamp, isEnded = isPollEnded, pollItemViewState = pollItemViewState, endedPollEventId = endedPollEventId, diff --git a/vector/src/main/res/layout/item_poll_detail.xml b/vector/src/main/res/layout/item_poll_detail.xml new file mode 100644 index 0000000000..353c7a81e3 --- /dev/null +++ b/vector/src/main/res/layout/item_poll_detail.xml @@ -0,0 +1,29 @@ + + + + + + + +