Render the active polls list on fragment
This commit is contained in:
parent
7b63f891c3
commit
f20513eb16
|
@ -16,20 +16,63 @@
|
||||||
|
|
||||||
package im.vector.app.features.roomprofile.polls.active
|
package im.vector.app.features.roomprofile.polls.active
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.airbnb.mvrx.parentFragmentViewModel
|
import com.airbnb.mvrx.parentFragmentViewModel
|
||||||
|
import com.airbnb.mvrx.withState
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import im.vector.app.core.extensions.cleanup
|
||||||
import im.vector.app.core.platform.VectorBaseFragment
|
import im.vector.app.core.platform.VectorBaseFragment
|
||||||
import im.vector.app.databinding.FragmentRoomPollsListBinding
|
import im.vector.app.databinding.FragmentRoomPollsListBinding
|
||||||
|
import im.vector.app.features.roomprofile.polls.PollSummary
|
||||||
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
|
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class RoomActivePollsFragment : VectorBaseFragment<FragmentRoomPollsListBinding>() {
|
class RoomActivePollsFragment :
|
||||||
|
VectorBaseFragment<FragmentRoomPollsListBinding>(),
|
||||||
|
RoomActivePollsController.Listener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var roomActivePollsController: RoomActivePollsController
|
||||||
|
|
||||||
private val viewModel: RoomPollsViewModel by parentFragmentViewModel(RoomPollsViewModel::class)
|
private val viewModel: RoomPollsViewModel by parentFragmentViewModel(RoomPollsViewModel::class)
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollsListBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollsListBinding {
|
||||||
return FragmentRoomPollsListBinding.inflate(inflater, container, false)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<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_width="match_parent"
|
||||||
android:layout_height="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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
android:id="@+id/pollActiveDate"
|
android:id="@+id/pollActiveDate"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
android:textAppearance="@style/TextAppearance.Vector.Caption"
|
android:textAppearance="@style/TextAppearance.Vector.Caption"
|
||||||
android:textColor="?vctr_content_tertiary"
|
android:textColor="?vctr_content_tertiary"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
Loading…
Reference in New Issue