mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Mock process of load more
This commit is contained in:
parent
f7eed93a11
commit
b03b207c82
@ -20,7 +20,8 @@ import im.vector.app.features.home.room.detail.timeline.item.PollOptionViewState
|
|||||||
import im.vector.app.features.roomprofile.polls.list.ui.PollSummary
|
import im.vector.app.features.roomprofile.polls.list.ui.PollSummary
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
@ -28,15 +29,19 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class RoomPollDataSource @Inject constructor() {
|
class RoomPollDataSource @Inject constructor() {
|
||||||
|
|
||||||
|
private val pollsFlow = MutableSharedFlow<List<PollSummary>>(replay = 1)
|
||||||
|
private val polls = mutableListOf<PollSummary>()
|
||||||
|
private var fakeLoadCounter = 0
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// unmock using SDK service + add unit tests
|
// unmock using SDK service + add unit tests
|
||||||
// after unmock, expose domain layer model (entity) and do the mapping to PollSummary in the UI layer
|
// after unmock, expose domain layer model (entity) and do the mapping to PollSummary in the UI layer
|
||||||
fun getPolls(roomId: String): Flow<List<PollSummary>> {
|
fun getPolls(roomId: String): Flow<List<PollSummary>> {
|
||||||
Timber.d("roomId=$roomId")
|
Timber.d("roomId=$roomId")
|
||||||
return flowOf(getActivePolls() + getEndedPolls())
|
return pollsFlow.asSharedFlow()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getActivePolls(): List<PollSummary.ActivePoll> {
|
private fun getActivePollsPart1(): List<PollSummary.ActivePoll> {
|
||||||
return listOf(
|
return listOf(
|
||||||
PollSummary.ActivePoll(
|
PollSummary.ActivePoll(
|
||||||
id = "id1",
|
id = "id1",
|
||||||
@ -50,6 +55,11 @@ class RoomPollDataSource @Inject constructor() {
|
|||||||
creationTimestamp = 1656194400000,
|
creationTimestamp = 1656194400000,
|
||||||
title = "Which sport should the pupils do this year?"
|
title = "Which sport should the pupils do this year?"
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getActivePollsPart2(): List<PollSummary.ActivePoll> {
|
||||||
|
return listOf(
|
||||||
PollSummary.ActivePoll(
|
PollSummary.ActivePoll(
|
||||||
id = "id3",
|
id = "id3",
|
||||||
// 2022/06/24 UTC+1
|
// 2022/06/24 UTC+1
|
||||||
@ -65,7 +75,7 @@ class RoomPollDataSource @Inject constructor() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEndedPolls(): List<PollSummary.EndedPoll> {
|
private fun getEndedPollsPart1(): List<PollSummary.EndedPoll> {
|
||||||
return listOf(
|
return listOf(
|
||||||
PollSummary.EndedPoll(
|
PollSummary.EndedPoll(
|
||||||
id = "id1-ended",
|
id = "id1-ended",
|
||||||
@ -83,6 +93,11 @@ class RoomPollDataSource @Inject constructor() {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getEndedPollsPart2(): List<PollSummary.EndedPoll> {
|
||||||
|
return listOf(
|
||||||
PollSummary.EndedPoll(
|
PollSummary.EndedPoll(
|
||||||
id = "id2-ended",
|
id = "id2-ended",
|
||||||
// 2022/06/26 UTC+1
|
// 2022/06/26 UTC+1
|
||||||
@ -121,9 +136,15 @@ class RoomPollDataSource @Inject constructor() {
|
|||||||
suspend fun loadMorePolls(roomId: String): LoadMorePollsResult {
|
suspend fun loadMorePolls(roomId: String): LoadMorePollsResult {
|
||||||
Timber.d("roomId=$roomId")
|
Timber.d("roomId=$roomId")
|
||||||
// TODO
|
// TODO
|
||||||
// mock getting more polls + update the given flow
|
|
||||||
// unmock using SDK service + add unit tests
|
// unmock using SDK service + add unit tests
|
||||||
delay(5000)
|
delay(3000)
|
||||||
return LoadMorePollsResult(canLoadMore = false)
|
fakeLoadCounter++
|
||||||
|
when (fakeLoadCounter) {
|
||||||
|
1 -> polls.addAll(getActivePollsPart1() + getEndedPollsPart1())
|
||||||
|
2 -> polls.addAll(getActivePollsPart2() + getEndedPollsPart2())
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
pollsFlow.emit(polls)
|
||||||
|
return LoadMorePollsResult(canLoadMore = fakeLoadCounter < 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user