Avatar working - WIP
This commit is contained in:
parent
71ca64644a
commit
13be8f3fac
6 changed files with 53 additions and 10 deletions
|
|
@ -3,4 +3,5 @@ package io.element.android.x.ui.screen.roomlist
|
|||
data class MatrixUser(
|
||||
val username: String? = null,
|
||||
val avatarUrl: String? = null,
|
||||
val avatarData: List<UByte>? = null,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package io.element.android.x.ui.screen.roomlist
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
|
|
@ -23,6 +24,7 @@ import com.airbnb.mvrx.Success
|
|||
import com.airbnb.mvrx.compose.collectAsState
|
||||
import com.airbnb.mvrx.compose.mavericksViewModel
|
||||
import io.element.android.x.ui.theme.ElementXTheme
|
||||
import io.element.android.x.ui.theme.components.Avatar
|
||||
import org.matrix.rustcomponents.sdk.Room
|
||||
|
||||
class RoomListActivity : ComponentActivity() {
|
||||
|
|
@ -107,14 +109,7 @@ class RoomListActivity : ComponentActivity() {
|
|||
Row(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Image(
|
||||
painter = rememberAsyncImagePainter(matrixUser.avatarUrl),
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(CircleShape)
|
||||
.border(1.5.dp, MaterialTheme.colorScheme.primary, CircleShape)
|
||||
)
|
||||
Avatar(data = matrixUser.avatarData)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text("${matrixUser.username}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import kotlinx.coroutines.launch
|
|||
import org.matrix.rustcomponents.sdk.Room
|
||||
import org.matrix.rustcomponents.sdk.StoppableSpawn
|
||||
import org.matrix.rustcomponents.sdk.UpdateSummary
|
||||
import org.matrix.rustcomponents.sdk.mediaSourceFromUrl
|
||||
|
||||
class RoomListViewModel(initialState: RoomListViewState) :
|
||||
MavericksViewModel<RoomListViewState>(initialState), MatrixClient.SlidingSyncListener {
|
||||
|
|
@ -29,11 +30,15 @@ class RoomListViewModel(initialState: RoomListViewState) :
|
|||
private fun handleInit() {
|
||||
viewModelScope.launch {
|
||||
val client = getClient()
|
||||
val url = client.avatarUrl()
|
||||
val mediaSource = mediaSourceFromUrl(url)
|
||||
mediaSource.url()
|
||||
setState {
|
||||
copy(
|
||||
user = MatrixUser(
|
||||
tryOrNull { client.username() } ?: "Room list",
|
||||
tryOrNull { client.avatarUrl() } ?: "https://previews.123rf.com/images/lkeskinen/lkeskinen1802/lkeskinen180208322/95731150-exemple-de-tampon-%C3%A9tiquette-typographique-timbre-ou-ic%C3%B4ne.jpg",
|
||||
username = tryOrNull { client.username() } ?: "Room list",
|
||||
avatarUrl = mediaSource.url(),
|
||||
avatarData = client.loadMedia2(url)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue