mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
Render poll detail.
This commit is contained in:
parent
b86f6a41bd
commit
ec4226b5d3
4 changed files with 55 additions and 3 deletions
|
@ -36,4 +36,5 @@ data class RoomPollsViewState(
|
||||||
fun hasNoPolls() = polls.isEmpty()
|
fun hasNoPolls() = polls.isEmpty()
|
||||||
fun hasNoPollsAndCanLoadMore() = !isSyncing && hasNoPolls() && canLoadMore
|
fun hasNoPollsAndCanLoadMore() = !isSyncing && hasNoPolls() && canLoadMore
|
||||||
fun getSelectedPoll() = polls.find { it.id == selectedPollId }
|
fun getSelectedPoll() = polls.find { it.id == selectedPollId }
|
||||||
|
fun canVoteSelectedPoll() = selectedRoomPollsType == RoomPollsType.ACTIVE
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,15 +26,19 @@ import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.extensions.configureWith
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
import im.vector.app.databinding.FragmentRoomPollDetailBinding
|
import im.vector.app.databinding.FragmentRoomPollDetailBinding
|
||||||
import im.vector.app.features.roomprofile.RoomProfileArgs
|
import im.vector.app.features.roomprofile.RoomProfileArgs
|
||||||
import im.vector.app.features.roomprofile.polls.RoomPollsType
|
import im.vector.app.features.roomprofile.polls.RoomPollsType
|
||||||
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
|
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>() {
|
class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>() {
|
||||||
|
|
||||||
|
@Inject lateinit var roomPollDetailController: RoomPollDetailController
|
||||||
|
|
||||||
private val viewModel: RoomPollsViewModel by activityViewModel()
|
private val viewModel: RoomPollsViewModel by activityViewModel()
|
||||||
private val roomProfileArgs: RoomProfileArgs by args()
|
private val roomProfileArgs: RoomProfileArgs by args()
|
||||||
|
|
||||||
|
@ -45,11 +49,14 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
initToolbar()
|
views.pollDetailRecyclerView.configureWith(
|
||||||
|
roomPollDetailController,
|
||||||
|
hasFixedSize = true,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initToolbar() = withState(viewModel) { state ->
|
private fun setupToolbar(roomPollsType: RoomPollsType) {
|
||||||
val title = if (state.selectedRoomPollsType == RoomPollsType.ACTIVE) getString(R.string.room_polls_active)
|
val title = if (roomPollsType == RoomPollsType.ACTIVE) getString(R.string.room_polls_active)
|
||||||
else getString(R.string.room_polls_ended)
|
else getString(R.string.room_polls_ended)
|
||||||
|
|
||||||
setupToolbar(views.roomPollDetailToolbar)
|
setupToolbar(views.roomPollDetailToolbar)
|
||||||
|
@ -58,7 +65,10 @@ class RoomPollDetailFragment : VectorBaseFragment<FragmentRoomPollDetailBinding>
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invalidate() = withState(viewModel) { state ->
|
override fun invalidate() = withState(viewModel) { state ->
|
||||||
|
setupToolbar(state.selectedRoomPollsType)
|
||||||
|
|
||||||
state.getSelectedPoll()?.let { _ ->
|
state.getSelectedPoll()?.let { _ ->
|
||||||
|
roomPollDetailController.setData(state)
|
||||||
}
|
}
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/pollDetailRecyclerView"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
|
|
Loading…
Reference in a new issue