forked from element-hq/element-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request element-hq#7867 from vector-im/feature/mna/active-…
…polls-ui [Poll] Render active polls list of a room (PSG-908)
- Loading branch information
Showing
23 changed files
with
800 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Poll] Render active polls list of a room |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
vector/src/main/java/im/vector/app/features/roomprofile/polls/GetPollsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.emptyFlow | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class GetPollsUseCase @Inject constructor() { | ||
|
||
fun execute(filter: RoomPollsFilterType): Flow<List<PollSummary>> { | ||
// TODO unmock and add unit tests | ||
return when (filter) { | ||
RoomPollsFilterType.ACTIVE -> getActivePolls() | ||
RoomPollsFilterType.ENDED -> emptyFlow() | ||
}.map { it.sortedByDescending { poll -> poll.creationTimestamp } } | ||
} | ||
|
||
private fun getActivePolls(): Flow<List<PollSummary.ActivePoll>> { | ||
return flowOf( | ||
listOf( | ||
PollSummary.ActivePoll( | ||
id = "id1", | ||
// 2022/06/28 UTC+1 | ||
creationTimestamp = 1656367200000, | ||
title = "Which charity would you like to support?" | ||
), | ||
PollSummary.ActivePoll( | ||
id = "id2", | ||
// 2022/06/26 UTC+1 | ||
creationTimestamp = 1656194400000, | ||
title = "Which sport should the pupils do this year?" | ||
), | ||
PollSummary.ActivePoll( | ||
id = "id3", | ||
// 2022/06/24 UTC+1 | ||
creationTimestamp = 1656021600000, | ||
title = "What type of food should we have at the party?" | ||
), | ||
PollSummary.ActivePoll( | ||
id = "id4", | ||
// 2022/06/22 UTC+1 | ||
creationTimestamp = 1655848800000, | ||
title = "What film should we show at the end of the year party?" | ||
), | ||
) | ||
) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
vector/src/main/java/im/vector/app/features/roomprofile/polls/PollSummary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
sealed interface PollSummary { | ||
data class ActivePoll( | ||
val id: String, | ||
val creationTimestamp: Long, | ||
val title: String, | ||
) : PollSummary | ||
} |
23 changes: 23 additions & 0 deletions
23
vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
import im.vector.app.core.platform.VectorViewModelAction | ||
|
||
sealed interface RoomPollsAction : VectorViewModelAction { | ||
data class SetFilter(val filter: RoomPollsFilterType) : RoomPollsAction | ||
} |
22 changes: 22 additions & 0 deletions
22
vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsFilterType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
enum class RoomPollsFilterType { | ||
ACTIVE, | ||
ENDED, | ||
} |
73 changes: 73 additions & 0 deletions
73
vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.airbnb.mvrx.args | ||
import com.airbnb.mvrx.fragmentViewModel | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import im.vector.app.R | ||
import im.vector.app.core.platform.VectorBaseFragment | ||
import im.vector.app.databinding.FragmentRoomPollsBinding | ||
import im.vector.app.features.roomprofile.RoomProfileArgs | ||
|
||
@AndroidEntryPoint | ||
class RoomPollsFragment : VectorBaseFragment<FragmentRoomPollsBinding>() { | ||
|
||
private val roomProfileArgs: RoomProfileArgs by args() | ||
|
||
private val viewModel: RoomPollsViewModel by fragmentViewModel() | ||
|
||
private var tabLayoutMediator: TabLayoutMediator? = null | ||
|
||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRoomPollsBinding { | ||
return FragmentRoomPollsBinding.inflate(inflater, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
setupToolbar() | ||
setupTabs() | ||
} | ||
|
||
override fun onDestroyView() { | ||
views.roomPollsViewPager.adapter = null | ||
tabLayoutMediator?.detach() | ||
tabLayoutMediator = null | ||
super.onDestroyView() | ||
} | ||
|
||
private fun setupToolbar() { | ||
setupToolbar(views.roomPollsToolbar) | ||
.allowBack() | ||
} | ||
|
||
private fun setupTabs() { | ||
views.roomPollsViewPager.adapter = RoomPollsPagerAdapter(this) | ||
|
||
tabLayoutMediator = TabLayoutMediator(views.roomPollsTabs, views.roomPollsViewPager) { tab, position -> | ||
when (position) { | ||
0 -> tab.text = getString(R.string.room_polls_active) | ||
} | ||
}.also { it.attach() } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
import im.vector.app.features.roomprofile.polls.active.RoomActivePollsFragment | ||
|
||
class RoomPollsPagerAdapter( | ||
private val fragment: Fragment | ||
) : FragmentStateAdapter(fragment) { | ||
|
||
override fun getItemCount() = 1 | ||
|
||
override fun createFragment(position: Int): Fragment { | ||
return instantiateFragment(RoomActivePollsFragment::class.java.name) | ||
} | ||
|
||
private fun instantiateFragment(fragmentName: String): Fragment { | ||
return fragment.childFragmentManager.fragmentFactory.instantiate(fragment.requireContext().classLoader, fragmentName) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
vector/src/main/java/im/vector/app/features/roomprofile/polls/RoomPollsViewEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.roomprofile.polls | ||
|
||
import im.vector.app.core.platform.VectorViewEvents | ||
|
||
sealed class RoomPollsViewEvent : VectorViewEvents |
Oops, something went wrong.