mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 14:08:44 +03:00
Adding creation date field
This commit is contained in:
parent
2ee079fe79
commit
b75787a4f4
5 changed files with 53 additions and 5 deletions
|
@ -19,6 +19,7 @@ package im.vector.app.features.roomprofile.polls.detail.ui
|
||||||
import im.vector.app.features.poll.PollItemViewState
|
import im.vector.app.features.poll.PollItemViewState
|
||||||
|
|
||||||
data class RoomPollDetail(
|
data class RoomPollDetail(
|
||||||
|
val creationTimestamp: Long,
|
||||||
val isEnded: Boolean,
|
val isEnded: Boolean,
|
||||||
val endedPollEventId: String?,
|
val endedPollEventId: String?,
|
||||||
val pollItemViewState: PollItemViewState,
|
val pollItemViewState: PollItemViewState,
|
||||||
|
|
|
@ -17,10 +17,14 @@
|
||||||
package im.vector.app.features.roomprofile.polls.detail.ui
|
package im.vector.app.features.roomprofile.polls.detail.ui
|
||||||
|
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
|
import im.vector.app.core.date.DateFormatKind
|
||||||
|
import im.vector.app.core.date.VectorDateFormatter
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RoomPollDetailController @Inject constructor() : TypedEpoxyController<RoomPollDetailViewState>() {
|
class RoomPollDetailController @Inject constructor(
|
||||||
|
val dateFormatter: VectorDateFormatter,
|
||||||
|
) : TypedEpoxyController<RoomPollDetailViewState>() {
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
fun vote(pollEventId: String, optionId: String)
|
fun vote(pollEventId: String, optionId: String)
|
||||||
|
@ -37,6 +41,7 @@ class RoomPollDetailController @Inject constructor() : TypedEpoxyController<Room
|
||||||
roomPollDetailItem {
|
roomPollDetailItem {
|
||||||
id(viewState.pollId)
|
id(viewState.pollId)
|
||||||
eventId(viewState.pollId)
|
eventId(viewState.pollId)
|
||||||
|
formattedDate(host.dateFormatter.format(pollDetail.creationTimestamp, DateFormatKind.TIMELINE_DAY_DIVIDER))
|
||||||
question(pollItemViewState.question)
|
question(pollItemViewState.question)
|
||||||
canVote(pollItemViewState.canVote)
|
canVote(pollItemViewState.canVote)
|
||||||
votesStatus(pollItemViewState.votesStatus)
|
votesStatus(pollItemViewState.votesStatus)
|
||||||
|
|
|
@ -28,7 +28,10 @@ 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
|
||||||
|
|
||||||
@EpoxyModelClass
|
@EpoxyModelClass
|
||||||
abstract class RoomPollDetailItem : VectorEpoxyModel<RoomPollDetailItem.Holder>(R.layout.item_timeline_event_poll) {
|
abstract class RoomPollDetailItem : VectorEpoxyModel<RoomPollDetailItem.Holder>(R.layout.item_poll_detail) {
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
lateinit var formattedDate: String
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var question: String? = null
|
var question: String? = null
|
||||||
|
@ -53,7 +56,7 @@ abstract class RoomPollDetailItem : VectorEpoxyModel<RoomPollDetailItem.Holder>(
|
||||||
|
|
||||||
override fun bind(holder: Holder) {
|
override fun bind(holder: Holder) {
|
||||||
super.bind(holder)
|
super.bind(holder)
|
||||||
|
holder.date.text = formattedDate
|
||||||
holder.questionTextView.text = question
|
holder.questionTextView.text = question
|
||||||
holder.votesStatusTextView.text = votesStatus
|
holder.votesStatusTextView.text = votesStatus
|
||||||
holder.optionsContainer.removeAllViews()
|
holder.optionsContainer.removeAllViews()
|
||||||
|
@ -77,6 +80,7 @@ abstract class RoomPollDetailItem : VectorEpoxyModel<RoomPollDetailItem.Holder>(
|
||||||
}
|
}
|
||||||
|
|
||||||
class Holder : VectorEpoxyHolder() {
|
class Holder : VectorEpoxyHolder() {
|
||||||
|
val date by bind<TextView>(R.id.pollDetailDate)
|
||||||
val questionTextView by bind<TextView>(R.id.questionTextView)
|
val questionTextView by bind<TextView>(R.id.questionTextView)
|
||||||
val optionsContainer by bind<LinearLayout>(R.id.optionsContainer)
|
val optionsContainer by bind<LinearLayout>(R.id.optionsContainer)
|
||||||
val votesStatusTextView by bind<TextView>(R.id.optionsVotesStatusTextView)
|
val votesStatusTextView by bind<TextView>(R.id.optionsVotesStatusTextView)
|
||||||
|
|
|
@ -39,14 +39,21 @@ class RoomPollDetailMapper @Inject constructor(
|
||||||
val result = runCatching {
|
val result = runCatching {
|
||||||
val content = timelineEvent.getVectorLastMessageContent()
|
val content = timelineEvent.getVectorLastMessageContent()
|
||||||
val pollResponseData = pollResponseDataFactory.create(timelineEvent)
|
val pollResponseData = pollResponseDataFactory.create(timelineEvent)
|
||||||
return if (eventId.isNotEmpty() && content is MessagePollContent) {
|
val creationTimestamp = timelineEvent.root.originServerTs ?: 0
|
||||||
|
return if (eventId.isNotEmpty() && creationTimestamp > 0 && content is MessagePollContent) {
|
||||||
val isPollEnded = pollResponseData?.isClosed.orFalse()
|
val isPollEnded = pollResponseData?.isClosed.orFalse()
|
||||||
val endedPollEventId = getEndedPollEventId(
|
val endedPollEventId = getEndedPollEventId(
|
||||||
isPollEnded,
|
isPollEnded,
|
||||||
startPollEventId = eventId,
|
startPollEventId = eventId,
|
||||||
roomId = timelineEvent.roomId,
|
roomId = timelineEvent.roomId,
|
||||||
)
|
)
|
||||||
convertToRoomPollDetail(content, pollResponseData, isPollEnded, endedPollEventId)
|
convertToRoomPollDetail(
|
||||||
|
creationTimestamp = creationTimestamp,
|
||||||
|
content = content,
|
||||||
|
pollResponseData = pollResponseData,
|
||||||
|
isPollEnded = isPollEnded,
|
||||||
|
endedPollEventId = endedPollEventId,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
Timber.w("missing mandatory info about poll event with id=$eventId")
|
Timber.w("missing mandatory info about poll event with id=$eventId")
|
||||||
null
|
null
|
||||||
|
@ -60,6 +67,7 @@ class RoomPollDetailMapper @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertToRoomPollDetail(
|
private fun convertToRoomPollDetail(
|
||||||
|
creationTimestamp: Long,
|
||||||
content: MessagePollContent,
|
content: MessagePollContent,
|
||||||
pollResponseData: PollResponseData?,
|
pollResponseData: PollResponseData?,
|
||||||
isPollEnded: Boolean,
|
isPollEnded: Boolean,
|
||||||
|
@ -72,6 +80,7 @@ class RoomPollDetailMapper @Inject constructor(
|
||||||
isSent = true,
|
isSent = true,
|
||||||
)
|
)
|
||||||
return RoomPollDetail(
|
return RoomPollDetail(
|
||||||
|
creationTimestamp = creationTimestamp,
|
||||||
isEnded = isPollEnded,
|
isEnded = isPollEnded,
|
||||||
pollItemViewState = pollItemViewState,
|
pollItemViewState = pollItemViewState,
|
||||||
endedPollEventId = endedPollEventId,
|
endedPollEventId = endedPollEventId,
|
||||||
|
|
29
vector/src/main/res/layout/item_poll_detail.xml
Normal file
29
vector/src/main/res/layout/item_poll_detail.xml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/pollDetailDate"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="@style/TextAppearance.Vector.Caption"
|
||||||
|
android:textColor="?vctr_content_tertiary"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/pollDetailContent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:text="28/06/22" />
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/pollDetailContent"
|
||||||
|
layout="@layout/item_timeline_event_poll"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/pollDetailDate" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in a new issue