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.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.airbnb.epoxy.EpoxyAttribute
|
import com.airbnb.epoxy.EpoxyAttribute
|
||||||
import com.airbnb.epoxy.EpoxyModelClass
|
import com.airbnb.epoxy.EpoxyModelClass
|
||||||
import im.vector.app.R
|
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.VectorEpoxyHolder
|
||||||
import im.vector.app.core.epoxy.VectorEpoxyModel
|
import im.vector.app.core.epoxy.VectorEpoxyModel
|
||||||
import im.vector.app.core.epoxy.onClick
|
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.PollOptionView
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
|
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
|
@EpoxyAttribute
|
||||||
var winnerOptions: List<PollOptionViewState.PollEnded> = emptyList()
|
var winnerOptions: List<PollOptionViewState.PollEnded> = emptyList()
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
var totalVotesStatus: String? = null
|
||||||
|
|
||||||
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
@EpoxyAttribute(EpoxyAttribute.Option.DoNotHash)
|
||||||
var clickListener: ClickListener? = null
|
var clickListener: ClickListener? = null
|
||||||
|
|
||||||
@ -49,16 +54,19 @@ abstract class RoomPollItem : VectorEpoxyModel<RoomPollItem.Holder>(R.layout.ite
|
|||||||
holder.date.text = formattedDate
|
holder.date.text = formattedDate
|
||||||
holder.title.text = title
|
holder.title.text = title
|
||||||
holder.winnerOptions.removeAllViews()
|
holder.winnerOptions.removeAllViews()
|
||||||
|
holder.winnerOptions.isVisible = winnerOptions.isNotEmpty()
|
||||||
for (winnerOption in winnerOptions) {
|
for (winnerOption in winnerOptions) {
|
||||||
val optionView = PollOptionView(holder.view.context)
|
val optionView = PollOptionView(holder.view.context)
|
||||||
holder.winnerOptions.addView(optionView)
|
holder.winnerOptions.addView(optionView)
|
||||||
optionView.render(winnerOption)
|
optionView.render(winnerOption)
|
||||||
}
|
}
|
||||||
|
holder.totalVotes.setTextOrHide(totalVotesStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Holder : VectorEpoxyHolder() {
|
class Holder : VectorEpoxyHolder() {
|
||||||
val date by bind<TextView>(R.id.pollDate)
|
val date by bind<TextView>(R.id.pollDate)
|
||||||
val title by bind<TextView>(R.id.pollTitle)
|
val title by bind<TextView>(R.id.pollTitle)
|
||||||
val winnerOptions by bind<LinearLayout>(R.id.pollWinnerOptionsContainer)
|
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
|
package im.vector.app.features.roomprofile.polls.list
|
||||||
|
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
|
import im.vector.app.R
|
||||||
import im.vector.app.core.date.DateFormatKind
|
import im.vector.app.core.date.DateFormatKind
|
||||||
import im.vector.app.core.date.VectorDateFormatter
|
import im.vector.app.core.date.VectorDateFormatter
|
||||||
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.roomprofile.polls.PollSummary
|
import im.vector.app.features.roomprofile.polls.PollSummary
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RoomPollsController @Inject constructor(
|
class RoomPollsController @Inject constructor(
|
||||||
val dateFormatter: VectorDateFormatter,
|
val dateFormatter: VectorDateFormatter,
|
||||||
|
val stringProvider: StringProvider,
|
||||||
) : TypedEpoxyController<List<PollSummary>>() {
|
) : TypedEpoxyController<List<PollSummary>>() {
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
@ -64,6 +67,7 @@ class RoomPollsController @Inject constructor(
|
|||||||
formattedDate(host.dateFormatter.format(poll.creationTimestamp, DateFormatKind.TIMELINE_DAY_DIVIDER))
|
formattedDate(host.dateFormatter.format(poll.creationTimestamp, DateFormatKind.TIMELINE_DAY_DIVIDER))
|
||||||
title(poll.title)
|
title(poll.title)
|
||||||
winnerOptions(poll.winnerOptions)
|
winnerOptions(poll.winnerOptions)
|
||||||
|
totalVotesStatus(host.stringProvider.getQuantityString(R.plurals.poll_total_vote_count_after_ended, poll.totalVotes, poll.totalVotes))
|
||||||
clickListener {
|
clickListener {
|
||||||
host.listener?.onPollClicked(poll.id)
|
host.listener?.onPollClicked(poll.id)
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,16 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/pollTitle" />
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user