From 05363dc8ca26609ff41f746869a720ccb7da6135 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Wed, 4 Jan 2023 10:30:57 +0100 Subject: [PATCH] Adding winner option views for ended poll items --- .../features/roomprofile/polls/list/RoomPollItem.kt | 13 +++++++++++++ .../roomprofile/polls/list/RoomPollsController.kt | 1 + vector/src/main/res/layout/item_poll.xml | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollItem.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollItem.kt index 633162f6eb..fd4e36159e 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollItem.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollItem.kt @@ -16,6 +16,7 @@ package im.vector.app.features.roomprofile.polls.list +import android.widget.LinearLayout import android.widget.TextView import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass @@ -24,6 +25,8 @@ import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.VectorEpoxyModel import im.vector.app.core.epoxy.onClick +import im.vector.app.features.home.room.detail.timeline.item.PollOptionView +import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState @EpoxyModelClass abstract class RoomPollItem : VectorEpoxyModel(R.layout.item_poll) { @@ -34,6 +37,9 @@ abstract class RoomPollItem : VectorEpoxyModel(R.layout.ite @EpoxyAttribute lateinit var title: String + @EpoxyAttribute + var winnerOptions: List = emptyList() + @EpoxyAttribute(EpoxyAttribute.Option.DoNotHash) var clickListener: ClickListener? = null @@ -42,10 +48,17 @@ abstract class RoomPollItem : VectorEpoxyModel(R.layout.ite holder.view.onClick(clickListener) holder.date.text = formattedDate holder.title.text = title + holder.winnerOptions.removeAllViews() + for (winnerOption in winnerOptions) { + val optionView = PollOptionView(holder.view.context) + holder.winnerOptions.addView(optionView) + optionView.render(winnerOption) + } } class Holder : VectorEpoxyHolder() { val date by bind(R.id.pollDate) val title by bind(R.id.pollTitle) + val winnerOptions by bind(R.id.pollWinnerOptionsContainer) } } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollsController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollsController.kt index e24241f0af..c6288aac8b 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollsController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/RoomPollsController.kt @@ -63,6 +63,7 @@ class RoomPollsController @Inject constructor( id(poll.id) formattedDate(host.dateFormatter.format(poll.creationTimestamp, DateFormatKind.TIMELINE_DAY_DIVIDER)) title(poll.title) + winnerOptions(poll.winnerOptions) clickListener { host.listener?.onPollClicked(poll.id) } diff --git a/vector/src/main/res/layout/item_poll.xml b/vector/src/main/res/layout/item_poll.xml index 8e9fa54a0f..9563f3d52a 100644 --- a/vector/src/main/res/layout/item_poll.xml +++ b/vector/src/main/res/layout/item_poll.xml @@ -42,4 +42,16 @@ app:layout_constraintTop_toBottomOf="@id/pollDate" tools:text="Which sport should the pupils do this year?" /> + +