RoomList: add avatar for rooms and date formatting
This commit is contained in:
parent
1801bcfcd3
commit
9037b9b66b
16 changed files with 244 additions and 61 deletions
|
|
@ -0,0 +1,9 @@
|
|||
package io.element.android.x.core.data
|
||||
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
|
||||
suspend fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = coroutineScope {
|
||||
map { async { f(it) } }.awaitAll()
|
||||
}
|
||||
|
|
@ -1,37 +1,31 @@
|
|||
package io.element.android.x.designsystem.components
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.rememberAsyncImagePainter
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
/**
|
||||
* TODO fallback Avatar
|
||||
*/
|
||||
@Composable
|
||||
fun Avatar(
|
||||
data: List<UByte>?,
|
||||
data: ByteArray?,
|
||||
size: Dp = 48.dp,
|
||||
) {
|
||||
Image(
|
||||
painter = rememberAsyncImagePainter(
|
||||
model = data?.toUByteArray()?.toByteArray(),
|
||||
onError = {
|
||||
Log.e("TAG", "Error $it\n${it.result}", it.result.throwable)
|
||||
}),
|
||||
AsyncImage(
|
||||
model = data,
|
||||
onError = {
|
||||
Log.e("TAG", "Error $it\n${it.result}", it.result.throwable)
|
||||
},
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.size(size)
|
||||
.clip(CircleShape)
|
||||
.border(1.5.dp, MaterialTheme.colorScheme.primary, CircleShape)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,10 +96,21 @@ class MatrixClient internal constructor(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun loadMediaContentForSource(source: MediaSource): Result<List<UByte>> =
|
||||
suspend fun loadMediaContentForSource(source: MediaSource): Result<ByteArray> =
|
||||
withContext(dispatchers.io) {
|
||||
runCatching {
|
||||
client.getMediaContent(source)
|
||||
client.getMediaContent(source).toUByteArray().toByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun loadMediaThumbnailForSource(
|
||||
source: MediaSource,
|
||||
width: Long,
|
||||
height: Long
|
||||
): Result<ByteArray> =
|
||||
withContext(dispatchers.io) {
|
||||
runCatching {
|
||||
client.getMediaThumbnail(source, width.toULong(), height.toULong()).toUByteArray().toByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ data class RoomSummaryDetails(
|
|||
val avatarURLString: String?,
|
||||
val lastMessage: CharSequence?,
|
||||
val lastMessageTimestamp: Long?,
|
||||
val unreadNotificationCount: UInt,
|
||||
val unreadNotificationCount: Int,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ internal class RustRoomSummaryDataSource(
|
|||
name = room.name() ?: identifier,
|
||||
isDirect = room.isDm() ?: false,
|
||||
avatarURLString = room.fullRoom()?.avatarUrl(),
|
||||
unreadNotificationCount = room.unreadNotifications().notificationCount(),
|
||||
unreadNotificationCount = room.unreadNotifications().notificationCount().toInt(),
|
||||
lastMessage = latestRoomMessage?.body,
|
||||
lastMessageTimestamp = latestRoomMessage?.originServerTs
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue