Adding winner option views for ended poll items

This commit is contained in:
Maxime NATUREL 2023-01-04 10:30:57 +01:00
parent 1cc26449f3
commit 05363dc8ca
3 changed files with 26 additions and 0 deletions

View file

@ -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<RoomPollItem.Holder>(R.layout.item_poll) {
@ -34,6 +37,9 @@ abstract class RoomPollItem : VectorEpoxyModel<RoomPollItem.Holder>(R.layout.ite
@EpoxyAttribute
lateinit var title: String
@EpoxyAttribute
var winnerOptions: List<PollOptionViewState.PollEnded> = emptyList()
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
var clickListener: ClickListener? = null
@ -42,10 +48,17 @@ abstract class RoomPollItem : VectorEpoxyModel<RoomPollItem.Holder>(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<TextView>(R.id.pollDate)
val title by bind<TextView>(R.id.pollTitle)
val winnerOptions by bind<LinearLayout>(R.id.pollWinnerOptionsContainer)
}
}

View file

@ -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)
}

View file

@ -42,4 +42,16 @@
app:layout_constraintTop_toBottomOf="@id/pollDate"
tools:text="Which sport should the pupils do this year?" />
<LinearLayout
android:id="@+id/pollWinnerOptionsContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:divider="@drawable/divider_poll_options"
android:orientation="vertical"
android:showDividers="middle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/pollTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>