Skip to content

Commit

Permalink
Adding winner option views for ended poll items
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaturel committed Jan 5, 2023
1 parent 1cc2644 commit 05363dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions vector/src/main/res/layout/item_poll.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 05363dc

Please sign in to comment.