From 171717bcd18318394c22326c4df77e23b349bdb9 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL <46314705+mnaturel@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:03:39 +0100 Subject: [PATCH] Adding helper methods for ViewState --- .../app/features/roomprofile/polls/RoomPollsViewState.kt | 3 +++ .../roomprofile/polls/list/ui/RoomPollsListFragment.kt | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsViewState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsViewState.kt index eca32e2481..fa985c5c76 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsViewState.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsViewState.kt @@ -30,4 +30,7 @@ data class RoomPollsViewState( ) : MavericksState { constructor(roomProfileArgs: RoomProfileArgs) : this(roomId = roomProfileArgs.roomId) + + fun hasNoPolls() = polls.isEmpty() + fun hasNoPollsAndCanLoadMore() = !isSyncing && hasNoPolls() && canLoadMore } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListFragment.kt index 327b1d713a..5920eb046e 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListFragment.kt @@ -119,11 +119,10 @@ abstract class RoomPollsListFragment : canLoadMore = viewState.canLoadMore, nbLoadedDays = viewState.nbLoadedDays, ) - views.roomPollsEmptyTitle.isVisible = viewState.polls.isEmpty() && !viewState.isSyncing - views.roomPollsLoadMoreWhenEmpty.isVisible = viewState.polls.isEmpty() && viewState.canLoadMore && !viewState.isSyncing - views.roomPollsLoadMoreWhenEmptyProgress.isVisible = viewState.polls.isEmpty() && viewState.canLoadMore && - viewState.isLoadingMore && !viewState.isSyncing - views.roomPollsLoadMoreWhenEmptyProgress.isEnabled = !viewState.isLoadingMore + views.roomPollsEmptyTitle.isVisible = !viewState.isSyncing && viewState.hasNoPolls() + views.roomPollsLoadMoreWhenEmpty.isVisible = viewState.hasNoPollsAndCanLoadMore() + views.roomPollsLoadMoreWhenEmpty.isEnabled = !viewState.isLoadingMore + views.roomPollsLoadMoreWhenEmptyProgress.isVisible = viewState.hasNoPollsAndCanLoadMore() && viewState.isLoadingMore } override fun onPollClicked(pollId: String) {