Ensure room placeholder are displayed as soon as the app is started.
This commit is contained in:
parent
87812f6f5c
commit
a772865618
2 changed files with 28 additions and 4 deletions
|
|
@ -1,14 +1,13 @@
|
||||||
package io.element.android.x.features.roomlist
|
package io.element.android.x.features.roomlist
|
||||||
|
|
||||||
import com.airbnb.mvrx.MavericksViewModel
|
import com.airbnb.mvrx.*
|
||||||
import com.airbnb.mvrx.MavericksViewModelFactory
|
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
|
||||||
import io.element.android.x.core.data.parallelMap
|
import io.element.android.x.core.data.parallelMap
|
||||||
import io.element.android.x.designsystem.components.avatar.AvatarData
|
import io.element.android.x.designsystem.components.avatar.AvatarData
|
||||||
import io.element.android.x.designsystem.components.avatar.AvatarSize
|
import io.element.android.x.designsystem.components.avatar.AvatarSize
|
||||||
import io.element.android.x.features.roomlist.model.MatrixUser
|
import io.element.android.x.features.roomlist.model.MatrixUser
|
||||||
import io.element.android.x.features.roomlist.model.RoomListRoomSummary
|
import io.element.android.x.features.roomlist.model.RoomListRoomSummary
|
||||||
import io.element.android.x.features.roomlist.model.RoomListViewState
|
import io.element.android.x.features.roomlist.model.RoomListViewState
|
||||||
|
import io.element.android.x.features.roomlist.model.createFakePlaceHolders
|
||||||
import io.element.android.x.matrix.MatrixClient
|
import io.element.android.x.matrix.MatrixClient
|
||||||
import io.element.android.x.matrix.MatrixInstance
|
import io.element.android.x.matrix.MatrixInstance
|
||||||
import io.element.android.x.matrix.media.MediaResolver
|
import io.element.android.x.matrix.media.MediaResolver
|
||||||
|
|
@ -80,7 +79,19 @@ class RoomListViewModel(
|
||||||
.map(::mapRoomSummaries)
|
.map(::mapRoomSummaries)
|
||||||
.flowOn(Dispatchers.Default)
|
.flowOn(Dispatchers.Default)
|
||||||
.execute {
|
.execute {
|
||||||
copy(rooms = it)
|
copy(
|
||||||
|
rooms = when {
|
||||||
|
it is Loading ||
|
||||||
|
// Note: this second case will prevent to handle correctly the empty case
|
||||||
|
(it is Success && it().isEmpty()) -> {
|
||||||
|
// Show fake placeholders to avoid having empty screen
|
||||||
|
Loading(createFakePlaceHolders())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package io.element.android.x.features.roomlist.model
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a list of 16 RoomListRoomSummary placeholders
|
||||||
|
*/
|
||||||
|
fun createFakePlaceHolders(): List<RoomListRoomSummary> {
|
||||||
|
return mutableListOf<RoomListRoomSummary>().apply {
|
||||||
|
for (i in 0..15) {
|
||||||
|
add(RoomListRoomSummary.placeholder("\$fakeRoom$i"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue