Skip to content

Commit

Permalink
Epoxy controller to render active poll list
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaturel committed Jan 4, 2023
1 parent 9f97579 commit 7b63f89
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import im.vector.app.features.roomprofile.RoomProfileArgs

data class RoomPollsViewState(
val roomId: String,
val polls: List<PollSummary> = emptyList(),
) : MavericksState {

constructor(roomProfileArgs: RoomProfileArgs) : this(roomId = roomProfileArgs.roomId)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
}

0 comments on commit 7b63f89

Please sign in to comment.