Skip to content

Commit

Permalink
Render the active polls list on fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaturel committed Jan 4, 2023
1 parent 7b63f89 commit f20513e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
13 changes: 13 additions & 0 deletions vector/src/main/res/layout/fragment_room_polls_list.xml
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions vector/src/main/res/layout/item_poll_active.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f20513e

Please sign in to comment.