Adding total votes status for ended poll items
This commit is contained in:
parent
05363dc8ca
commit
a5d076a28a
@ -18,6 +18,7 @@ package im.vector.app.features.roomprofile.polls.list
|
||||
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.app.R
|
||||
@ -25,6 +26,7 @@ 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.core.extensions.setTextOrHide
|
||||
import im.vector.app.features.home.room.detail.timeline.item.PollOptionView
|
||||
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
|
||||
|
||||
@ -40,6 +42,9 @@ abstract class RoomPollItem : VectorEpoxyModel<RoomPollItem.Holder>(R.layout.ite
|
||||
@EpoxyAttribute
|
||||
var winnerOptions: List<PollOptionViewState.PollEnded> = emptyList()
|
||||
|
||||
@EpoxyAttribute
|
||||
var totalVotesStatus: String? = null
|
||||
|
||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
||||
var clickListener: ClickListener? = null
|
||||
|
||||
@ -49,16 +54,19 @@ abstract class RoomPollItem : VectorEpoxyModel<RoomPollItem.Holder>(R.layout.ite
|
||||
holder.date.text = formattedDate
|
||||
holder.title.text = title
|
||||
holder.winnerOptions.removeAllViews()
|
||||
holder.winnerOptions.isVisible = winnerOptions.isNotEmpty()
|
||||
for (winnerOption in winnerOptions) {
|
||||
val optionView = PollOptionView(holder.view.context)
|
||||
holder.winnerOptions.addView(optionView)
|
||||
optionView.render(winnerOption)
|
||||
}
|
||||
holder.totalVotes.setTextOrHide(totalVotesStatus)
|
||||
}
|
||||
|
||||
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)
|
||||
val totalVotes by bind<TextView>(R.id.pollTotalVotes)
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,16 @@
|
||||
package im.vector.app.features.roomprofile.polls.list
|
||||
|
||||
import com.airbnb.epoxy.TypedEpoxyController
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.date.DateFormatKind
|
||||
import im.vector.app.core.date.VectorDateFormatter
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.features.roomprofile.polls.PollSummary
|
||||
import javax.inject.Inject
|
||||
|
||||
class RoomPollsController @Inject constructor(
|
||||
val dateFormatter: VectorDateFormatter,
|
||||
val stringProvider: StringProvider,
|
||||
) : TypedEpoxyController<List<PollSummary>>() {
|
||||
|
||||
interface Listener {
|
||||
@ -64,6 +67,7 @@ class RoomPollsController @Inject constructor(
|
||||
formattedDate(host.dateFormatter.format(poll.creationTimestamp, DateFormatKind.TIMELINE_DAY_DIVIDER))
|
||||
title(poll.title)
|
||||
winnerOptions(poll.winnerOptions)
|
||||
totalVotesStatus(host.stringProvider.getQuantityString(R.plurals.poll_total_vote_count_after_ended, poll.totalVotes, poll.totalVotes))
|
||||
clickListener {
|
||||
host.listener?.onPollClicked(poll.id)
|
||||
}
|
||||
|
@ -54,4 +54,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/pollTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pollTotalVotes"
|
||||
style="@style/Widget.Vector.TextView.Caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/pollWinnerOptionsContainer"
|
||||
tools:text="@sample/poll.json/totalVotes" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user