Skip to content

Commit 41bcdd7

Browse files
authored
Merge pull request #7867 from vector-im/feature/mna/active-polls-ui
[Poll] Render active polls list of a room (PSG-908)
2 parents b8da53b + 7fc9705 commit 41bcdd7

23 files changed

+800
-0
lines changed

changelog.d/7864.wip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Poll] Render active polls list of a room

library/ui-strings/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,7 @@
23352335
<item quantity="one">"One person"</item>
23362336
<item quantity="other">"%1$d people"</item>
23372337
</plurals>
2338+
<string name="room_profile_section_more_polls">Poll history</string>
23382339
<string name="room_profile_section_more_uploads">Uploads</string>
23392340
<string name="room_profile_section_more_leave">Leave Room</string>
23402341
<string name="direct_room_profile_section_more_leave">Leave</string>
@@ -3190,6 +3191,8 @@
31903191
<string name="open_poll_option_description">Voters see results as soon as they have voted</string>
31913192
<string name="closed_poll_option_title">Closed poll</string>
31923193
<string name="closed_poll_option_description">Results are only revealed when you end the poll</string>
3194+
<string name="room_polls_active">Active polls</string>
3195+
<string name="room_polls_active_no_item">There are no active polls in this room</string>
31933196

31943197
<!-- Location -->
31953198
<string name="location_activity_title_static_sharing">Share location</string>

vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import im.vector.app.features.roomprofile.banned.RoomBannedMemberListViewModel
8484
import im.vector.app.features.roomprofile.members.RoomMemberListViewModel
8585
import im.vector.app.features.roomprofile.notifications.RoomNotificationSettingsViewModel
8686
import im.vector.app.features.roomprofile.permissions.RoomPermissionsViewModel
87+
import im.vector.app.features.roomprofile.polls.RoomPollsViewModel
8788
import im.vector.app.features.roomprofile.settings.RoomSettingsViewModel
8889
import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRuleChooseRestrictedViewModel
8990
import im.vector.app.features.roomprofile.uploads.RoomUploadsViewModel
@@ -697,4 +698,9 @@ interface MavericksViewModelModule {
697698
@IntoMap
698699
@MavericksViewModelKey(SetLinkViewModel::class)
699700
fun setLinkViewModelFactory(factory: SetLinkViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
701+
702+
@Binds
703+
@IntoMap
704+
@MavericksViewModelKey(RoomPollsViewModel::class)
705+
fun roomPollsViewModelFactory(factory: RoomPollsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
700706
}

vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import im.vector.app.features.roomprofile.banned.RoomBannedMemberListFragment
3636
import im.vector.app.features.roomprofile.members.RoomMemberListFragment
3737
import im.vector.app.features.roomprofile.notifications.RoomNotificationSettingsFragment
3838
import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment
39+
import im.vector.app.features.roomprofile.polls.RoomPollsFragment
3940
import im.vector.app.features.roomprofile.settings.RoomSettingsFragment
4041
import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment
4142
import im.vector.lib.core.utils.compat.getParcelableCompat
@@ -98,6 +99,7 @@ class RoomProfileActivity :
9899
RoomProfileSharedAction.OpenRoomSettings -> openRoomSettings()
99100
RoomProfileSharedAction.OpenRoomAliasesSettings -> openRoomAlias()
100101
RoomProfileSharedAction.OpenRoomPermissionsSettings -> openRoomPermissions()
102+
RoomProfileSharedAction.OpenRoomPolls -> openRoomPolls()
101103
RoomProfileSharedAction.OpenRoomUploads -> openRoomUploads()
102104
RoomProfileSharedAction.OpenBannedRoomMembers -> openBannedRoomMembers()
103105
RoomProfileSharedAction.OpenRoomNotificationSettings -> openRoomNotificationSettings()
@@ -126,6 +128,10 @@ class RoomProfileActivity :
126128
finish()
127129
}
128130

131+
private fun openRoomPolls() {
132+
addFragmentToBackstack(views.simpleFragmentContainer, RoomPollsFragment::class.java, roomProfileArgs)
133+
}
134+
129135
private fun openRoomUploads() {
130136
addFragmentToBackstack(views.simpleFragmentContainer, RoomUploadsFragment::class.java, roomProfileArgs)
131137
}

vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileController.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package im.vector.app.features.roomprofile
1919

2020
import com.airbnb.epoxy.TypedEpoxyController
21+
import im.vector.app.BuildConfig
2122
import im.vector.app.R
2223
import im.vector.app.core.epoxy.expandableTextItem
2324
import im.vector.app.core.epoxy.profiles.buildProfileAction
@@ -56,6 +57,7 @@ class RoomProfileController @Inject constructor(
5657
fun onMemberListClicked()
5758
fun onBannedMemberListClicked()
5859
fun onNotificationsClicked()
60+
fun onPollHistoryClicked()
5961
fun onUploadsClicked()
6062
fun createShortcut()
6163
fun onSettingsClicked()
@@ -263,6 +265,15 @@ class RoomProfileController @Inject constructor(
263265
action = { callback?.onBannedMemberListClicked() }
264266
)
265267
}
268+
if (BuildConfig.DEBUG) {
269+
// WIP, will be in release when related screens will be finished
270+
buildProfileAction(
271+
id = "poll_history",
272+
title = stringProvider.getString(R.string.room_profile_section_more_polls),
273+
icon = R.drawable.ic_attachment_poll,
274+
action = { callback?.onPollHistoryClicked() }
275+
)
276+
}
266277
buildProfileAction(
267278
id = "uploads",
268279
title = stringProvider.getString(R.string.room_profile_section_more_uploads),

vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ class RoomProfileFragment :
269269
roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomNotificationSettings)
270270
}
271271

