Render the active polls list on fragment

This commit is contained in:
Maxime NATUREL 2022-12-30 10:56:44 +01:00
parent 7b63f891c3
commit f20513eb16
3 changed files with 58 additions and 1 deletions

View file

@ -16,20 +16,63 @@
package im.vector.app.features.roomprofile.polls.active
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.airbnb.mvrx.parentFragmentViewModel
import com.airbnb.mvrx.withState
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.core.extensions.cleanup
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentRoomPollsListBinding
import im.vector.app.features.roomprofile.polls.PollSummary
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
import javax.inject.Inject
@AndroidEntryPoint
class RoomActivePollsFragment : VectorBaseFragment<FragmentRoomPollsListBinding>() {
class RoomActivePollsFragment :
VectorBaseFragment<FragmentRoomPollsListBinding>(),
RoomActivePollsController.Listener {
@Inject
lateinit var roomActivePollsController: RoomActivePollsController
private val viewModel: RoomPollsViewModel by parentFragmentViewModel(RoomPollsViewModel::class)
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollsListBinding {
return FragmentRoomPollsListBinding.inflate(inflater, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupList()
}
private fun setupList() {
roomActivePollsController.listener = this
views.activePollsList.adapter = roomActivePollsController.adapter
}
override fun onDestroyView() {
cleanUpList()
super.onDestroyView()
}
private fun cleanUpList() {
views.activePollsList.cleanup()
roomActivePollsController.listener = null
}
override fun invalidate() = withState(viewModel) { viewState ->
renderList(viewState.polls.filterIsInstance(PollSummary.ActivePoll::class.java))
}
private fun renderList(polls: List<PollSummary.ActivePoll>) {
roomActivePollsController.setData(polls)
}
override fun onPollClicked(pollId: String) {
// TODO navigate to details
}
}

View file

@ -1,7 +1,20 @@
<?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="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activePollsList"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/layout_horizontal_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="5"
tools:listitem="@layout/item_poll_active" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -10,6 +10,7 @@
android:id="@+id/pollActiveDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textAppearance="@style/TextAppearance.Vector.Caption"
android:textColor="?vctr_content_tertiary"
app:layout_constraintStart_toStartOf="parent"