Epoxy controller to render active poll list

This commit is contained in:
Maxime NATUREL 2022-12-30 10:42:42 +01:00
parent 9f97579f9d
commit 7b63f891c3
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.roomprofile.polls
sealed interface PollSummary {
data class ActivePoll(
val id: String,
val creationTimestamp: Long,
val title: String,
) : PollSummary
}

View File

@ -21,6 +21,7 @@ import im.vector.app.features.roomprofile.RoomProfileArgs
data class RoomPollsViewState( data class RoomPollsViewState(
val roomId: String, val roomId: String,
val polls: List<PollSummary> = emptyList(),
) : MavericksState { ) : MavericksState {
constructor(roomProfileArgs: RoomProfileArgs) : this(roomId = roomProfileArgs.roomId) constructor(roomProfileArgs: RoomProfileArgs) : this(roomId = roomProfileArgs.roomId)

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.roomprofile.polls.active
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.features.roomprofile.polls.PollSummary
import javax.inject.Inject
class RoomActivePollsController @Inject constructor(
val dateFormatter: VectorDateFormatter,
) : TypedEpoxyController<List<PollSummary.ActivePoll>>() {
interface Listener {
fun onPollClicked(pollId: String)
}
var listener: Listener? = null
override fun buildModels(data: List<PollSummary.ActivePoll>?) {
if (data == null) return
val host = this
data.forEach { poll ->
activePollItem {
formattedDate(host.dateFormatter.format(poll.creationTimestamp, DateFormatKind.EDIT_HISTORY_HEADER))
title(poll.title)
clickListener {
host.listener?.onPollClicked(poll.id)
}
}
}
}
}