272+
override fun onPollHistoryClicked() {
273+
roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomPolls)
274+
}
275+
272276
override fun onUploadsClicked() {
273277
roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomUploads)
274278
}

vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileSharedAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sealed class RoomProfileSharedAction : VectorSharedAction {
2525
object OpenRoomSettings : RoomProfileSharedAction()
2626
object OpenRoomAliasesSettings : RoomProfileSharedAction()
2727
object OpenRoomPermissionsSettings : RoomProfileSharedAction()
28+
object OpenRoomPolls : RoomProfileSharedAction()
2829
object OpenRoomUploads : RoomProfileSharedAction()
2930
object OpenRoomMembers : RoomProfileSharedAction()
3031
object OpenBannedRoomMembers : RoomProfileSharedAction()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.features.roomprofile.polls
18+
19+
import kotlinx.coroutines.flow.Flow
20+
import kotlinx.coroutines.flow.emptyFlow
21+
import kotlinx.coroutines.flow.flowOf
22+
import kotlinx.coroutines.flow.map
23+
import javax.inject.Inject
24+
25+
class GetPollsUseCase @Inject constructor() {
26+
27+
fun execute(filter: RoomPollsFilterType): Flow<List<PollSummary>> {
28+
// TODO unmock and add unit tests
29+
return when (filter) {
30+
RoomPollsFilterType.ACTIVE -> getActivePolls()
31+
RoomPollsFilterType.ENDED -> emptyFlow()
32+
}.map { it.sortedByDescending { poll -> poll.creationTimestamp } }
33+
}
34+
35+
private fun getActivePolls(): Flow<List<PollSummary.ActivePoll>> {
36+
return flowOf(
37+
listOf(
38+
PollSummary.ActivePoll(
39+
id = "id1",
40+
// 2022/06/28 UTC+1
41+
creationTimestamp = 1656367200000,
42+
title = "Which charity would you like to support?"
43+
),
44+
PollSummary.ActivePoll(
45+
id = "id2",
46+
// 2022/06/26 UTC+1
47+
creationTimestamp = 1656194400000,
48+
title = "Which sport should the pupils do this year?"
49+
),
50+
PollSummary.ActivePoll(
51+
id = "id3",
52+
// 2022/06/24 UTC+1
53+
creationTimestamp = 1656021600000,
54+
title = "What type of food should we have at the party?"
55+
),
56+
PollSummary.ActivePoll(
57+
id = "id4",
58+
// 2022/06/22 UTC+1
59+
creationTimestamp = 1655848800000,
60+
title = "What film should we show at the end of the year party?"
61+
),
62+
)
63+
)
64+
}
65+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.features.roomprofile.polls
18+
19+
sealed interface PollSummary {
20+
data class ActivePoll(
21+
val id: String,
22+
val creationTimestamp: Long,
23+
val title: String,
24+
) : PollSummary
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.features.roomprofile.polls
18+
19+
import im.vector.app.core.platform.VectorViewModelAction
20+
21+
sealed interface RoomPollsAction : VectorViewModelAction {
22+
data class SetFilter(val filter: RoomPollsFilterType) : RoomPollsAction
23+
}

0 commit comments

Comments
 (0)