Render poll detail.

This commit is contained in:
Onuray Sahin 2023-01-31 12:19:30 +03:00 committed by Maxime NATUREL
parent b86f6a41bd
commit ec4226b5d3
4 changed files with 55 additions and 3 deletions

View file

@ -36,4 +36,5 @@ data class RoomPollsViewState(
fun hasNoPolls() = polls.isEmpty()
fun hasNoPollsAndCanLoadMore() = !isSyncing && hasNoPolls() && canLoadMore
fun getSelectedPoll() = polls.find { it.id == selectedPollId }
fun canVoteSelectedPoll() = selectedRoomPollsType == RoomPollsType.ACTIVE
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2023 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.detail
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.app.features.home.room.detail.timeline.item.PollItem_
import im.vector.app.features.roomprofile.polls.RoomPollsViewState
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
import javax.inject.Inject
class RoomPollDetailController @Inject constructor(
) : TypedEpoxyController<RoomPollsViewState>() {
override fun buildModels(viewState: RoomPollsViewState?) {
viewState ?: return
val pollSummary = viewState.getSelectedPoll() ?: return
PollItem_()
.eventId(pollSummary.id)
.pollQuestion(pollSummary.title.toEpoxyCharSequence())
.canVote(viewState.canVoteSelectedPoll())
.optionViewStates(pollSummary.optionViewStates)
.ended(viewState.canVoteSelectedPoll().not())
}
}

View file

@ -26,15 +26,19 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentRoomPollDetailBinding
import im.vector.app.features.roomprofile.RoomProfileArgs
import im.vector.app.features.roomprofile.polls.RoomPollsType
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
import javax.inject.Inject
@AndroidEntryPoint
class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>() {
@Inject lateinit var roomPollDetailController: RoomPollDetailController
private val viewModel: RoomPollsViewModel by activityViewModel()
private val roomProfileArgs: RoomProfileArgs by args()
@ -45,11 +49,14 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initToolbar()
views.pollDetailRecyclerView.configureWith(
roomPollDetailController,
hasFixedSize = true,
)
}
private fun initToolbar() = withState(viewModel) { state ->
val title = if (state.selectedRoomPollsType == RoomPollsType.ACTIVE) getString(R.string.room_polls_active)
private fun setupToolbar(roomPollsType: RoomPollsType) {
val title = if (roomPollsType == RoomPollsType.ACTIVE) getString(R.string.room_polls_active)
else getString(R.string.room_polls_ended)
setupToolbar(views.roomPollDetailToolbar)
@ -58,7 +65,10 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
}
override fun invalidate() = withState(viewModel) { state ->
setupToolbar(state.selectedRoomPollsType)
state.getSelectedPoll()?.let { _ ->
roomPollDetailController.setData(state)
}
Unit
}

View file

@ -22,6 +22,7 @@
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/pollDetailRecyclerView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"