diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/active/RoomActivePollsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/active/RoomActivePollsFragment.kt index 230da49b22..10518d4b18 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/active/RoomActivePollsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/active/RoomActivePollsFragment.kt @@ -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() { +class RoomActivePollsFragment : + VectorBaseFragment(), + 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) { + roomActivePollsController.setData(polls) + } + + override fun onPollClicked(pollId: String) { + // TODO navigate to details + } } diff --git a/vector/src/main/res/layout/fragment_room_polls_list.xml b/vector/src/main/res/layout/fragment_room_polls_list.xml index 1d672087a9..39add6a298 100644 --- a/vector/src/main/res/layout/fragment_room_polls_list.xml +++ b/vector/src/main/res/layout/fragment_room_polls_list.xml @@ -1,7 +1,20 @@ + + diff --git a/vector/src/main/res/layout/item_poll_active.xml b/vector/src/main/res/layout/item_poll_active.xml index 8cf6c9e576..2db6450f94 100644 --- a/vector/src/main/res/layout/item_poll_active.xml +++ b/vector/src/main/res/layout/item_poll_active.xml @@ -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"